fix: Dialogs

This commit is contained in:
Christian Pauly 2021-01-19 15:46:43 +01:00
parent 1805a479a3
commit 5f0ce49c46
11 changed files with 104 additions and 68 deletions

View File

@ -11,10 +11,14 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../matrix.dart';
class BootstrapDialog extends StatefulWidget {
const BootstrapDialog({Key key, @required this.l10n}) : super(key: key);
Future<bool> show(BuildContext context) => PlatformInfos.isCupertinoStyle
? showCupertinoDialog(context: context, builder: (context) => this)
: showDialog(context: context, builder: (context) => this);
final L10n l10n;
@override
_BootstrapDialogState createState() => _BootstrapDialogState();
}
@ -39,36 +43,36 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
case BootstrapState.askWipeSsss:
body = Text('Wipe chat backup?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.wipeSsss(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.wipeSsss(false),
));
break;
case BootstrapState.askUseExistingSsss:
body = Text('Use existing chat backup?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.useExistingSsss(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.useExistingSsss(false),
));
break;
case BootstrapState.askBadSsss:
body = Text('SSSS bad - continue nevertheless? DATALOSS!!!');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.ignoreBadSecrets(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.ignoreBadSecrets(false),
));
break;
@ -77,14 +81,15 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
for (final entry in bootstrap.oldSsssKeys.entries) {
final keyId = entry.key;
final key = entry.value;
widgets.add(Flexible(child: _AskUnlockOldSsss(keyId, key)));
widgets
.add(Flexible(child: _AskUnlockOldSsss(keyId, key, widget.l10n)));
}
body = Column(
children: widgets,
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).confirm),
child: Text(widget.l10n.confirm),
onPressed: () => bootstrap.unlockedSsss(),
));
break;
@ -130,19 +135,19 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
case BootstrapState.askWipeCrossSigning:
body = Text('Wipe cross-signing?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.wipeCrossSigning(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.wipeCrossSigning(false),
));
break;
case BootstrapState.askSetupCrossSigning:
body = Text('Set up cross-signing?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.askSetupCrossSigning(
setupMasterKey: true,
setupSelfSigningKey: true,
@ -151,31 +156,31 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.askSetupCrossSigning(),
));
break;
case BootstrapState.askWipeOnlineKeyBackup:
body = Text('Wipe chat backup?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.wipeOnlineKeyBackup(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.wipeOnlineKeyBackup(false),
));
break;
case BootstrapState.askSetupOnlineKeyBackup:
body = Text('Set up chat backup?');
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).yes),
child: Text(widget.l10n.yes),
onPressed: () => bootstrap.askSetupOnlineKeyBackup(true),
));
buttons.add(AdaptiveFlatButton(
textColor: Theme.of(context).textTheme.bodyText1.color,
child: Text(L10n.of(context).no),
child: Text(widget.l10n.no),
onPressed: () => bootstrap.askSetupOnlineKeyBackup(false),
));
break;
@ -183,10 +188,10 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
body = ListTile(
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.error_outline, color: Colors.red),
title: Text(L10n.of(context).oopsSomethingWentWrong),
title: Text(widget.l10n.oopsSomethingWentWrong),
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close),
child: Text(widget.l10n.close),
onPressed: () => Navigator.of(context).pop<bool>(false),
));
break;
@ -197,7 +202,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
title: Text('Chat backup has been initialized!'),
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close),
child: Text(widget.l10n.close),
onPressed: () => Navigator.of(context).pop<bool>(false),
));
break;
@ -222,7 +227,8 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
class _AskUnlockOldSsss extends StatefulWidget {
final String keyId;
final OpenSSSS ssssKey;
_AskUnlockOldSsss(this.keyId, this.ssssKey);
final L10n l10n;
_AskUnlockOldSsss(this.keyId, this.ssssKey, this.l10n);
@override
_AskUnlockOldSsssState createState() => _AskUnlockOldSsssState();
@ -274,7 +280,7 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> {
maxLines: 1,
obscureText: true,
decoration: InputDecoration(
hintText: L10n.of(context).passphraseOrKey,
hintText: widget.l10n.passphraseOrKey,
prefixStyle: TextStyle(color: Theme.of(context).primaryColor),
suffixStyle: TextStyle(color: Theme.of(context).primaryColor),
border: OutlineInputBorder(),
@ -285,7 +291,7 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> {
color: Theme.of(context).primaryColor,
elevation: 5,
textColor: Colors.white,
child: Text(L10n.of(context).submit),
child: Text(widget.l10n.submit),
onPressed: () {
input = textEditingController.text;
checkInput(context);

View File

@ -16,7 +16,12 @@ class KeyVerificationDialog extends StatefulWidget {
final KeyVerification request;
KeyVerificationDialog({this.request});
final L10n l10n;
KeyVerificationDialog({
this.request,
@required this.l10n,
});
@override
_KeyVerificationPageState createState() => _KeyVerificationPageState();
@ -86,7 +91,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
if (valid.error != null) {
await showOkAlertDialog(
context: context,
message: L10n.of(context).incorrectPassphraseOrKey,
message: widget.l10n.incorrectPassphraseOrKey,
);
}
};
@ -94,8 +99,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
margin: EdgeInsets.only(left: 8.0, right: 8.0),
child: Column(
children: <Widget>[
Text(L10n.of(context).askSSSSSign,
style: TextStyle(fontSize: 20)),
Text(widget.l10n.askSSSSSign, style: TextStyle(fontSize: 20)),
Container(height: 10),
TextField(
controller: textEditingController,
@ -109,7 +113,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
maxLines: 1,
obscureText: true,
decoration: InputDecoration(
hintText: L10n.of(context).passphraseOrKey,
hintText: widget.l10n.passphraseOrKey,
prefixStyle: TextStyle(color: Theme.of(context).primaryColor),
suffixStyle: TextStyle(color: Theme.of(context).primaryColor),
border: OutlineInputBorder(),
@ -120,30 +124,29 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
),
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).submit),
child: Text(widget.l10n.submit),
onPressed: () {
input = textEditingController.text;
checkInput();
},
));
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).skip),
child: Text(widget.l10n.skip),
onPressed: () => widget.request.openSSSS(skip: true),
));
break;
case KeyVerificationState.askAccept:
body = Container(
child: Text(
L10n.of(context).askVerificationRequest(widget.request.userId),
child: Text(widget.l10n.askVerificationRequest(widget.request.userId),
style: TextStyle(fontSize: 20)),
margin: EdgeInsets.only(left: 8.0, right: 8.0),
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).accept),
child: Text(widget.l10n.accept),
onPressed: () => widget.request.acceptVerification(),
));
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).reject),
child: Text(widget.l10n.reject),
onPressed: () {
widget.request.rejectVerification().then((_) {
Navigator.of(context).pop();
@ -159,7 +162,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
: CircularProgressIndicator(),
SizedBox(height: 10),
Text(
L10n.of(context).waitingPartnerAcceptRequest,
widget.l10n.waitingPartnerAcceptRequest,
textAlign: TextAlign.center,
),
],
@ -172,14 +175,14 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
// view for if "emoji" is a present sasType or not?
String compareText;
if (widget.request.sasTypes.contains('emoji')) {
compareText = L10n.of(context).compareEmojiMatch;
compareText = widget.l10n.compareEmojiMatch;
compareWidget = TextSpan(
children: widget.request.sasEmojis
.map((e) => WidgetSpan(child: _Emoji(e)))
.toList(),
);
} else {
compareText = L10n.of(context).compareNumbersMatch;
compareText = widget.l10n.compareNumbersMatch;
final numbers = widget.request.sasNumbers;
final numbstr = '${numbers[0]}-${numbers[1]}-${numbers[2]}';
compareWidget =
@ -203,19 +206,19 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).theyMatch),
child: Text(widget.l10n.theyMatch),
onPressed: () => widget.request.acceptSas(),
));
buttons.add(AdaptiveFlatButton(
textColor: Colors.red,
child: Text(L10n.of(context).theyDontMatch),
child: Text(widget.l10n.theyDontMatch),
onPressed: () => widget.request.rejectSas(),
));
break;
case KeyVerificationState.waitingSas:
var acceptText = widget.request.sasTypes.contains('emoji')
? L10n.of(context).waitingPartnerEmoji
: L10n.of(context).waitingPartnerNumbers;
? widget.l10n.waitingPartnerEmoji
: widget.l10n.waitingPartnerNumbers;
body = Column(
children: <Widget>[
PlatformInfos.isCupertinoStyle
@ -236,14 +239,14 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
Icon(Icons.check_circle_outlined, color: Colors.green, size: 200.0),
SizedBox(height: 10),
Text(
L10n.of(context).verifySuccess,
widget.l10n.verifySuccess,
textAlign: TextAlign.center,
),
],
mainAxisSize: MainAxisSize.min,
);
buttons.add(AdaptiveFlatButton(
child: Text(L10n.of(context).close),
child: Text(widget.l10n.close),
onPressed: () => Navigator.of(context).pop(),
));
break;
@ -260,7 +263,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
mainAxisSize: MainAxisSize.min,
);
buttons.add(FlatButton(
child: Text(L10n.of(context).close),
child: Text(widget.l10n.close),
onPressed: () => Navigator.of(context).pop(),
));
break;
@ -305,7 +308,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
],
crossAxisAlignment: CrossAxisAlignment.start,
);
final title = Text(L10n.of(context).verifyTitle);
final title = Text(widget.l10n.verifyTitle);
final content = Scrollbar(
isAlwaysShown: true,
controller: _scrollController,

View File

@ -5,8 +5,13 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
class PermissionSliderDialog extends StatefulWidget {
const PermissionSliderDialog({Key key, this.initialPermission = 0})
: super(key: key);
const PermissionSliderDialog({
Key key,
this.initialPermission = 0,
@required this.l10n,
}) : super(key: key);
final L10n l10n;
Future<int> show(BuildContext context) => PlatformInfos.isCupertinoStyle
? showCupertinoDialog<int>(context: context, builder: (context) => this)
@ -41,7 +46,7 @@ class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
min: 0.0,
);
final title = Text(
L10n.of(context).setPermissionsLevel,
widget.l10n.setPermissionsLevel,
textAlign: TextAlign.center,
);
final content = Column(
@ -49,9 +54,9 @@ class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
children: [
Text('Level: ' +
(_permission == 100
? '$_permission (${L10n.of(context).admin})'
? '$_permission (${widget.l10n.admin})'
: _permission >= 50
? '$_permission (${L10n.of(context).moderator})'
? '$_permission (${widget.l10n.moderator})'
: _permission.toString())),
Container(
height: 56,
@ -61,11 +66,11 @@ class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
);
final buttons = [
AdaptiveFlatButton(
child: Text(L10n.of(context).cancel),
child: Text(widget.l10n.cancel),
onPressed: () => Navigator.of(context).pop<int>(null),
),
AdaptiveFlatButton(
child: Text(L10n.of(context).confirm),
child: Text(widget.l10n.confirm),
onPressed: () => Navigator.of(context).pop<int>(_permission),
),
];

View File

@ -7,8 +7,13 @@ import 'package:intl/intl.dart';
class RecordingDialog extends StatefulWidget {
final Function onFinished;
final L10n l10n;
const RecordingDialog({this.onFinished, Key key}) : super(key: key);
const RecordingDialog({
this.onFinished,
@required this.l10n,
Key key,
}) : super(key: key);
@override
_RecordingDialogState createState() => _RecordingDialogState();
@ -67,7 +72,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
SizedBox(width: 8),
Expanded(
child: Text(
'${L10n.of(context).recording}: $time',
'${widget.l10n.recording}: $time',
style: TextStyle(
fontSize: 18,
),
@ -78,7 +83,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
actions: <Widget>[
FlatButton(
child: Text(
L10n.of(context).cancel.toUpperCase(),
widget.l10n.cancel.toUpperCase(),
style: TextStyle(
color: Theme.of(context).textTheme.bodyText2.color.withAlpha(150),
),
@ -88,7 +93,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
FlatButton(
child: Row(
children: <Widget>[
Text(L10n.of(context).send.toUpperCase()),
Text(widget.l10n.send.toUpperCase()),
SizedBox(width: 4),
Icon(Icons.send_outlined, size: 15),
],

View File

@ -362,7 +362,10 @@ class MatrixState extends State<Matrix> {
request.onUpdate = null;
hidPopup = true;
await request.acceptVerification();
await KeyVerificationDialog(request: request).show(context);
await KeyVerificationDialog(
request: request,
l10n: L10n.of(context),
).show(context);
} else {
request.onUpdate = null;
hidPopup = true;

View File

@ -52,7 +52,10 @@ class MessageContent extends StatelessWidget {
timeline.cancelSubscriptions();
}
};
await KeyVerificationDialog(request: req).show(context);
await KeyVerificationDialog(
request: req,
l10n: L10n.of(context),
).show(context);
} else {
final success = await showFutureLoadingDialog(
context: context,

View File

@ -59,9 +59,10 @@ class UserBottomSheet extends StatelessWidget {
}
break;
case 'permission':
final newPermission =
await PermissionSliderDialog(initialPermission: user.powerLevel)
.show(context);
final newPermission = await PermissionSliderDialog(
initialPermission: user.powerLevel,
l10n: L10n.of(context),
).show(context);
if (newPermission != null) {
if (newPermission == 100 && await _askConfirmation() == false) break;
await showFutureLoadingDialog(
@ -82,7 +83,7 @@ class UserBottomSheet extends StatelessWidget {
void _verifyAction(BuildContext context) async {
final client = user.room.client;
final req = await client.userDeviceKeys[user.id].startVerification();
await KeyVerificationDialog(request: req).show(context);
await KeyVerificationDialog(request: req,l10n: L10n.of(context),).show(context);
}
@override

View File

@ -265,6 +265,7 @@ class _ChatState extends State<Chat> {
context: context,
builder: (context) => RecordingDialog(
onFinished: (r) => result = r,
l10n: L10n.of(context),
));
if (result == null) return;
final audioFile = File(result);

View File

@ -36,7 +36,10 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
setState(() => null);
}
};
await KeyVerificationDialog(request: req).show(context);
await KeyVerificationDialog(
request: req,
l10n: L10n.of(context),
).show(context);
break;
case 'verify_manual':
if (await showOkCancelAlertDialog(
@ -59,7 +62,10 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
setState(() => null);
}
};
await KeyVerificationDialog(request: req).show(context);
await KeyVerificationDialog(
request: req,
l10n: L10n.of(context),
).show(context);
break;
case 'block':
if (key.directVerified) {

View File

@ -20,9 +20,10 @@ class ChatPermissionsSettings extends StatelessWidget {
return FlushbarHelper.createError(message: L10n.of(context).noPermission)
.show(context);
}
final newLevel =
await PermissionSliderDialog(initialPermission: currentLevel)
.show(context);
final newLevel = await PermissionSliderDialog(
initialPermission: currentLevel,
l10n: L10n.of(context),
).show(context);
if (newLevel == null) return;
final content = Map<String, dynamic>.from(
room.getState(EventTypes.RoomPowerLevels).content);

View File

@ -516,7 +516,8 @@ class _SettingsState extends State<Settings> {
: null,
onTap: () async {
if (!client.encryption.crossSigning.enabled) {
return BootstrapDialog().show(context);
return BootstrapDialog(l10n: L10n.of(context))
.show(context);
}
if (client.isUnknownSession) {
final input = await showTextInputDialog(
@ -592,7 +593,8 @@ class _SettingsState extends State<Settings> {
: null,
onTap: () async {
if (!client.encryption.keyManager.enabled) {
return BootstrapDialog().show(context);
return BootstrapDialog(l10n: L10n.of(context))
.show(context);
}
if (!(await client.encryption.keyManager.isCached())) {
await requestSSSSCache(context);