stack experience dialog for desktop advanced settings

This commit is contained in:
ryleedavis 2022-11-02 09:02:53 -06:00
parent fc25ea2a24
commit 712b33833b
3 changed files with 531 additions and 65 deletions

View file

@ -2,16 +2,15 @@ import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/src/widgets/framework.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/pages/stack_privacy_calls.dart'; import 'package:stackwallet/pages_desktop_specific/home/advanced_settings/debug_info_dialog.dart';
import 'package:stackwallet/pages_desktop_specific/home/advanced_settings/stack_privacy_dialog.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/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import '../../../pages/settings_views/global_settings_view/advanced_views/debug_view.dart';
import '../../../providers/global/prefs_provider.dart';
import '../../../widgets/custom_buttons/draggable_switch_button.dart';
class AdvancedSettings extends ConsumerStatefulWidget { class AdvancedSettings extends ConsumerStatefulWidget {
const AdvancedSettings({Key? key}) : super(key: key); const AdvancedSettings({Key? key}) : super(key: key);
@ -109,7 +108,12 @@ class _AdvancedSettings extends ConsumerState<AdvancedSettings> {
), ),
/// TODO: Make a dialog popup /// TODO: Make a dialog popup
Padding( Consumer(builder: (_, ref, __) {
final externalCalls = ref.watch(
prefsChangeNotifierProvider
.select((value) => value.externalCalls),
);
return Padding(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -128,7 +132,7 @@ class _AdvancedSettings extends ConsumerState<AdvancedSettings> {
textAlign: TextAlign.left, textAlign: TextAlign.left,
), ),
Text( Text(
"Easy Crypto", externalCalls ? "Easy crypto" : "Incognito",
style: STextStyles.desktopTextExtraExtraSmall( style: STextStyles.desktopTextExtraExtraSmall(
context), context),
), ),
@ -137,6 +141,9 @@ class _AdvancedSettings extends ConsumerState<AdvancedSettings> {
const StackPrivacyButton(), const StackPrivacyButton(),
], ],
), ),
);
}),
],
), ),
const Padding( const Padding(
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
@ -166,8 +173,6 @@ class _AdvancedSettings extends ConsumerState<AdvancedSettings> {
), ),
], ],
), ),
],
),
), ),
), ),
], ],
@ -181,6 +186,17 @@ class StackPrivacyButton extends ConsumerWidget {
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
Future<void> changePrivacySettings() async {
await showDialog<dynamic>(
context: context,
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return StackPrivacyDialog();
},
);
}
return SizedBox( return SizedBox(
width: 84, width: 84,
height: 37, height: 37,
@ -189,10 +205,11 @@ class StackPrivacyButton extends ConsumerWidget {
.extension<StackColors>()! .extension<StackColors>()!
.getPrimaryEnabledButtonColor(context), .getPrimaryEnabledButtonColor(context),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed( // Navigator.of(context).pushNamed(
StackPrivacyCalls.routeName, // StackPrivacyCalls.routeName,
arguments: false, // arguments: false,
); // );
changePrivacySettings();
}, },
child: Text( child: Text(
"Change", "Change",
@ -210,6 +227,17 @@ class ShowLogsButton extends ConsumerWidget {
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
Future<void> viewDebugLogs() async {
await showDialog<dynamic>(
context: context,
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return const DebugInfoDialog();
},
);
}
return SizedBox( return SizedBox(
width: 101, width: 101,
height: 37, height: 37,
@ -218,7 +246,8 @@ class ShowLogsButton extends ConsumerWidget {
.extension<StackColors>()! .extension<StackColors>()!
.getPrimaryEnabledButtonColor(context), .getPrimaryEnabledButtonColor(context),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed(DebugView.routeName); //
viewDebugLogs();
}, },
child: Text( child: Text(
"Show logs", "Show logs",

View file

@ -0,0 +1,437 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import '../../../hive/db.dart';
import '../../../providers/global/prefs_provider.dart';
import '../../../providers/global/price_provider.dart';
import '../../../services/exchange/exchange_data_loading_service.dart';
import '../../../utilities/assets.dart';
import '../../../utilities/constants.dart';
import '../../../utilities/theme/stack_colors.dart';
import '../../../utilities/util.dart';
import '../../../widgets/rounded_white_container.dart';
class StackPrivacyDialog extends ConsumerStatefulWidget {
const StackPrivacyDialog({Key? key}) : super(key: key);
@override
ConsumerState<StackPrivacyDialog> createState() => _StackPrivacyDialog();
}
class _StackPrivacyDialog extends ConsumerState<StackPrivacyDialog> {
late final bool isDesktop;
late bool isEasy;
late bool infoToggle;
@override
void initState() {
isDesktop = Util.isDesktop;
isEasy = ref.read(prefsChangeNotifierProvider).externalCalls;
infoToggle = isEasy;
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return DesktopDialog(
maxHeight: 650,
maxWidth: 600,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(32),
child: Text(
"Choose Your Stack Experience",
style: STextStyles.desktopH3(context),
textAlign: TextAlign.center,
),
),
const DesktopDialogCloseButton(),
],
),
const SizedBox(
height: 35,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: PrivacyToggle(
externalCallsEnabled: isEasy,
onChanged: (externalCalls) {
isEasy = externalCalls;
setState(() {
infoToggle = isEasy;
});
},
),
),
Padding(
padding: const EdgeInsets.all(32.0),
child: RoundedWhiteContainer(
borderColor: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
child: Center(
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
: 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: isDesktop
? STextStyles.desktopTextExtraExtraSmall600(
context)
: TextStyle(
color: Theme.of(context)
.extension<StackColors>()!
.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: isDesktop
? STextStyles.desktopTextExtraExtraSmall600(
context)
: TextStyle(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
),
),
// const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Row(
children: [
Expanded(
child: SecondaryButton(
label: "Cancel",
onPressed: () {},
),
),
const SizedBox(
width: 16,
),
Expanded(
child: PrimaryButton(
label: "Save",
onPressed: () {
ref.read(prefsChangeNotifierProvider).externalCalls =
isEasy;
DB.instance
.put<dynamic>(
boxName: DB.boxNamePrefs,
key: "externalCalls",
value: isEasy)
.then((_) {
if (isEasy) {
unawaited(ExchangeDataLoadingService().loadAll(ref));
ref
.read(priceAnd24hChangeNotifierProvider)
.start(true);
}
});
if (isDesktop) {
Navigator.pop(context);
}
},
),
)
],
),
),
],
),
);
}
}
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
State<PrivacyToggle> createState() => _PrivacyToggleState();
}
class _PrivacyToggleState extends State<PrivacyToggle> {
late bool externalCallsEnabled;
late final bool isDesktop;
@override
void initState() {
isDesktop = Util.isDesktop;
// initial toggle state
externalCallsEnabled = widget.externalCallsEnabled;
super.initState();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: RawMaterialButton(
elevation: 0,
hoverElevation: 0,
fillColor: Theme.of(context).extension<StackColors>()!.popupBG,
shape: RoundedRectangleBorder(
side: !externalCallsEnabled
? BorderSide.none
: BorderSide(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
width: 2,
),
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius * 2,
),
),
onPressed: () {
setState(() {
// update toggle state
externalCallsEnabled = true;
});
// call callback with newly set value
widget.onChanged?.call(externalCallsEnabled);
},
child: Padding(
padding: const EdgeInsets.all(
12,
),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (isDesktop)
const SizedBox(
height: 10,
),
SvgPicture.asset(
Assets.svg.personaEasy,
width: 120,
height: 120,
),
if (isDesktop)
const SizedBox(
height: 12,
),
Center(
child: Text(
"Easy Crypto",
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.label700(context),
),
),
Center(
child: Text(
"Recommended",
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.label(context),
),
),
if (isDesktop)
const SizedBox(
height: 12,
),
],
),
if (externalCallsEnabled)
Positioned(
top: 4,
right: 4,
child: SvgPicture.asset(
Assets.svg.checkCircle,
width: 20,
height: 20,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
),
if (!externalCallsEnabled)
Positioned(
top: 4,
right: 4,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1000),
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
),
),
),
],
),
),
),
),
const SizedBox(
width: 16,
),
Expanded(
child: RawMaterialButton(
elevation: 0,
hoverElevation: 0,
fillColor: Theme.of(context).extension<StackColors>()!.popupBG,
shape: RoundedRectangleBorder(
side: externalCallsEnabled
? BorderSide.none
: BorderSide(
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
width: 2,
),
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius * 2,
),
),
onPressed: () {
setState(() {
// update toggle state
externalCallsEnabled = false;
});
// call callback with newly set value
widget.onChanged?.call(externalCallsEnabled);
},
child: Padding(
padding: const EdgeInsets.all(
12,
),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (isDesktop)
const SizedBox(
height: 10,
),
SvgPicture.asset(
Assets.svg.personaIncognito,
width: 120,
height: 120,
),
if (isDesktop)
const SizedBox(
height: 12,
),
Center(
child: Text(
"Incognito",
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.label700(context),
),
),
Center(
child: Text(
"Privacy conscious",
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.label(context),
),
),
if (isDesktop)
const SizedBox(
height: 12,
),
],
),
if (!externalCallsEnabled)
Positioned(
top: 4,
right: 4,
child: SvgPicture.asset(
Assets.svg.checkCircle,
width: 20,
height: 20,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
),
if (externalCallsEnabled)
Positioned(
top: 4,
right: 4,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1000),
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
),
),
),
],
),
),
),
),
],
);
}
}