From 6d643881ddabe6898fc18b98f6c4a8b84544f5d8 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 2 Jan 2024 19:55:21 +0700 Subject: [PATCH] TF-2387 Handle system back button on login view mobile --- .../login/presentation/login_view.dart | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/lib/features/login/presentation/login_view.dart b/lib/features/login/presentation/login_view.dart index 699a36870..bb051da49 100644 --- a/lib/features/login/presentation/login_view.dart +++ b/lib/features/login/presentation/login_view.dart @@ -26,44 +26,50 @@ class LoginView extends BaseLoginView { Widget build(BuildContext context) { ThemeUtils.setSystemDarkUIStyle(); - return Scaffold( - backgroundColor: AppColor.primaryLightColor, - body: GestureDetector( - onTap: () => FocusScope.of(context).unfocus(), - child: Container( - color: Colors.white, - child: SafeArea( - child: _supportScrollForm(context) - ? Stack(children: [ - Center( - child: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: _buildCenterForm(context) - ) - ), - Obx(() { - if (controller.isBackButtonActivated) { - return LoginBackButton( - onBackAction: () => controller.handleBackButtonAction(context) - ); - } - return const SizedBox.shrink(); - }) - ]) - : Stack(children: [ - _buildCenterForm(context), - Obx(() { - if (controller.isBackButtonActivated) { - return LoginBackButton( - onBackAction: () => controller.handleBackButtonAction(context) - ); - } - return const SizedBox.shrink(); - }) - ]), + return PopScope( + canPop: false, + onPopInvoked: (didPop) => !didPop + ? controller.handleBackButtonAction(context) + : null, + child: Scaffold( + backgroundColor: AppColor.primaryLightColor, + body: GestureDetector( + onTap: () => FocusScope.of(context).unfocus(), + child: Container( + color: Colors.white, + child: SafeArea( + child: _supportScrollForm(context) + ? Stack(children: [ + Center( + child: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: _buildCenterForm(context) + ) + ), + Obx(() { + if (controller.isBackButtonActivated) { + return LoginBackButton( + onBackAction: () => controller.handleBackButtonAction(context) + ); + } + return const SizedBox.shrink(); + }) + ]) + : Stack(children: [ + _buildCenterForm(context), + Obx(() { + if (controller.isBackButtonActivated) { + return LoginBackButton( + onBackAction: () => controller.handleBackButtonAction(context) + ); + } + return const SizedBox.shrink(); + }) + ]), + ), ), - ), - )); + )), + ); } Widget _buildCenterForm(BuildContext context) {