From 541c57f99758bfbfb46bc67d958de05b45150dbf Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 19 Sep 2022 15:53:21 -0600 Subject: [PATCH] restore options refactor clean up --- .../name_your_wallet_view.dart | 2 +- .../restore_options_view.dart | 194 +----------------- .../mobile_mnemonic_length_selector.dart | 59 ++++++ .../sub_widgets/restore_from_date_picker.dart | 76 +++++++ .../restore_options_next_button.dart | 33 +++ .../restore_options_platform_layout.dart | 39 ++++ lib/route_generator.dart | 2 +- 7 files changed, 215 insertions(+), 190 deletions(-) rename lib/pages/add_wallet_views/restore_wallet_view/{ => restore_options_view}/restore_options_view.dart (72%) create mode 100644 lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/mobile_mnemonic_length_selector.dart create mode 100644 lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_from_date_picker.dart create mode 100644 lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_next_button.dart create mode 100644 lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_platform_layout.dart diff --git a/lib/pages/add_wallet_views/name_your_wallet_view/name_your_wallet_view.dart b/lib/pages/add_wallet_views/name_your_wallet_view/name_your_wallet_view.dart index c6e326ec1..ae9b0aebd 100644 --- a/lib/pages/add_wallet_views/name_your_wallet_view/name_your_wallet_view.dart +++ b/lib/pages/add_wallet_views/name_your_wallet_view/name_your_wallet_view.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/notifications/show_flush_bar.dart'; import 'package:stackwallet/pages/add_wallet_views/new_wallet_recovery_phrase_warning_view/new_wallet_recovery_phrase_warning_view.dart'; -import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/restore_options_view.dart'; import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/exit_to_my_stack_button.dart'; import 'package:stackwallet/providers/global/wallets_service_provider.dart'; import 'package:stackwallet/providers/ui/verify_recovery_phrase/mnemonic_word_count_state_provider.dart'; diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/restore_options_view.dart similarity index 72% rename from lib/pages/add_wallet_views/restore_wallet_view/restore_options_view.dart rename to lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/restore_options_view.dart index 6c640cd5b..77e14ea61 100644 --- a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view.dart +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/restore_options_view.dart @@ -4,6 +4,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_rounded_date_picker/flutter_rounded_date_picker.dart'; import 'package:flutter_svg/svg.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/mobile_mnemonic_length_selector.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_from_date_picker.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_next_button.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_platform_layout.dart'; import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/sub_widgets/mnemonic_word_count_select_sheet.dart'; import 'package:stackwallet/providers/ui/verify_recovery_phrase/mnemonic_word_count_state_provider.dart'; @@ -221,7 +225,7 @@ class _RestoreOptionsViewState extends ConsumerState { }, ), ), - body: PlatformRestoreOptionsLayout( + body: RestoreOptionsPlatformLayout( isDesktop: isDesktop, child: ConstrainedBox( constraints: BoxConstraints( @@ -370,7 +374,7 @@ class _RestoreOptionsViewState extends ConsumerState { const SizedBox( height: 32, ), - RestoreNextButton( + RestoreOptionsNextButton( isDesktop: isDesktop, onPressed: _nextEnabled ? nextPressed : null, ), @@ -381,189 +385,3 @@ class _RestoreOptionsViewState extends ConsumerState { ); } } - -class PlatformRestoreOptionsLayout extends StatelessWidget { - const PlatformRestoreOptionsLayout({ - Key? key, - required this.isDesktop, - required this.child, - }) : super(key: key); - - final bool isDesktop; - final Widget child; - - @override - Widget build(BuildContext context) { - if (isDesktop) { - return child; - } else { - return Container( - color: CFColors.background, - child: Padding( - padding: const EdgeInsets.all(16), - child: LayoutBuilder( - builder: (ctx, constraints) { - return SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints(minHeight: constraints.maxHeight), - child: IntrinsicHeight( - child: child, - ), - ), - ); - }, - ), - ), - ); - } - } -} - -class RestoreFromDatePicker extends StatefulWidget { - const RestoreFromDatePicker({Key? key, required this.onTap}) - : super(key: key); - - final VoidCallback onTap; - - @override - State createState() => _RestoreFromDatePickerState(); -} - -class _RestoreFromDatePickerState extends State { - late final TextEditingController _dateController; - late final VoidCallback onTap; - - @override - void initState() { - onTap = widget.onTap; - _dateController = TextEditingController(); - - super.initState(); - } - - @override - void dispose() { - _dateController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Container( - color: Colors.transparent, - child: TextField( - onTap: onTap, - controller: _dateController, - style: STextStyles.field, - decoration: InputDecoration( - hintText: "Restore from...", - suffixIcon: UnconstrainedBox( - child: Row( - children: [ - const SizedBox( - width: 16, - ), - SvgPicture.asset( - Assets.svg.calendar, - color: CFColors.neutral50, - width: 16, - height: 16, - ), - const SizedBox( - width: 12, - ), - ], - ), - ), - ), - key: const Key("restoreOptionsViewDatePickerKey"), - readOnly: true, - toolbarOptions: const ToolbarOptions( - copy: true, - cut: false, - paste: false, - selectAll: false, - ), - onChanged: (newValue) {}, - ), - ); - } -} - -class MobileMnemonicLengthSelector extends ConsumerWidget { - const MobileMnemonicLengthSelector({ - Key? key, - required this.chooseMnemonicLength, - }) : super(key: key); - - final VoidCallback chooseMnemonicLength; - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Stack( - children: [ - const TextField( - // controller: _lengthController, - readOnly: true, - textInputAction: TextInputAction.none, - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 12, - ), - child: RawMaterialButton( - splashColor: CFColors.splashLight, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - Constants.size.circularBorderRadius, - ), - ), - onPressed: chooseMnemonicLength, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "${ref.watch(mnemonicWordCountStateProvider.state).state} words", - style: STextStyles.itemSubtitle12, - ), - SvgPicture.asset( - Assets.svg.chevronDown, - width: 8, - height: 4, - color: CFColors.gray3, - ), - ], - ), - ), - ) - ], - ); - } -} - -class RestoreNextButton extends StatelessWidget { - const RestoreNextButton({Key? key, required this.isDesktop, this.onPressed}) - : super(key: key); - - final bool isDesktop; - final VoidCallback? onPressed; - - @override - Widget build(BuildContext context) { - return ConstrainedBox( - constraints: BoxConstraints( - minHeight: isDesktop ? 70 : 0, - ), - child: TextButton( - onPressed: onPressed, - style: onPressed != null - ? CFColors.getPrimaryEnabledButtonColor(context) - : CFColors.getPrimaryDisabledButtonColor(context), - child: Text( - "Next", - style: STextStyles.button, - ), - ), - ); - } -} diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/mobile_mnemonic_length_selector.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/mobile_mnemonic_length_selector.dart new file mode 100644 index 000000000..553ea1eab --- /dev/null +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/mobile_mnemonic_length_selector.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/providers/ui/verify_recovery_phrase/mnemonic_word_count_state_provider.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; + +class MobileMnemonicLengthSelector extends ConsumerWidget { + const MobileMnemonicLengthSelector({ + Key? key, + required this.chooseMnemonicLength, + }) : super(key: key); + + final VoidCallback chooseMnemonicLength; + + @override + Widget build(BuildContext context, WidgetRef ref) { + return Stack( + children: [ + const TextField( + // controller: _lengthController, + readOnly: true, + textInputAction: TextInputAction.none, + ), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 12, + ), + child: RawMaterialButton( + splashColor: CFColors.splashLight, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius, + ), + ), + onPressed: chooseMnemonicLength, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "${ref.watch(mnemonicWordCountStateProvider.state).state} words", + style: STextStyles.itemSubtitle12, + ), + SvgPicture.asset( + Assets.svg.chevronDown, + width: 8, + height: 4, + color: CFColors.gray3, + ), + ], + ), + ), + ) + ], + ); + } +} diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_from_date_picker.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_from_date_picker.dart new file mode 100644 index 000000000..f557277e0 --- /dev/null +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_from_date_picker.dart @@ -0,0 +1,76 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; + +class RestoreFromDatePicker extends StatefulWidget { + const RestoreFromDatePicker({Key? key, required this.onTap}) + : super(key: key); + + final VoidCallback onTap; + + @override + State createState() => _RestoreFromDatePickerState(); +} + +class _RestoreFromDatePickerState extends State { + late final TextEditingController _dateController; + late final VoidCallback onTap; + + @override + void initState() { + onTap = widget.onTap; + _dateController = TextEditingController(); + + super.initState(); + } + + @override + void dispose() { + _dateController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.transparent, + child: TextField( + onTap: onTap, + controller: _dateController, + style: STextStyles.field, + decoration: InputDecoration( + hintText: "Restore from...", + suffixIcon: UnconstrainedBox( + child: Row( + children: [ + const SizedBox( + width: 16, + ), + SvgPicture.asset( + Assets.svg.calendar, + color: CFColors.neutral50, + width: 16, + height: 16, + ), + const SizedBox( + width: 12, + ), + ], + ), + ), + ), + key: const Key("restoreOptionsViewDatePickerKey"), + readOnly: true, + toolbarOptions: const ToolbarOptions( + copy: true, + cut: false, + paste: false, + selectAll: false, + ), + onChanged: (newValue) {}, + ), + ); + } +} diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_next_button.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_next_button.dart new file mode 100644 index 000000000..8474fd759 --- /dev/null +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_next_button.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; + +class RestoreOptionsNextButton extends StatelessWidget { + const RestoreOptionsNextButton({ + Key? key, + required this.isDesktop, + this.onPressed, + }) : super(key: key); + + final bool isDesktop; + final VoidCallback? onPressed; + + @override + Widget build(BuildContext context) { + return ConstrainedBox( + constraints: BoxConstraints( + minHeight: isDesktop ? 70 : 0, + ), + child: TextButton( + onPressed: onPressed, + style: onPressed != null + ? CFColors.getPrimaryEnabledButtonColor(context) + : CFColors.getPrimaryDisabledButtonColor(context), + child: Text( + "Next", + style: STextStyles.button, + ), + ), + ); + } +} diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_platform_layout.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_platform_layout.dart new file mode 100644 index 000000000..5576fd1d3 --- /dev/null +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_options_view/sub_widgets/restore_options_platform_layout.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; +import 'package:stackwallet/utilities/cfcolors.dart'; + +class RestoreOptionsPlatformLayout extends StatelessWidget { + const RestoreOptionsPlatformLayout({ + Key? key, + required this.isDesktop, + required this.child, + }) : super(key: key); + + final bool isDesktop; + final Widget child; + + @override + Widget build(BuildContext context) { + if (isDesktop) { + return child; + } else { + return Container( + color: CFColors.background, + child: Padding( + padding: const EdgeInsets.all(16), + child: LayoutBuilder( + builder: (ctx, constraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: constraints.maxHeight), + child: IntrinsicHeight( + child: child, + ), + ), + ); + }, + ), + ), + ); + } + } +} diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 5ceae480c..797b62969 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -10,7 +10,7 @@ import 'package:stackwallet/pages/add_wallet_views/create_or_restore_wallet_view import 'package:stackwallet/pages/add_wallet_views/name_your_wallet_view/name_your_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/new_wallet_recovery_phrase_view/new_wallet_recovery_phrase_view.dart'; import 'package:stackwallet/pages/add_wallet_views/new_wallet_recovery_phrase_warning_view/new_wallet_recovery_phrase_warning_view.dart'; -import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view.dart'; +import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_options_view/restore_options_view.dart'; import 'package:stackwallet/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dart'; import 'package:stackwallet/pages/address_book_views/address_book_view.dart';