From bf27f38bb51c799d0bf5829999f77fbc6c319c6c Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 11 Oct 2022 08:15:51 -0600 Subject: [PATCH] WIP startup privacy options page layout --- lib/pages/stack_privacy_calls.dart | 260 +++++++++++++++++++++++------ lib/utilities/prefs.dart | 25 +++ 2 files changed, 236 insertions(+), 49 deletions(-) diff --git a/lib/pages/stack_privacy_calls.dart b/lib/pages/stack_privacy_calls.dart index c16e9d741..6f971408a 100644 --- a/lib/pages/stack_privacy_calls.dart +++ b/lib/pages/stack_privacy_calls.dart @@ -2,15 +2,15 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/pages/pinpad_views/create_pin_view.dart'; +import 'package:stackwallet/providers/global/prefs_provider.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/constants.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/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; -import 'package:stackwallet/hive/db.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/util.dart'; - class StackPrivacyCalls extends ConsumerStatefulWidget { const StackPrivacyCalls({ Key? key, @@ -73,55 +73,66 @@ class _StackPrivacyCalls extends ConsumerState { const SizedBox( height: 36, ), - Center( - child: CustomRadio((bool isEasy) { - setState(() { - this.isEasy = isEasy; - - DB.instance.put( - boxName: DB.boxNamePrefs, - key: "externalCalls", - value: isEasy); - }); - }), + const Padding( + padding: EdgeInsets.symmetric( + horizontal: 16, + ), + child: PrivacyToggle(), ), + // Center( + // child: CustomRadio((bool isEasy) { + // setState(() { + // this.isEasy = isEasy; + // + // DB.instance.put( + // boxName: DB.boxNamePrefs, + // key: "externalCalls", + // value: isEasy); + // }); + // }), + // ), const SizedBox( height: 36, ), - RoundedWhiteContainer( - child: Center( - child: RichText( - textAlign: TextAlign.left, - text: TextSpan( - style: - STextStyles.label(context).copyWith(fontSize: 12.0), - children: isEasy - ? const [ - TextSpan( - text: - "Exchange data preloaded for a seamless experience."), - 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(fontWeight: FontWeight.bold)), - ] - : const [ - TextSpan( - text: - "Exchange data not preloaded (slower experience)."), - 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(fontWeight: FontWeight.bold)), - ], + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, + ), + child: RoundedWhiteContainer( + child: Center( + child: RichText( + textAlign: TextAlign.left, + text: TextSpan( + style: STextStyles.label(context) + .copyWith(fontSize: 12.0), + children: isEasy + ? const [ + TextSpan( + text: + "Exchange data preloaded for a seamless experience."), + 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( + fontWeight: FontWeight.bold)), + ] + : const [ + TextSpan( + text: + "Exchange data not preloaded (slower experience)."), + 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( + fontWeight: FontWeight.bold)), + ], + ), ), ), ), @@ -153,6 +164,157 @@ class _StackPrivacyCalls extends ConsumerState { } } +class PrivacyToggle extends ConsumerStatefulWidget { + const PrivacyToggle({Key? key}) : super(key: key); + + @override + ConsumerState createState() => _PrivacyToggleState(); +} + +class _PrivacyToggleState extends ConsumerState { + @override + Widget build(BuildContext context) { + return Row( + children: [ + Expanded( + child: RawMaterialButton( + fillColor: Theme.of(context).extension()!.popupBG, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius * 2, + ), + ), + onPressed: () { + ref.read(prefsChangeNotifierProvider).externalCalls = true; + }, + child: Padding( + padding: const EdgeInsets.all( + 12, + ), + child: Column( + children: [ + SvgPicture.asset( + Assets.svg.personaEasy, + // color: Theme.of(context).extension()!.textWhite, + width: 96, + height: 96, + ), + const Text( + "Easy Crypto", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + const Text( + "Recommended", + ), + ], + ), + ), + ), + ), + const SizedBox( + width: 16, + ), + Expanded( + child: RawMaterialButton( + elevation: 0, + fillColor: Theme.of(context).extension()!.popupBG, + shape: RoundedRectangleBorder( + side: ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.externalCalls, + ), + ) + ? BorderSide.none + : BorderSide( + color: Theme.of(context) + .extension()! + .infoItemIcons, + width: 2, + ), + borderRadius: BorderRadius.circular( + Constants.size.circularBorderRadius * 2, + ), + ), + onPressed: () { + ref.read(prefsChangeNotifierProvider).externalCalls = false; + }, + child: Padding( + padding: const EdgeInsets.all( + 12, + ), + child: Stack( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SvgPicture.asset( + Assets.svg.personaIncognito, + width: 96, + height: 96, + ), + const Center( + child: Text( + "Incognito", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + ), + const Center( + child: Text( + "Privacy conscious", + ), + ), + ], + ), + if (!ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.externalCalls, + ), + )) + Positioned( + top: 4, + right: 4, + child: SvgPicture.asset( + Assets.svg.checkCircle, + width: 20, + height: 20, + color: Theme.of(context) + .extension()! + .infoItemIcons, + ), + ), + if (ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.externalCalls, + ), + )) + Positioned( + top: 4, + right: 4, + child: Container( + width: 20, + height: 20, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(1000), + color: Theme.of(context) + .extension()! + .textFieldDefaultBG, + ), + ), + ), + ], + ), + ), + ), + ), + ], + ); + } +} + class ContinueButton extends StatelessWidget { const ContinueButton({Key? key, required this.isDesktop}) : super(key: key); diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 578cf35a4..7e1096550 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -36,6 +36,7 @@ class Prefs extends ChangeNotifier { _hideBlockExplorerWarning = await _getHideBlockExplorerWarning(); _gotoWalletOnStartup = await _getGotoWalletOnStartup(); _startupWalletId = await _getStartupWalletId(); + _externalCalls = await _getHasExternalCalls(); _initialized = true; } @@ -544,4 +545,28 @@ class Prefs extends ChangeNotifier { return await DB.instance.get( boxName: DB.boxNamePrefs, key: "startupWalletId") as String?; } + + bool _externalCalls = false; + + bool get externalCalls => _externalCalls; + + set externalCalls(bool externalCalls) { + if (_externalCalls != externalCalls) { + DB.instance + .put( + boxName: DB.boxNamePrefs, + key: "externalCalls", + value: externalCalls) + .then((_) { + _externalCalls = externalCalls; + notifyListeners(); + }); + } + } + + Future _getHasExternalCalls() async { + return await DB.instance.get( + boxName: DB.boxNamePrefs, key: "externalCalls") as bool? ?? + false; + } }