From e5f69700f7fcbaa4d380d1e8cf0f3ba67c6167cf Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Thu, 3 Nov 2022 14:28:24 -0600 Subject: [PATCH] conditional for desktop syncing pref settings --- .../syncing_options_view.dart | 701 +++++++++--------- .../syncing_preferences_settings.dart | 9 + 2 files changed, 345 insertions(+), 365 deletions(-) diff --git a/lib/pages/settings_views/global_settings_view/syncing_preferences_views/syncing_options_view.dart b/lib/pages/settings_views/global_settings_view/syncing_preferences_views/syncing_options_view.dart index bada67353..a65a03a87 100644 --- a/lib/pages/settings_views/global_settings_view/syncing_preferences_views/syncing_options_view.dart +++ b/lib/pages/settings_views/global_settings_view/syncing_preferences_views/syncing_options_view.dart @@ -6,6 +6,8 @@ import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/sync_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; @@ -16,383 +18,352 @@ class SyncingOptionsView extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - backgroundColor: Theme.of(context).extension()!.background, - appBar: AppBar( - leading: AppBarBackButton( - onPressed: () async { - Navigator.of(context).pop(); - }, - ), - title: Text( - "Syncing", - style: STextStyles.navBarTitle(context), - ), - ), - body: Padding( - padding: const EdgeInsets.all(16), - child: LayoutBuilder( - builder: (context, constraints) { - return SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints( - minHeight: constraints.maxHeight, - ), - child: IntrinsicHeight( - child: Column( - children: [ - RoundedWhiteContainer( - padding: const EdgeInsets.all(0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsets.all(4), - child: RawMaterialButton( - // splashColor: Theme.of(context).extension()!.highlight, - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - onPressed: () { - final state = ref - .read(prefsChangeNotifierProvider) - .syncType; - if (state != SyncingType.currentWalletOnly) { - ref - .read(prefsChangeNotifierProvider) - .syncType = - SyncingType.currentWalletOnly; + return ConditionalParent( + condition: !Util.isDesktop, + builder: (child) { + return Scaffold( + backgroundColor: + Theme.of(context).extension()!.background, + appBar: AppBar( + leading: AppBarBackButton( + onPressed: () async { + Navigator.of(context).pop(); + }, + ), + title: Text( + "Syncing", + style: STextStyles.navBarTitle(context), + ), + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: LayoutBuilder( + builder: (context, constraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: constraints.maxHeight, + ), + child: IntrinsicHeight( + child: child, + ), + ), + ); + }, + ), + ), + ); + }, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Column( + children: [ + RoundedWhiteContainer( + padding: const EdgeInsets.all(0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: const EdgeInsets.all(4), + child: RawMaterialButton( + // splashColor: Theme.of(context).extension()!.highlight, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + onPressed: () { + final state = + ref.read(prefsChangeNotifierProvider).syncType; + if (state != SyncingType.currentWalletOnly) { + ref.read(prefsChangeNotifierProvider).syncType = + SyncingType.currentWalletOnly; - // disable auto sync on all wallets that aren't active/current - ref - .read(walletsChangeNotifierProvider) - .managers - .forEach((e) { - if (!e.isActiveWallet) { - e.shouldAutoSync = false; - } - }); - } - }, - child: Container( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox( - width: 20, - height: 20, - child: Radio( - activeColor: Theme.of(context) - .extension()! - .radioButtonIconEnabled, - value: - SyncingType.currentWalletOnly, - groupValue: ref.watch( - prefsChangeNotifierProvider - .select((value) => - value.syncType), - ), - onChanged: (value) { - if (value is SyncingType) { - ref - .read( - prefsChangeNotifierProvider) - .syncType = value; - } - }, - ), - ), - const SizedBox( - width: 12, - ), - Flexible( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - "Sync only currently open wallet", - style: STextStyles.titleBold12( - context), - textAlign: TextAlign.left, - ), - Text( - "Sync only the wallet that you are using", - style: STextStyles.itemSubtitle( - context), - textAlign: TextAlign.left, - ), - ], - ), - ), - ], - ), + // disable auto sync on all wallets that aren't active/current + ref + .read(walletsChangeNotifierProvider) + .managers + .forEach((e) { + if (!e.isActiveWallet) { + e.shouldAutoSync = false; + } + }); + } + }, + child: Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 20, + height: 20, + child: Radio( + activeColor: Theme.of(context) + .extension()! + .radioButtonIconEnabled, + value: SyncingType.currentWalletOnly, + groupValue: ref.watch( + prefsChangeNotifierProvider + .select((value) => value.syncType), ), + onChanged: (value) { + if (value is SyncingType) { + ref + .read(prefsChangeNotifierProvider) + .syncType = value; + } + }, ), ), - ), - Padding( - padding: const EdgeInsets.all(4.0), - child: RawMaterialButton( - // splashColor: Theme.of(context).extension()!.highlight, - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - onPressed: () { - final state = ref - .read(prefsChangeNotifierProvider) - .syncType; - if (state != - SyncingType.allWalletsOnStartup) { - ref - .read(prefsChangeNotifierProvider) - .syncType = - SyncingType.allWalletsOnStartup; - - // enable auto sync on all wallets - ref - .read(walletsChangeNotifierProvider) - .managers - .forEach( - (e) => e.shouldAutoSync = true); - } - }, - child: Container( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox( - width: 20, - height: 20, - child: Radio( - activeColor: Theme.of(context) - .extension()! - .radioButtonIconEnabled, - value: - SyncingType.allWalletsOnStartup, - groupValue: ref.watch( - prefsChangeNotifierProvider - .select((value) => - value.syncType), - ), - onChanged: (value) { - if (value is SyncingType) { - ref - .read( - prefsChangeNotifierProvider) - .syncType = value; - } - }, - ), - ), - const SizedBox( - width: 12, - ), - Flexible( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - "Sync all wallets at startup", - style: STextStyles.titleBold12( - context), - textAlign: TextAlign.left, - ), - Text( - "All of your wallets will start syncing when you open the app", - style: STextStyles.itemSubtitle( - context), - textAlign: TextAlign.left, - ), - ], - ), - ), - ], - ), - ), - ), - ), - ), - Padding( - padding: const EdgeInsets.all(4), - child: RawMaterialButton( - // splashColor: Theme.of(context).extension()!.highlight, - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - onPressed: () { - final state = ref - .read(prefsChangeNotifierProvider) - .syncType; - if (state != - SyncingType.selectedWalletsAtStartup) { - ref - .read(prefsChangeNotifierProvider) - .syncType = - SyncingType.selectedWalletsAtStartup; - - final ids = ref - .read(prefsChangeNotifierProvider) - .walletIdsSyncOnStartup; - - // enable auto sync on selected wallets only - ref - .read(walletsChangeNotifierProvider) - .managers - .forEach((e) => e.shouldAutoSync = - ids.contains(e.walletId)); - } - }, - child: Container( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.all(8), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox( - width: 20, - height: 20, - child: Radio( - activeColor: Theme.of(context) - .extension()! - .radioButtonIconEnabled, - value: SyncingType - .selectedWalletsAtStartup, - groupValue: ref.watch( - prefsChangeNotifierProvider - .select((value) => - value.syncType), - ), - onChanged: (value) { - if (value is SyncingType) { - ref - .read( - prefsChangeNotifierProvider) - .syncType = value; - } - }, - ), - ), - const SizedBox( - width: 12, - ), - Flexible( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - "Sync only selected wallets at startup", - style: STextStyles.titleBold12( - context), - textAlign: TextAlign.left, - ), - Text( - "Only the wallets you select will start syncing when you open the app", - style: STextStyles.itemSubtitle( - context), - textAlign: TextAlign.left, - ), - ], - ), - ), - ], - ), - ), - ), - ), - ), - if (ref.watch(prefsChangeNotifierProvider - .select((value) => value.syncType)) != - SyncingType.selectedWalletsAtStartup) const SizedBox( - height: 12, + width: 12, ), - if (ref.watch(prefsChangeNotifierProvider - .select((value) => value.syncType)) == - SyncingType.selectedWalletsAtStartup) - Container( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.only( - left: 12.0, - right: 12, - bottom: 12, - ), - child: Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - const SizedBox( - width: 12 + 20, - height: 12, - ), - Flexible( - child: RawMaterialButton( - // splashColor: Theme.of(context).extension()!.highlight, - materialTapTargetSize: - MaterialTapTargetSize.shrinkWrap, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - Constants - .size.circularBorderRadius, - ), - ), - onPressed: () { - Navigator.of(context).pushNamed( - WalletSyncingOptionsView - .routeName); - }, - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - "Select wallets...", - style: - STextStyles.link2(context), - textAlign: TextAlign.left, - ), - ], - ), - ), - ), - ], - ), + Flexible( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Sync only currently open wallet", + style: STextStyles.titleBold12(context), + textAlign: TextAlign.left, + ), + Text( + "Sync only the wallet that you are using", + style: STextStyles.itemSubtitle(context), + textAlign: TextAlign.left, + ), + ], ), ), + ], + ), + ), + ), + ), + ), + Padding( + padding: const EdgeInsets.all(4.0), + child: RawMaterialButton( + // splashColor: Theme.of(context).extension()!.highlight, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + onPressed: () { + final state = + ref.read(prefsChangeNotifierProvider).syncType; + if (state != SyncingType.allWalletsOnStartup) { + ref.read(prefsChangeNotifierProvider).syncType = + SyncingType.allWalletsOnStartup; + + // enable auto sync on all wallets + ref + .read(walletsChangeNotifierProvider) + .managers + .forEach((e) => e.shouldAutoSync = true); + } + }, + child: Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 20, + height: 20, + child: Radio( + activeColor: Theme.of(context) + .extension()! + .radioButtonIconEnabled, + value: SyncingType.allWalletsOnStartup, + groupValue: ref.watch( + prefsChangeNotifierProvider + .select((value) => value.syncType), + ), + onChanged: (value) { + if (value is SyncingType) { + ref + .read(prefsChangeNotifierProvider) + .syncType = value; + } + }, + ), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Sync all wallets at startup", + style: STextStyles.titleBold12(context), + textAlign: TextAlign.left, + ), + Text( + "All of your wallets will start syncing when you open the app", + style: STextStyles.itemSubtitle(context), + textAlign: TextAlign.left, + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + Padding( + padding: const EdgeInsets.all(4), + child: RawMaterialButton( + // splashColor: Theme.of(context).extension()!.highlight, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + onPressed: () { + final state = + ref.read(prefsChangeNotifierProvider).syncType; + if (state != SyncingType.selectedWalletsAtStartup) { + ref.read(prefsChangeNotifierProvider).syncType = + SyncingType.selectedWalletsAtStartup; + + final ids = ref + .read(prefsChangeNotifierProvider) + .walletIdsSyncOnStartup; + + // enable auto sync on selected wallets only + ref + .read(walletsChangeNotifierProvider) + .managers + .forEach((e) => + e.shouldAutoSync = ids.contains(e.walletId)); + } + }, + child: Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.all(8), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 20, + height: 20, + child: Radio( + activeColor: Theme.of(context) + .extension()! + .radioButtonIconEnabled, + value: SyncingType.selectedWalletsAtStartup, + groupValue: ref.watch( + prefsChangeNotifierProvider + .select((value) => value.syncType), + ), + onChanged: (value) { + if (value is SyncingType) { + ref + .read(prefsChangeNotifierProvider) + .syncType = value; + } + }, + ), + ), + const SizedBox( + width: 12, + ), + Flexible( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Sync only selected wallets at startup", + style: STextStyles.titleBold12(context), + textAlign: TextAlign.left, + ), + Text( + "Only the wallets you select will start syncing when you open the app", + style: STextStyles.itemSubtitle(context), + textAlign: TextAlign.left, + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + if (ref.watch(prefsChangeNotifierProvider + .select((value) => value.syncType)) != + SyncingType.selectedWalletsAtStartup) + const SizedBox( + height: 12, + ), + if (ref.watch(prefsChangeNotifierProvider + .select((value) => value.syncType)) == + SyncingType.selectedWalletsAtStartup) + Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.only( + left: 12.0, + right: 12, + bottom: 12, + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + width: 12 + 20, + height: 12, + ), + Flexible( + child: RawMaterialButton( + // splashColor: Theme.of(context).extension()!.highlight, + materialTapTargetSize: + MaterialTapTargetSize.shrinkWrap, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + onPressed: () { + Navigator.of(context).pushNamed( + WalletSyncingOptionsView.routeName); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Select wallets...", + style: STextStyles.link2(context), + textAlign: TextAlign.left, + ), + ], + ), + ), + ), ], ), ), - ], - ), - ), + ), + ], ), - ); - }, + ), + ], ), ), ); diff --git a/lib/pages_desktop_specific/home/settings_menu/syncing_preferences_settings.dart b/lib/pages_desktop_specific/home/settings_menu/syncing_preferences_settings.dart index 9b6c6c85c..7f6aac260 100644 --- a/lib/pages_desktop_specific/home/settings_menu/syncing_preferences_settings.dart +++ b/lib/pages_desktop_specific/home/settings_menu/syncing_preferences_settings.dart @@ -7,6 +7,8 @@ import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import '../../../pages/settings_views/global_settings_view/syncing_preferences_views/syncing_options_view.dart'; + class SyncingPreferencesSettings extends ConsumerStatefulWidget { const SyncingPreferencesSettings({Key? key}) : super(key: key); @@ -62,6 +64,13 @@ class _SyncingPreferencesSettings ), ], ), + + ///TODO: ONLY SHOW SYNC OPTIONS ON BUTTON PRESS + Column( + children: [ + SyncingOptionsView(), + ], + ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: const [