conditional and padding for wallet syncing options

This commit is contained in:
ryleedavis 2022-11-03 17:11:01 -06:00
parent e5f69700f7
commit 563492d4e8
2 changed files with 376 additions and 318 deletions

View file

@ -9,6 +9,8 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
class SyncingOptionsView extends ConsumerWidget { class SyncingOptionsView extends ConsumerWidget {
@ -18,8 +20,9 @@ class SyncingOptionsView extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final isDesktop = Util.isDesktop;
return ConditionalParent( return ConditionalParent(
condition: !Util.isDesktop, condition: !isDesktop,
builder: (child) { builder: (child) {
return Scaffold( return Scaffold(
backgroundColor: backgroundColor:
@ -54,317 +57,353 @@ class SyncingOptionsView extends ConsumerWidget {
), ),
); );
}, },
child: Padding( child: Column(
padding: const EdgeInsets.symmetric(horizontal: 10), children: [
child: Column( RoundedWhiteContainer(
children: [ padding: const EdgeInsets.all(0),
RoundedWhiteContainer( child: Column(
padding: const EdgeInsets.all(0), crossAxisAlignment: CrossAxisAlignment.stretch,
child: Column( children: [
crossAxisAlignment: CrossAxisAlignment.stretch, Padding(
children: [ padding: const EdgeInsets.all(4),
Padding( child: RawMaterialButton(
padding: const EdgeInsets.all(4), // splashColor: Theme.of(context).extension<StackColors>()!.highlight,
child: RawMaterialButton( materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
// splashColor: Theme.of(context).extension<StackColors>()!.highlight, shape: RoundedRectangleBorder(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, borderRadius: BorderRadius.circular(
shape: RoundedRectangleBorder( Constants.size.circularBorderRadius,
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<StackColors>()!
.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,
),
],
),
),
],
),
),
), ),
), ),
), onPressed: () {
Padding( final state =
padding: const EdgeInsets.all(4.0), ref.read(prefsChangeNotifierProvider).syncType;
child: RawMaterialButton( if (state != SyncingType.currentWalletOnly) {
// splashColor: Theme.of(context).extension<StackColors>()!.highlight, ref.read(prefsChangeNotifierProvider).syncType =
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, SyncingType.currentWalletOnly;
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 // disable auto sync on all wallets that aren't active/current
ref ref
.read(walletsChangeNotifierProvider) .read(walletsChangeNotifierProvider)
.managers .managers
.forEach((e) => e.shouldAutoSync = true); .forEach((e) {
} if (!e.isActiveWallet) {
}, e.shouldAutoSync = false;
child: Container( }
color: Colors.transparent, });
child: Padding( }
padding: const EdgeInsets.all(8.0), },
child: Row( child: Container(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
height: 20,
child: Radio(
activeColor: Theme.of(context)
.extension<StackColors>()!
.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<StackColors>()!.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<StackColors>()!
.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, color: Colors.transparent,
child: Padding( child: Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.all(8.0),
left: 12.0,
right: 12,
bottom: 12,
),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(
width: 20,
height: 20,
child: Radio(
activeColor: Theme.of(context)
.extension<StackColors>()!
.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( const SizedBox(
width: 12 + 20, width: 12,
height: 12,
), ),
Flexible( Flexible(
child: RawMaterialButton( child: Column(
// splashColor: Theme.of(context).extension<StackColors>()!.highlight, crossAxisAlignment: CrossAxisAlignment.start,
materialTapTargetSize: children: [
MaterialTapTargetSize.shrinkWrap, Text(
shape: RoundedRectangleBorder( "Sync only currently open wallet",
borderRadius: BorderRadius.circular( style: STextStyles.titleBold12(context),
Constants.size.circularBorderRadius, textAlign: TextAlign.left,
), ),
), Text(
onPressed: () { "Sync only the wallet that you are using",
Navigator.of(context).pushNamed( style: STextStyles.itemSubtitle(context),
WalletSyncingOptionsView.routeName); textAlign: TextAlign.left,
}, ),
child: Column( ],
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Select wallets...",
style: STextStyles.link2(context),
textAlign: TextAlign.left,
),
],
),
), ),
), ),
], ],
), ),
), ),
), ),
], ),
), ),
Padding(
padding: const EdgeInsets.all(4.0),
child: RawMaterialButton(
// splashColor: Theme.of(context).extension<StackColors>()!.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<StackColors>()!
.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<StackColors>()!.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<StackColors>()!
.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<StackColors>()!.highlight,
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: () {
!isDesktop
? Navigator.of(context).pushNamed(
WalletSyncingOptionsView.routeName)
: showDialog(
context: context,
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return DesktopDialog(
maxWidth: 600,
maxHeight: 800,
child: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Padding(
padding:
const EdgeInsets.all(
32),
child: Text(
"Select wallets to sync",
style: STextStyles
.desktopH3(context),
textAlign:
TextAlign.center,
),
),
const DesktopDialogCloseButton(),
],
),
const Expanded(
child:
WalletSyncingOptionsView(),
),
],
),
);
});
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Select wallets...",
style: STextStyles.link2(context),
textAlign: TextAlign.left,
),
],
),
),
),
],
),
),
),
],
), ),
], ),
), ],
), ),
); );
} }

View file

@ -10,7 +10,9 @@ import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/animated_text.dart'; import 'package:stackwallet/widgets/animated_text.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart'; import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
@ -25,30 +27,47 @@ class WalletSyncingOptionsView extends ConsumerWidget {
final managers = ref final managers = ref
.watch(walletsChangeNotifierProvider.select((value) => value.managers)); .watch(walletsChangeNotifierProvider.select((value) => value.managers));
return Scaffold( final isDesktop = Util.isDesktop;
backgroundColor: Theme.of(context).extension<StackColors>()!.background, return ConditionalParent(
appBar: AppBar( condition: !isDesktop,
leading: AppBarBackButton( builder: (child) {
onPressed: () async { return Scaffold(
Navigator.of(context).pop(); backgroundColor:
}, Theme.of(context).extension<StackColors>()!.background,
), appBar: AppBar(
title: FittedBox( leading: AppBarBackButton(
fit: BoxFit.scaleDown, onPressed: () async {
child: Text( Navigator.of(context).pop();
"Sync only selected wallets at startup", },
style: STextStyles.navBarTitle(context), ),
title: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
"Sync only selected wallets at startup",
style: STextStyles.navBarTitle(context),
),
),
), ),
), body: Padding(
), padding: const EdgeInsets.only(
body: LayoutBuilder(builder: (context, constraints) { left: 12,
return Padding( top: 12,
padding: const EdgeInsets.only( right: 12,
left: 12, ),
top: 12, child: child,
right: 12,
), ),
child: SingleChildScrollView( );
},
child: ConditionalParent(
condition: isDesktop,
builder: (child) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: child,
);
},
child: LayoutBuilder(builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
minHeight: constraints.maxHeight - 24, minHeight: constraints.maxHeight - 24,
@ -208,9 +227,9 @@ class WalletSyncingOptionsView extends ConsumerWidget {
), ),
), ),
), ),
), );
); }),
}), ),
); );
} }
} }