2021-07-12 04:32:49 -07:00
|
|
|
import 'package:flutter/material.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> {
|
2021-09-10 02:56:15 -07:00
|
|
|
late Backup backup;
|
2021-07-12 04:32:49 -07:00
|
|
|
final _backupController = TextEditingController();
|
|
|
|
final _skController = TextEditingController();
|
|
|
|
final _ivkController = TextEditingController();
|
|
|
|
|
|
|
|
Future<bool> _init() async {
|
|
|
|
backup = await accountManager.getBackup();
|
|
|
|
_backupController.text = backup.value();
|
2021-09-10 23:05:48 -07:00
|
|
|
_skController.text = backup.sk ?? "";
|
2021-09-10 02:56:15 -07:00
|
|
|
_ivkController.text = backup.ivk;
|
2021-07-12 04:32:49 -07:00
|
|
|
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-09-10 23:05:48 -07:00
|
|
|
onPressed: () => _showQR(backup.sk!))),
|
2021-07-12 04:32:49 -07:00
|
|
|
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
|
|
|
]
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-27 19:10:33 -07:00
|
|
|
_showQR(String text) => showQR(context, text);
|
2021-07-12 04:32:49 -07:00
|
|
|
}
|