only save incognito setting on explicit button press

This commit is contained in:
julian 2022-10-17 14:15:25 -06:00
parent a62d8f49a8
commit 78b6d096fe

View file

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