diff --git a/lib/pages/stack_privacy_calls.dart b/lib/pages/stack_privacy_calls.dart index 6065c90dc..2aa2a5c8a 100644 --- a/lib/pages/stack_privacy_calls.dart +++ b/lib/pages/stack_privacy_calls.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/pages/pinpad_views/create_pin_view.dart'; +import 'package:stackwallet/pages_desktop_specific/create_password/create_password_view.dart'; import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; @@ -12,9 +12,6 @@ import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; -import 'package:stackwallet/providers/global/prefs_provider.dart'; -import 'package:stackwallet/utilities/prefs.dart'; - class StackPrivacyCalls extends ConsumerStatefulWidget { const StackPrivacyCalls({ Key? key, @@ -31,19 +28,19 @@ class StackPrivacyCalls extends ConsumerStatefulWidget { class _StackPrivacyCalls extends ConsumerState { late final bool isDesktop; - bool isEasy = Prefs.instance.externalCalls; - final PageController _pageController = - PageController(initialPage: 0, keepPage: true); + late bool isEasy; + late bool infoToggle; @override void initState() { isDesktop = Util.isDesktop; + isEasy = ref.read(prefsChangeNotifierProvider).externalCalls; + infoToggle = isEasy; super.initState(); } @override void dispose() { - _pageController.dispose(); super.dispose(); } @@ -59,135 +56,161 @@ class _StackPrivacyCalls extends ConsumerState { ), ), body: SafeArea( - child: PageView( - controller: _pageController, - physics: const NeverScrollableScrollPhysics(), - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(0, 40, 0, 0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Choose your Stack experience", - style: STextStyles.pageTitleH1(context), - ), - const SizedBox( - height: 8, - ), - Text( - "You can change it later in Settings", - style: STextStyles.subtitle(context), - ), - const SizedBox( - height: 36, - ), - const Padding( - padding: EdgeInsets.symmetric( - horizontal: 16, - ), - child: PrivacyToggle(), - ), - const SizedBox( - height: 36, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: RoundedWhiteContainer( - child: Center( - child: RichText( - textAlign: TextAlign.left, - text: TextSpan( - style: STextStyles.label(context) - .copyWith(fontSize: 12.0), - children: ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - ) - ? [ - const TextSpan( - text: - "Exchange data preloaded for a seamless experience."), - const TextSpan( - text: - "\n\nCoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency)."), - TextSpan( - text: - "\n\nRecommended for most crypto users.", - style: TextStyle( - color: Theme.of(context) - .extension()! - .textDark, - fontWeight: FontWeight.w600, - ), - ), - ] - : [ - const TextSpan( - text: - "Exchange data not preloaded (slower experience)."), - const TextSpan( - text: - "\n\nCoinGecko disabled (price changes not shown, no wallet value shown in other currencies)."), - TextSpan( - text: - "\n\nRecommended for the privacy conscious.", - style: TextStyle( - color: Theme.of(context) - .extension()! - .textDark, - fontWeight: FontWeight.w600, - ), - ), - ], - ), - ), + child: Padding( + padding: const EdgeInsets.fromLTRB(0, 40, 0, 0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Choose your Stack experience", + style: STextStyles.pageTitleH1(context), + ), + const SizedBox( + height: 8, + ), + Text( + "You can change it later in Settings", + style: STextStyles.subtitle(context), + ), + const SizedBox( + height: 36, + ), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, + ), + child: PrivacyToggle( + externalCallsEnabled: isEasy, + onChanged: (externalCalls) { + isEasy = externalCalls; + setState(() { + infoToggle = isEasy; + }); + }, + ), + ), + const SizedBox( + height: 36, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: RoundedWhiteContainer( + child: Center( + child: RichText( + textAlign: TextAlign.left, + text: TextSpan( + style: + STextStyles.label(context).copyWith(fontSize: 12.0), + children: infoToggle + ? [ + const TextSpan( + text: + "Exchange data preloaded for a seamless experience."), + const TextSpan( + text: + "\n\nCoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency)."), + TextSpan( + text: + "\n\nRecommended for most crypto users.", + style: TextStyle( + color: Theme.of(context) + .extension()! + .textDark, + fontWeight: FontWeight.w600, + ), + ), + ] + : [ + const TextSpan( + text: + "Exchange data not preloaded (slower experience)."), + const TextSpan( + text: + "\n\nCoinGecko disabled (price changes not shown, no wallet value shown in other currencies)."), + TextSpan( + text: + "\n\nRecommended for the privacy conscious.", + style: TextStyle( + color: Theme.of(context) + .extension()! + .textDark, + fontWeight: FontWeight.w600, + ), + ), + ], ), ), ), - const Spacer( - flex: 4, - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 16, - ), - child: Row( - children: [ - Expanded( - child: ContinueButton( - isDesktop: isDesktop, - isSettings: widget.isSettings, - isEasy: ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - ), - ), - ), - ], - ), - ), - ], + ), ), - ), - ], + const Spacer( + flex: 4, + ), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 16, + ), + child: Row( + children: [ + Expanded( + child: ContinueButton( + isDesktop: isDesktop, + label: !widget.isSettings ? "Continue" : "Save changes", + onPressed: () { + ref.read(prefsChangeNotifierProvider).externalCalls = + isEasy; + if (!widget.isSettings) { + if (isDesktop) { + Navigator.of(context).pushNamed( + CreatePasswordView.routeName, + ); + } else { + Navigator.of(context).pushNamed( + CreatePinView.routeName, + ); + } + } else { + Navigator.pop(context); + } + }, + ), + ), + ], + ), + ), + ], + ), ), ), ); } } -class PrivacyToggle extends ConsumerStatefulWidget { - const PrivacyToggle({Key? key}) : super(key: key); +class PrivacyToggle extends StatefulWidget { + const PrivacyToggle({ + Key? key, + required this.externalCallsEnabled, + this.onChanged, + }) : super(key: key); + + final bool externalCallsEnabled; + final void Function(bool)? onChanged; @override - ConsumerState createState() => _PrivacyToggleState(); + State createState() => _PrivacyToggleState(); } -class _PrivacyToggleState extends ConsumerState { +class _PrivacyToggleState extends State { + late bool externalCallsEnabled; + + @override + void initState() { + // initial toggle state + externalCallsEnabled = widget.externalCallsEnabled; + super.initState(); + } + @override Widget build(BuildContext context) { return Row( @@ -196,11 +219,7 @@ class _PrivacyToggleState extends ConsumerState { child: RawMaterialButton( fillColor: Theme.of(context).extension()!.popupBG, shape: RoundedRectangleBorder( - side: !ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - ) + side: !externalCallsEnabled ? BorderSide.none : BorderSide( color: Theme.of(context) @@ -213,7 +232,12 @@ class _PrivacyToggleState extends ConsumerState { ), ), onPressed: () { - ref.read(prefsChangeNotifierProvider).externalCalls = true; + setState(() { + // update toggle state + externalCallsEnabled = true; + }); + // call callback with newly set value + widget.onChanged?.call(externalCallsEnabled); }, child: Padding( padding: const EdgeInsets.all( @@ -244,11 +268,7 @@ class _PrivacyToggleState extends ConsumerState { ), ], ), - if (ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - )) + if (externalCallsEnabled) Positioned( top: 4, right: 4, @@ -261,11 +281,7 @@ class _PrivacyToggleState extends ConsumerState { .infoItemIcons, ), ), - if (!ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - )) + if (!externalCallsEnabled) Positioned( top: 4, right: 4, @@ -293,11 +309,7 @@ class _PrivacyToggleState extends ConsumerState { elevation: 0, fillColor: Theme.of(context).extension()!.popupBG, shape: RoundedRectangleBorder( - side: ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - ) + side: externalCallsEnabled ? BorderSide.none : BorderSide( color: Theme.of(context) @@ -310,7 +322,12 @@ class _PrivacyToggleState extends ConsumerState { ), ), onPressed: () { - ref.read(prefsChangeNotifierProvider).externalCalls = false; + setState(() { + // update toggle state + externalCallsEnabled = false; + }); + // call callback with newly set value + widget.onChanged?.call(externalCallsEnabled); }, child: Padding( padding: const EdgeInsets.all( @@ -342,11 +359,7 @@ class _PrivacyToggleState extends ConsumerState { ), ], ), - if (!ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - )) + if (!externalCallsEnabled) Positioned( top: 4, right: 4, @@ -359,11 +372,7 @@ class _PrivacyToggleState extends ConsumerState { .infoItemIcons, ), ), - if (ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.externalCalls, - ), - )) + if (externalCallsEnabled) Positioned( top: 4, right: 4, @@ -388,58 +397,47 @@ class _PrivacyToggleState extends ConsumerState { } } -class ContinueButton extends StatelessWidget { - const ContinueButton( - {Key? key, - required this.isDesktop, - required this.isSettings, - required this.isEasy}) - : super(key: key); +class ContinueButton extends ConsumerWidget { + const ContinueButton({ + Key? key, + required this.isDesktop, + required this.onPressed, + required this.label, + }) : super(key: key); + final String label; final bool isDesktop; - final bool isSettings; - final bool isEasy; + final VoidCallback onPressed; @override - Widget build(BuildContext context) { - return !isDesktop - ? TextButton( - style: Theme.of(context) - .extension()! - .getPrimaryEnabledButtonColor(context), - onPressed: () { - Prefs.instance.externalCalls = isEasy; - if (!isSettings) { - Navigator.of(context).pushNamed(CreatePinView.routeName); - } else { - Navigator.pop(context); - } - }, - child: Text( - !isSettings ? "Continue" : "Save changes", - style: STextStyles.button(context), - ), - ) - : SizedBox( - width: 328, - height: 70, - child: TextButton( - style: Theme.of(context) - .extension()! - .getPrimaryEnabledButtonColor(context), - onPressed: () { - Prefs.instance.externalCalls = isEasy; - - if (!isSettings) { - Navigator.of(context).pushNamed(CreatePinView.routeName); - } - }, - child: Text( - !isSettings ? "Continue" : "Save changes", - style: STextStyles.button(context).copyWith(fontSize: 20), - ), - ), - ); + Widget build(BuildContext context, WidgetRef ref) { + if (isDesktop) { + return SizedBox( + width: 328, + height: 70, + child: TextButton( + style: Theme.of(context) + .extension()! + .getPrimaryEnabledButtonColor(context), + onPressed: onPressed, + child: Text( + label, + style: STextStyles.button(context).copyWith(fontSize: 20), + ), + ), + ); + } else { + return TextButton( + style: Theme.of(context) + .extension()! + .getPrimaryEnabledButtonColor(context), + onPressed: onPressed, + child: Text( + label, + style: STextStyles.button(context), + ), + ); + } } }