zwallet/lib/backup.dart

79 lines
2.5 KiB
Dart
Raw Normal View History

2021-07-12 04:32:49 -07:00
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'main.dart';
import 'store.dart';
2021-08-15 09:18:09 -07:00
import 'generated/l10n.dart';
2021-07-12 04:32:49 -07:00
class BackupPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => BackupState();
}
class BackupState extends State<BackupPage> {
Backup backup;
final _backupController = TextEditingController();
final _skController = TextEditingController();
final _ivkController = TextEditingController();
Future<bool> _init() async {
backup = await accountManager.getBackup();
_backupController.text = backup.value();
_skController.text = backup.sk ?? "";
_ivkController.text = backup.ivk ?? "";
return true;
}
@override
Widget build(BuildContext context) {
2021-08-15 09:18:09 -07:00
return Scaffold(appBar: AppBar(title: Text(S.of(context).backup)), body:
2021-07-12 04:32:49 -07:00
FutureBuilder(
future: _init(),
builder: _build,
));
}
Widget _build(BuildContext context, AsyncSnapshot<void> snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
final type = backup.type;
return Card(
child: Column(
children: [
TextField(
decoration: InputDecoration(
2021-08-15 09:18:09 -07:00
labelText: S.of(context).backupDataRequiredForRestore, prefixIcon: IconButton(icon: Icon(Icons.save),
2021-07-12 04:32:49 -07:00
onPressed: () => _showQR(backup.value()))),
controller: _backupController,
minLines: 3,
2021-08-06 19:18:20 -07:00
maxLines: 10,
2021-07-12 04:32:49 -07:00
readOnly: true,
),
if (type == 0) TextField(
2021-08-15 09:18:09 -07:00
decoration: InputDecoration(labelText: S.of(context).secretKey, prefixIcon: IconButton(icon: Icon(Icons.vpn_key),
2021-07-12 04:32:49 -07:00
onPressed: () => _showQR(backup.sk))),
controller: _skController,
minLines: 3,
maxLines: 10,
readOnly: true,
style: Theme.of(context).textTheme.caption
),
if (type != 2) TextField(
2021-08-15 09:18:09 -07:00
decoration: InputDecoration(labelText: S.of(context).viewingKey, prefixIcon: IconButton(icon: Icon(Icons.visibility),
2021-07-12 04:32:49 -07:00
onPressed: () => _showQR(backup.ivk))),
controller: _ivkController,
minLines: 3,
2021-08-06 19:18:20 -07:00
maxLines: 10,
2021-07-12 04:32:49 -07:00
readOnly: true,
style: Theme.of(context).textTheme.caption
),
Padding(padding: EdgeInsets.symmetric(vertical: 4)),
2021-08-15 09:18:09 -07:00
Text(S.of(context).tapAnIconToShowTheQrCode),
2021-07-12 04:32:49 -07:00
]
),
);
}
_showQR(String text) => showQR(context, text);
2021-07-12 04:32:49 -07:00
}