fix: Bootstrap column design

This commit is contained in:
Krille Fear 2021-10-14 16:56:08 +02:00
parent 24ceea0882
commit dd5f9b2c42
1 changed files with 144 additions and 134 deletions

View File

@ -1,5 +1,5 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:fluffychat/widgets/layouts/one_page_card.dart'; import 'package:fluffychat/config/themes.dart';
import 'package:matrix/encryption.dart'; import 'package:matrix/encryption.dart';
import 'package:matrix/encryption/utils/bootstrap.dart'; import 'package:matrix/encryption/utils/bootstrap.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
@ -92,41 +92,46 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
_recoveryKeyStored == false) { _recoveryKeyStored == false) {
final key = bootstrap.newSsssKey.recoveryKey; final key = bootstrap.newSsssKey.recoveryKey;
titleText = L10n.of(context).securityKey; titleText = L10n.of(context).securityKey;
return OnePageCard( return AlertDialog(
child: Scaffold( title: AppBar(
appBar: AppBar( centerTitle: true,
leading: IconButton( leading: IconButton(
icon: Icon(Icons.close), icon: Icon(Icons.close),
onPressed: Navigator.of(context).pop, onPressed: Navigator.of(context).pop,
),
title: Text(L10n.of(context).securityKey),
), ),
body: ListView( title: Text(L10n.of(context).securityKey),
padding: const EdgeInsets.all(16.0), ),
children: [ content: Center(
TextField( child: ConstrainedBox(
minLines: 4, constraints:
maxLines: 4, BoxConstraints(maxWidth: FluffyThemes.columnWidth * 1.5),
readOnly: true, child: ListView(
controller: TextEditingController(text: key), padding: const EdgeInsets.all(16.0),
), children: [
const SizedBox(height: 16), TextField(
ElevatedButton.icon( minLines: 4,
icon: Icon(Icons.copy_outlined), maxLines: 4,
label: Text(L10n.of(context).copyToClipboard), readOnly: true,
onPressed: () => Clipboard.setData(ClipboardData(text: key)), controller: TextEditingController(text: key),
),
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Theme.of(context).primaryColor,
), ),
icon: Icon(Icons.check_outlined), const SizedBox(height: 16),
label: Text(L10n.of(context).iWroteDownTheKey), ElevatedButton.icon(
onPressed: () => setState(() => _recoveryKeyStored = true), icon: Icon(Icons.copy_outlined),
), label: Text(L10n.of(context).copyToClipboard),
], onPressed: () => Clipboard.setData(ClipboardData(text: key)),
),
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Theme.of(context).primaryColor,
),
icon: Icon(Icons.check_outlined),
label: Text(L10n.of(context).iWroteDownTheKey),
onPressed: () => setState(() => _recoveryKeyStored = true),
),
],
),
), ),
), ),
); );
@ -161,110 +166,115 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
break; break;
case BootstrapState.openExistingSsss: case BootstrapState.openExistingSsss:
_recoveryKeyStored = true; _recoveryKeyStored = true;
return OnePageCard( return Scaffold(
child: Scaffold( appBar: AppBar(
appBar: AppBar( centerTitle: true,
leading: IconButton( leading: IconButton(
icon: Icon(Icons.close), icon: Icon(Icons.close),
onPressed: Navigator.of(context).pop, onPressed: Navigator.of(context).pop,
),
title: Text(L10n.of(context).pleaseEnterSecurityKey),
), ),
body: ListView( title: Text(L10n.of(context).pleaseEnterSecurityKey),
padding: const EdgeInsets.all(16.0), ),
children: [ body: Center(
TextField( child: ConstrainedBox(
minLines: 4, constraints:
maxLines: 4, BoxConstraints(maxWidth: FluffyThemes.columnWidth * 1.5),
autofocus: true, child: ListView(
autocorrect: false, padding: const EdgeInsets.all(16.0),
autofillHints: _recoveryKeyInputLoading children: [
? null TextField(
: [AutofillHints.password], minLines: 4,
controller: _recoveryKeyTextEditingController, maxLines: 4,
decoration: InputDecoration( autofocus: true,
hintText: 'Abc123 Def456', autocorrect: false,
labelText: L10n.of(context).securityKey, autofillHints: _recoveryKeyInputLoading
errorText: _recoveryKeyInputError, ? null
: [AutofillHints.password],
controller: _recoveryKeyTextEditingController,
decoration: InputDecoration(
hintText: 'Abc123 Def456',
labelText: L10n.of(context).securityKey,
errorText: _recoveryKeyInputError,
),
), ),
), const SizedBox(height: 16),
const SizedBox(height: 16), ElevatedButton.icon(
ElevatedButton.icon( icon: Icon(Icons.lock_open_outlined),
icon: Icon(Icons.lock_open_outlined), label: Text(L10n.of(context).unlockChatBackup),
label: Text(L10n.of(context).unlockChatBackup), onPressed: () async {
setState(() {
_recoveryKeyInputError = null;
_recoveryKeyInputLoading = true;
});
try {
await bootstrap.newSsssKey.unlock(
keyOrPassphrase:
_recoveryKeyTextEditingController.text,
);
await bootstrap.openExistingSsss();
} catch (e, s) {
Logs().w('Unable to unlock SSSS', e, s);
setState(() => _recoveryKeyInputError =
L10n.of(context).oopsSomethingWentWrong);
} finally {
setState(() => _recoveryKeyInputLoading = false);
}
}),
const SizedBox(height: 16),
Row(children: [
Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
Expanded(child: Divider()),
]),
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Theme.of(context).primaryColor,
),
icon: Icon(Icons.transfer_within_a_station_outlined),
label: Text(L10n.of(context).transferFromAnotherDevice),
onPressed: () async { onPressed: () async {
setState(() { final req = await showFutureLoadingDialog(
_recoveryKeyInputError = null; context: context,
_recoveryKeyInputLoading = true; future: () => widget
}); .client.userDeviceKeys[widget.client.userID]
try { .startVerification(),
await bootstrap.newSsssKey.unlock( );
keyOrPassphrase: if (req.error != null) return;
_recoveryKeyTextEditingController.text, await KeyVerificationDialog(request: req.result)
); .show(context);
await bootstrap.openExistingSsss(); Navigator.of(context, rootNavigator: false).pop();
} catch (e, s) { },
Logs().w('Unable to unlock SSSS', e, s); ),
setState(() => _recoveryKeyInputError = const SizedBox(height: 16),
L10n.of(context).oopsSomethingWentWrong); ElevatedButton.icon(
} finally { style: ElevatedButton.styleFrom(
setState(() => _recoveryKeyInputLoading = false); primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Colors.red,
),
icon: Icon(Icons.delete_outlined),
label: Text(L10n.of(context).securityKeyLost),
onPressed: () async {
if (OkCancelResult.ok ==
await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).securityKeyLost,
message: L10n.of(context).wipeChatBackup,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
isDestructiveAction: true,
)) {
_createBootstrap(true);
} }
}), },
const SizedBox(height: 16), )
Row(children: [ ],
Expanded(child: Divider()), ),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
Expanded(child: Divider()),
]),
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Theme.of(context).primaryColor,
),
icon: Icon(Icons.transfer_within_a_station_outlined),
label: Text(L10n.of(context).transferFromAnotherDevice),
onPressed: () async {
final req = await showFutureLoadingDialog(
context: context,
future: () => widget
.client.userDeviceKeys[widget.client.userID]
.startVerification(),
);
if (req.error != null) return;
await KeyVerificationDialog(request: req.result)
.show(context);
Navigator.of(context, rootNavigator: false).pop();
},
),
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary: Colors.red,
),
icon: Icon(Icons.delete_outlined),
label: Text(L10n.of(context).securityKeyLost),
onPressed: () async {
if (OkCancelResult.ok ==
await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).securityKeyLost,
message: L10n.of(context).wipeChatBackup,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
isDestructiveAction: true,
)) {
_createBootstrap(true);
}
},
)
],
), ),
), ),
); );