diff --git a/packages/deriv_auth/lib/features/setting_page/presentation/layouts/deriv_setting_layout.dart b/packages/deriv_auth/lib/features/setting_page/presentation/layouts/deriv_setting_layout.dart index e61f0d754..827a9d1ea 100644 --- a/packages/deriv_auth/lib/features/setting_page/presentation/layouts/deriv_setting_layout.dart +++ b/packages/deriv_auth/lib/features/setting_page/presentation/layouts/deriv_setting_layout.dart @@ -22,6 +22,7 @@ class DerivSettingLayout extends StatefulWidget { this.stagingApp = 'com.deriv.app.staging', this.getAppEnv, this.setAppEnv, + this.features, Key? key, }) : super(key: key); @@ -53,6 +54,9 @@ class DerivSettingLayout extends StatefulWidget { /// Sets environment variable final Future Function({required bool value})? setAppEnv; + /// Feature flag widget that should be listed in the setting page. + final Widget? features; + @override _SettingsPageState createState() => _SettingsPageState(); } @@ -74,7 +78,37 @@ class _SettingsPageState extends State { } @override - Widget build(BuildContext context) => WillPopScope( + Widget build(BuildContext context) => widget.features != null + ? WillPopScope( + onWillPop: () async { + final String endpoint = _endpointController.text.isNotEmpty + ? _endpointController.text + : defaultEndpoint; + final String appId = _appIdController.text.isNotEmpty + ? _appIdController.text + : defaultAppId; + await Future.wait(>[ + await widget.saveValues(endpoint: endpoint, appId: appId), + await widget.updateFlavorConfigs( + endpoint: endpoint, appId: appId), + ]); + return true; + }, + child: Scaffold( + key: const ValueKey('app_settings_page'), + appBar: AppBar( + elevation: ThemeProvider.zeroMargin, + title: Text(widget.appLabel), + leading: const BackButton( + key: ValueKey('app_settings_page_back_button'), + ), + ), + body: widget.features, + ), + ) + : _buildBasicAppSettings(); + + Widget _buildBasicAppSettings() => WillPopScope( onWillPop: () async { final String endpoint = _endpointController.text.isNotEmpty ? _endpointController.text @@ -92,6 +126,7 @@ class _SettingsPageState extends State { return true; }, child: Scaffold( + key: const ValueKey('app_settings_page'), appBar: AppBar( elevation: ThemeProvider.zeroMargin, title: Text(widget.appLabel), @@ -102,9 +137,9 @@ class _SettingsPageState extends State { children: [ _title, const SizedBox(height: ThemeProvider.margin16), - _endpoint, + _endpointTextInput, const SizedBox(height: ThemeProvider.margin16), - _appId, + _appIdTextInput, const SizedBox(width: ThemeProvider.margin08), _buildEnvironmentSwitcher, ], @@ -113,41 +148,44 @@ class _SettingsPageState extends State { ), ); - Widget get _buildEnvironmentSwitcher => FutureBuilder( - future: packageInfo, - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData && - (snapshot.data?.packageName == widget.devApp || - snapshot.data?.packageName == widget.stagingApp)) { - return Padding( - padding: - const EdgeInsets.symmetric(horizontal: ThemeProvider.margin16), - child: Row( - children: [ - const Text('Production environment'), - const SizedBox(width: ThemeProvider.margin08), - FutureBuilder( - future: widget.getAppEnv, - builder: - (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData && widget.setAppEnv != null) { - return Switch( - value: snapshot.data ?? false, - onChanged: (bool val) { - setState(() { - widget.setAppEnv!(value: val); - }); - }, - ); - } - return const SizedBox.shrink(); - }) - ], - ), - ); - } - return const SizedBox.shrink(); - }); + Widget get _buildEnvironmentSwitcher => widget.setAppEnv != null && + widget.getAppEnv != null + ? FutureBuilder( + future: packageInfo, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData && + (snapshot.data?.packageName == widget.devApp || + snapshot.data?.packageName == widget.stagingApp)) { + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: ThemeProvider.margin16), + child: Row( + children: [ + const Text('Production environment'), + const SizedBox(width: ThemeProvider.margin08), + FutureBuilder( + future: widget.getAppEnv, + builder: (BuildContext context, + AsyncSnapshot snapshot) { + if (snapshot.hasData) { + return Switch( + value: snapshot.data ?? false, + onChanged: (bool val) { + setState(() { + widget.setAppEnv!(value: val); + }); + }, + ); + } + return const SizedBox.shrink(); + }) + ], + ), + ); + } + return const SizedBox.shrink(); + }) + : const SizedBox.shrink(); Widget get _title => Padding( padding: const EdgeInsets.only( @@ -163,7 +201,7 @@ class _SettingsPageState extends State { ), ); - Widget get _endpoint => _buildTextInputField( + Widget get _endpointTextInput => _buildTextInputField( label: context.derivAuthLocalization.labelEndpoint, semantic: context.derivAuthLocalization.semanticEndpoint, controller: _endpointController, @@ -172,7 +210,7 @@ class _SettingsPageState extends State { : context.derivAuthLocalization.warnInvalidEndpoint, ); - Widget get _appId => _buildTextInputField( + Widget get _appIdTextInput => _buildTextInputField( label: context.derivAuthLocalization.labelApplicationID, semantic: context.derivAuthLocalization.semanticApplicationID, controller: _appIdController, diff --git a/packages/deriv_auth/lib/features/single_entry/core/models/setting_page_model.dart b/packages/deriv_auth/lib/features/single_entry/core/models/setting_page_model.dart index 3093a9857..7211e4912 100644 --- a/packages/deriv_auth/lib/features/single_entry/core/models/setting_page_model.dart +++ b/packages/deriv_auth/lib/features/single_entry/core/models/setting_page_model.dart @@ -10,6 +10,9 @@ class SettingPageModel { required this.saveValues, required this.updateFlavorConfigs, this.settingsPageNavigation, + this.getAppEnv, + this.setAppEnv, + this.features, }); /// Setting page App label @@ -30,4 +33,13 @@ class SettingPageModel { /// Settings page navigation final Function(BuildContext context)? settingsPageNavigation; + + /// Gets environment variable + final Future? getAppEnv; + + /// Sets environment variable + final Future Function({required bool value})? setAppEnv; + + /// Feature flag widget that should be listed in the setting page. + final Widget? features; } diff --git a/packages/deriv_auth/lib/features/single_entry/features/settings/pages/settings_page.dart b/packages/deriv_auth/lib/features/single_entry/features/settings/pages/settings_page.dart index 149c3a540..bfe7d55a8 100644 --- a/packages/deriv_auth/lib/features/single_entry/features/settings/pages/settings_page.dart +++ b/packages/deriv_auth/lib/features/single_entry/features/settings/pages/settings_page.dart @@ -20,5 +20,8 @@ class _SettingsPageState extends State { saveValues: AuthData().data.settingPageModel.saveValues, appId: AuthData().data.settingPageModel.appId.call(), endpoint: AuthData().data.settingPageModel.endpoint.call(), + features: AuthData().data.settingPageModel.features, + setAppEnv: AuthData().data.settingPageModel.setAppEnv, + getAppEnv: AuthData().data.settingPageModel.getAppEnv, ); }