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,11 +56,7 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
), ),
), ),
body: SafeArea( body: SafeArea(
child: PageView( child: Padding(
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 40, 0, 0), padding: const EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -82,11 +75,19 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
const SizedBox( const SizedBox(
height: 36, height: 36,
), ),
const Padding( Padding(
padding: EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 16, horizontal: 16,
), ),
child: PrivacyToggle(), child: PrivacyToggle(
externalCallsEnabled: isEasy,
onChanged: (externalCalls) {
isEasy = externalCalls;
setState(() {
infoToggle = isEasy;
});
},
),
), ),
const SizedBox( const SizedBox(
height: 36, height: 36,
@ -98,13 +99,9 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
child: RichText( child: RichText(
textAlign: TextAlign.left, textAlign: TextAlign.left,
text: TextSpan( text: TextSpan(
style: STextStyles.label(context) style:
.copyWith(fontSize: 12.0), STextStyles.label(context).copyWith(fontSize: 12.0),
children: ref.watch( children: infoToggle
prefsChangeNotifierProvider.select(
(value) => value.externalCalls,
),
)
? [ ? [
const TextSpan( const TextSpan(
text: text:
@ -159,12 +156,24 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
Expanded( Expanded(
child: ContinueButton( child: ContinueButton(
isDesktop: isDesktop, isDesktop: isDesktop,
isSettings: widget.isSettings, label: !widget.isSettings ? "Continue" : "Save changes",
isEasy: ref.watch( onPressed: () {
prefsChangeNotifierProvider.select( ref.read(prefsChangeNotifierProvider).externalCalls =
(value) => value.externalCalls, isEasy;
), if (!widget.isSettings) {
), if (isDesktop) {
Navigator.of(context).pushNamed(
CreatePasswordView.routeName,
);
} else {
Navigator.of(context).pushNamed(
CreatePinView.routeName,
);
}
} else {
Navigator.pop(context);
}
},
), ),
), ),
], ],
@ -173,21 +182,35 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
], ],
), ),
), ),
],
),
), ),
); );
} }
} }
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)
.extension<StackColors>()!
.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, width: 328,
height: 70, height: 70,
child: TextButton( child: TextButton(
style: Theme.of(context) style: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.getPrimaryEnabledButtonColor(context), .getPrimaryEnabledButtonColor(context),
onPressed: () { onPressed: onPressed,
Prefs.instance.externalCalls = isEasy;
if (!isSettings) {
Navigator.of(context).pushNamed(CreatePinView.routeName);
}
},
child: Text( child: Text(
!isSettings ? "Continue" : "Save changes", label,
style: STextStyles.button(context).copyWith(fontSize: 20), style: STextStyles.button(context).copyWith(fontSize: 20),
), ),
), ),
); );
} else {
return TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonColor(context),
onPressed: onPressed,
child: Text(
label,
style: STextStyles.button(context),
),
);
}
} }
} }