stack_wallet/lib/pages/stack_privacy_calls.dart

570 lines
21 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:async';
import 'dart:io';
2022-10-07 23:13:02 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
2024-05-27 23:56:22 +00:00
2024-07-08 17:27:20 +00:00
import '../app_config.dart';
import '../db/hive/db.dart';
import '../pages_desktop_specific/password/create_password_view.dart';
import '../providers/global/prefs_provider.dart';
import '../providers/global/price_provider.dart';
import '../services/exchange/exchange_data_loading_service.dart';
import '../themes/stack_colors.dart';
import '../themes/theme_providers.dart';
import '../utilities/assets.dart';
import '../utilities/constants.dart';
import '../utilities/text_styles.dart';
import '../utilities/util.dart';
import '../widgets/conditional_parent.dart';
import '../widgets/custom_buttons/app_bar_icon_button.dart';
import '../widgets/desktop/desktop_app_bar.dart';
import '../widgets/desktop/desktop_scaffold.dart';
import '../widgets/desktop/primary_button.dart';
import '../widgets/rounded_white_container.dart';
2024-05-27 23:56:22 +00:00
import 'pinpad_views/create_pin_view.dart';
2022-10-07 23:13:02 +00:00
class StackPrivacyCalls extends ConsumerStatefulWidget {
const StackPrivacyCalls({
2024-05-27 23:56:22 +00:00
super.key,
required this.isSettings,
2024-05-27 23:56:22 +00:00
});
2022-10-07 23:13:02 +00:00
final bool isSettings;
2022-10-07 23:13:02 +00:00
static const String routeName = "/stackPrivacy";
@override
ConsumerState<StackPrivacyCalls> createState() => _StackPrivacyCalls();
}
class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
late final bool isDesktop;
late bool isEasy;
late bool infoToggle;
2022-10-07 23:13:02 +00:00
@override
void initState() {
isDesktop = Util.isDesktop;
isEasy = ref.read(prefsChangeNotifierProvider).externalCalls;
infoToggle = isEasy;
super.initState();
}
2022-10-07 23:13:02 +00:00
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
2022-10-28 15:16:35 +00:00
return MasterScaffold(
background: Theme.of(context).extension<StackColors>()!.background,
isDesktop: isDesktop,
appBar: isDesktop
? const DesktopAppBar(
isCompactHeight: false,
leading: AppBarBackButton(),
)
: AppBar(
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
),
2022-10-07 23:13:02 +00:00
body: SafeArea(
child: ConditionalParent(
condition: !isDesktop,
builder: (child) => LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
2022-10-28 15:16:35 +00:00
),
child: IntrinsicHeight(
child: child,
2022-10-28 15:16:35 +00:00
),
),
),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0, isDesktop ? 0 : 40, 0, 0),
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: isDesktop ? 480 : double.infinity,
),
child: ConditionalParent(
condition: isDesktop,
builder: (child) => SingleChildScrollView(
child: child,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Choose your ${AppConfig.prefix} experience",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopH2(context)
: STextStyles.pageTitleH1(context),
),
SizedBox(
height: isDesktop ? 16 : 8,
),
Text(
!widget.isSettings
? "You can change it later in Settings"
: "",
style: isDesktop
? STextStyles.desktopSubtitleH2(context)
: STextStyles.subtitle(context),
),
SizedBox(
height: isDesktop ? 32 : 36,
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: isDesktop ? 0 : 16,
),
child: PrivacyToggle(
externalCallsEnabled: isEasy,
onChanged: (externalCalls) {
isEasy = externalCalls;
setState(() {
infoToggle = isEasy;
});
},
),
),
SizedBox(
height: isDesktop ? 16 : 36,
),
Padding(
padding: isDesktop
? const EdgeInsets.all(0)
: const EdgeInsets.all(16.0),
child: RoundedWhiteContainer(
child: Center(
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(
context,
)
: STextStyles.label(context).copyWith(
fontSize: 12.0,
),
children: infoToggle
? [
if (Constants.enableExchange)
const TextSpan(
text:
"Exchange data preloaded for a seamless experience.\n\n",
),
const TextSpan(
text:
"CoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency).\n\n",
2024-05-27 23:56:22 +00:00
),
TextSpan(
text:
"Recommended for most crypto users.",
style: isDesktop
? STextStyles
.desktopTextExtraExtraSmall600(
context,
)
: TextStyle(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
fontWeight: FontWeight.w600,
),
),
]
: [
if (Constants.enableExchange)
const TextSpan(
text:
"Exchange data not preloaded (slower experience).\n\n",
),
2023-03-27 16:48:51 +00:00
const TextSpan(
text:
"CoinGecko disabled (price changes not shown, no wallet value shown in other currencies).\n\n",
2024-05-27 23:56:22 +00:00
),
TextSpan(
text:
"Recommended for the privacy conscious.",
style: isDesktop
? STextStyles
.desktopTextExtraExtraSmall600(
context,
)
: TextStyle(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
fontWeight: FontWeight.w600,
),
),
],
),
),
2022-10-28 15:16:35 +00:00
),
2022-10-07 23:13:02 +00:00
),
),
if (!isDesktop)
const Spacer(
flex: 4,
),
if (isDesktop)
const SizedBox(
height: 32,
),
Padding(
padding: isDesktop
? const EdgeInsets.all(0)
: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
child: Row(
children: [
Expanded(
child: PrimaryButton(
label: !widget.isSettings
? "Continue"
: "Save changes",
onPressed: () {
ref
.read(prefsChangeNotifierProvider)
.externalCalls = isEasy;
DB.instance
.put<dynamic>(
boxName: DB.boxNamePrefs,
key: "externalCalls",
value: isEasy,
)
.then((_) {
if (isEasy) {
if (AppConfig.hasFeature(AppFeature.swap)) {
unawaited(
ExchangeDataLoadingService.instance
.loadAll(),
);
}
// unawaited(
// BuyDataLoadingService().loadAll(ref));
ref
.read(priceAnd24hChangeNotifierProvider)
.start(true);
}
});
if (!widget.isSettings) {
if (isDesktop) {
Navigator.of(context).pushNamed(
CreatePasswordView.routeName,
);
} else {
Navigator.of(context).pushNamed(
CreatePinView.routeName,
2024-07-08 17:27:20 +00:00
);
}
} else {
Navigator.pop(context);
}
},
),
),
],
),
),
if (isDesktop)
const SizedBox(
height: kDesktopAppBarHeight,
),
],
),
),
2022-10-28 15:16:35 +00:00
),
),
2022-10-07 23:13:02 +00:00
),
),
);
}
}
class PrivacyToggle extends ConsumerStatefulWidget {
const PrivacyToggle({
2024-05-27 23:56:22 +00:00
super.key,
required this.externalCallsEnabled,
this.onChanged,
2024-05-27 23:56:22 +00:00
});
final bool externalCallsEnabled;
final void Function(bool)? onChanged;
@override
ConsumerState<PrivacyToggle> createState() => _PrivacyToggleState();
}
class _PrivacyToggleState extends ConsumerState<PrivacyToggle> {
late bool externalCallsEnabled;
2022-10-28 15:16:35 +00:00
late final bool isDesktop;
@override
void initState() {
2022-10-28 15:16:35 +00:00
isDesktop = Util.isDesktop;
// initial toggle state
externalCallsEnabled = widget.externalCallsEnabled;
super.initState();
}
@override
Widget build(BuildContext context) {
final easyFile =
ref.watch(themeProvider.select((value) => value.assets.personaEasy));
final incognitoFile = ref
.watch(themeProvider.select((value) => value.assets.personaIncognito));
return Row(
children: [
Expanded(
child: RawMaterialButton(
2022-11-02 16:28:34 +00:00
elevation: 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: [
(easyFile.endsWith(".png"))
? Image.file(
File(
easyFile,
),
2023-04-17 15:56:51 +00:00
)
: SvgPicture.file(
File(
easyFile,
2023-04-25 22:11:26 +00:00
),
2023-04-17 15:56:51 +00:00
width: 140,
height: 140,
),
2022-10-11 21:28:56 +00:00
Center(
2022-10-28 15:16:35 +00:00
child: Text(
"Easy Crypto",
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.label700(context),
),
2022-10-28 15:16:35 +00:00
),
2022-10-11 21:28:56 +00:00
Center(
child: Text(
"Recommended",
2022-10-28 15:16:35 +00:00
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.label(context),
),
),
2022-10-28 15:16:35 +00:00
if (isDesktop)
const SizedBox(
height: 12,
),
],
2022-10-10 16:35:20 +00:00
),
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,
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: [
2022-10-28 15:16:35 +00:00
if (isDesktop)
const SizedBox(
height: 10,
),
(incognitoFile.endsWith(".png"))
? Image.file(
File(
incognitoFile,
),
2023-04-17 15:56:51 +00:00
)
: SvgPicture.file(
File(
incognitoFile,
2023-04-25 22:11:26 +00:00
),
2023-04-17 15:56:51 +00:00
width: 140,
height: 140,
),
// SvgPicture.asset(
// Assets.svg.personaIncognito(context),
// width: 140,
// height: 140,
// ),
2022-10-28 15:16:35 +00:00
if (isDesktop)
const SizedBox(
height: 12,
),
2022-10-11 21:28:56 +00:00
Center(
child: Text(
"Incognito",
2022-10-28 15:16:35 +00:00
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.label700(context),
2022-10-10 16:35:20 +00:00
),
2022-10-07 23:13:02 +00:00
),
2022-10-11 21:28:56 +00:00
Center(
child: Text(
"Privacy conscious",
2022-10-28 15:16:35 +00:00
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
: STextStyles.label(context),
),
),
2022-10-28 15:16:35 +00:00
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,
),
),
2022-10-10 16:35:20 +00:00
),
],
),
2022-10-07 23:13:02 +00:00
),
),
2022-10-07 23:13:02 +00:00
),
],
2022-10-07 23:13:02 +00:00
);
}
}