added conditional for desktop manual and restore backup

This commit is contained in:
ryleedavis 2022-11-04 14:18:54 -06:00
parent 9231c3a2a5
commit a6c380592e
2 changed files with 695 additions and 663 deletions

View file

@ -15,6 +15,7 @@ import 'package:stackwallet/utilities/logger.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/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/progress_bar.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
@ -93,8 +94,14 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
@override
Widget build(BuildContext context) {
final isDesktop = Util.isDesktop;
return ConditionalParent(
condition: !isDesktop,
builder: (child) {
return Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () async {
@ -122,6 +129,30 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: child,
),
),
);
},
),
),
);
},
child: ConditionalParent(
condition: isDesktop,
builder: (child) {
return Column(
children: [
Text(
"Choose file location",
style: STextStyles.desktopTextExtraSmall(context).copyWith(
color:
Theme.of(context).extension<StackColors>()!.textDark3),
),
// child,
],
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@ -139,8 +170,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
await stackFileSystem.prepareStorage();
if (mounted) {
await stackFileSystem
.pickDir(context);
await stackFileSystem.pickDir(context);
}
if (mounted) {
@ -150,8 +180,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
});
}
} catch (e, s) {
Logging.instance.log("$e\n$s",
level: LogLevel.Error);
Logging.instance
.log("$e\n$s", level: LogLevel.Error);
}
},
controller: fileLocationController,
@ -180,8 +210,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
),
),
),
key: const Key(
"createBackupSaveToFileLocationTextFieldKey"),
key:
const Key("createBackupSaveToFileLocationTextFieldKey"),
readOnly: true,
toolbarOptions: const ToolbarOptions(
copy: true,
@ -231,9 +261,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
});
},
child: SvgPicture.asset(
hidePassword
? Assets.svg.eye
: Assets.svg.eyeSlash,
hidePassword ? Assets.svg.eye : Assets.svg.eyeSlash,
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
@ -257,8 +285,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
}
final result = zxcvbn.evaluate(newValue);
String suggestionsAndTips = "";
for (var sug
in result.feedback.suggestions!.toSet()) {
for (var sug in result.feedback.suggestions!.toSet()) {
suggestionsAndTips += "$sug\n";
}
suggestionsAndTips += result.feedback.warning!;
@ -275,8 +302,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
}
if (feedback.endsWith("\n")) {
feedback =
feedback.substring(0, feedback.length - 2);
feedback = feedback.substring(0, feedback.length - 2);
}
setState(() {
@ -328,9 +354,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
backgroundColor: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
percent: passwordStrength < 0.25
? 0.03
: passwordStrength,
percent: passwordStrength < 0.25 ? 0.03 : passwordStrength,
),
),
const SizedBox(
@ -368,9 +392,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
});
},
child: SvgPicture.asset(
hidePassword
? Assets.svg.eye
: Assets.svg.eyeSlash,
hidePassword ? Assets.svg.eye : Assets.svg.eyeSlash,
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
@ -406,10 +428,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
onPressed: !shouldEnableCreate
? null
: () async {
final String pathToSave =
fileLocationController.text;
final String passphrase =
passwordController.text;
final String pathToSave = fileLocationController.text;
final String passphrase = passwordController.text;
final String repeatPassphrase =
passwordRepeatController.text;
@ -455,18 +475,15 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
),
));
// make sure the dialog is able to be displayed for at least 1 second
await Future<void>.delayed(
const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
final DateTime now = DateTime.now();
final String fileToSave =
"$pathToSave/stackbackup_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.swb";
final backup =
await SWB.createStackWalletJSON();
final backup = await SWB.createStackWalletJSON();
bool result =
await SWB.encryptStackWalletWithPassphrase(
bool result = await SWB.encryptStackWalletWithPassphrase(
fileToSave,
passphrase,
jsonEncode(backup),
@ -486,8 +503,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
message: fileToSave,
)
: const StackOkDialog(
title:
"Backup creation succeeded"),
title: "Backup creation succeeded"),
);
passwordController.text = "";
passwordRepeatController.text = "";
@ -510,11 +526,6 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
],
),
),
),
);
},
),
),
);
}
}

View file

@ -15,13 +15,13 @@ import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
import 'package:stackwallet/utilities/logger.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/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/stack_text_field.dart';
import 'package:tuple/tuple.dart';
import 'package:stackwallet/utilities/util.dart';
class RestoreFromFileView extends ConsumerStatefulWidget {
const RestoreFromFileView({Key? key}) : super(key: key);
@ -65,14 +65,21 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
@override
Widget build(BuildContext context) {
final isDesktop = Util.isDesktop;
return ConditionalParent(
condition: !isDesktop,
builder: (child) {
return Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () async {
if (FocusScope.of(context).hasFocus) {
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 75));
await Future<void>.delayed(
const Duration(milliseconds: 75));
}
if (mounted) {
Navigator.of(context).pop();
@ -94,6 +101,31 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: child,
),
),
);
},
),
),
);
},
child: ConditionalParent(
condition: isDesktop,
builder: (child) {
return Column(
children: [
Text(
"Choose file location",
style: STextStyles.desktopTextExtraSmall(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark3),
),
// child,
],
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@ -114,8 +146,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
});
}
} catch (e, s) {
Logging.instance
.log("$e\n$s", level: LogLevel.Error);
Logging.instance.log("$e\n$s", level: LogLevel.Error);
}
},
controller: fileLocationController,
@ -230,8 +261,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
: () async {
final String fileToRestore =
fileLocationController.text;
final String passphrase =
passwordController.text;
final String passphrase = passwordController.text;
if (FocusScope.of(context).hasFocus) {
FocusScope.of(context).unfocus();
@ -257,18 +287,15 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
return shouldPop;
},
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Material(
color: Colors.transparent,
child: Center(
child: Text(
"Decrypting Stack backup file",
style: STextStyles.pageTitleH2(
context)
style: STextStyles.pageTitleH2(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
@ -328,12 +355,6 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
),
],
),
),
),
);
},
),
),
);
));
}
}