chore: Switch to adaptive dialogs
This commit is contained in:
parent
499de09169
commit
0fae270165
20 changed files with 361 additions and 363 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat_details.dart';
|
||||
|
|
@ -84,8 +85,11 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
onSelected: (String choice) async {
|
||||
switch (choice) {
|
||||
case 'leave':
|
||||
var confirmed = await SimpleDialogs(context).askConfirmation();
|
||||
if (confirmed) {
|
||||
var confirmed = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
);
|
||||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.leave());
|
||||
if (success != false) {
|
||||
|
|
|
|||
|
|
@ -2,140 +2,12 @@ import 'package:flushbar/flushbar_helper.dart';
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix_link_text/link_text.dart';
|
||||
|
||||
class SimpleDialogs {
|
||||
final BuildContext context;
|
||||
|
||||
const SimpleDialogs(this.context);
|
||||
|
||||
Future<String> enterText(
|
||||
{String titleText,
|
||||
String confirmText,
|
||||
String cancelText,
|
||||
String hintText,
|
||||
String labelText,
|
||||
String prefixText,
|
||||
String suffixText,
|
||||
bool password = false,
|
||||
bool multiLine = false,
|
||||
TextInputType keyboardType}) async {
|
||||
var textEditingController = TextEditingController();
|
||||
final controller = textEditingController;
|
||||
String input;
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: Text(titleText ?? 'Please enter a text'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
autocorrect: false,
|
||||
onSubmitted: (s) {
|
||||
input = s;
|
||||
Navigator.of(c).pop();
|
||||
},
|
||||
minLines: multiLine ? 3 : 1,
|
||||
maxLines: multiLine ? 3 : 1,
|
||||
obscureText: password,
|
||||
textInputAction: multiLine ? TextInputAction.newline : null,
|
||||
keyboardType: keyboardType,
|
||||
decoration: InputDecoration(
|
||||
hintText: hintText,
|
||||
labelText: labelText,
|
||||
prefixText: prefixText,
|
||||
suffixText: suffixText,
|
||||
prefixStyle: TextStyle(color: Theme.of(context).primaryColor),
|
||||
suffixStyle: TextStyle(color: Theme.of(context).primaryColor),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(
|
||||
cancelText?.toUpperCase() ??
|
||||
L10n.of(context).close.toUpperCase(),
|
||||
style: TextStyle(color: Colors.blueGrey)),
|
||||
onPressed: () => Navigator.of(c).pop(),
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(
|
||||
confirmText?.toUpperCase() ??
|
||||
L10n.of(context).confirm.toUpperCase(),
|
||||
),
|
||||
onPressed: () {
|
||||
input = controller.text;
|
||||
Navigator.of(c).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return input;
|
||||
}
|
||||
|
||||
Future<bool> askConfirmation({
|
||||
String titleText,
|
||||
String contentText,
|
||||
String confirmText,
|
||||
String cancelText,
|
||||
bool dangerous = false,
|
||||
}) async {
|
||||
var confirmed = false;
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: Text(titleText ?? L10n.of(context).areYouSure),
|
||||
content: contentText != null ? LinkText(text: contentText) : null,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(
|
||||
cancelText?.toUpperCase() ??
|
||||
L10n.of(context).close.toUpperCase(),
|
||||
style: TextStyle(color: Colors.blueGrey)),
|
||||
onPressed: () => Navigator.of(c).pop(),
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(
|
||||
confirmText?.toUpperCase() ??
|
||||
L10n.of(context).confirm.toUpperCase(),
|
||||
style: TextStyle(color: dangerous ? Colors.red : null),
|
||||
),
|
||||
onPressed: () {
|
||||
confirmed = true;
|
||||
Navigator.of(c).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
Future<void> inform({
|
||||
String titleText,
|
||||
String contentText,
|
||||
String okText,
|
||||
}) async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: titleText != null ? Text(titleText) : null,
|
||||
content: contentText != null ? Text(contentText) : null,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(
|
||||
okText ?? L10n.of(context).ok.toUpperCase(),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(c).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<dynamic> tryRequestWithLoadingDialog(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
var completed = false;
|
||||
|
|
@ -178,15 +50,4 @@ class SimpleDialogs {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void showLoadingDialog(BuildContext context) async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text(L10n.of(context).loadingPleaseWait),
|
||||
content: LinearProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
|
|
@ -36,14 +37,15 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
.show(context);
|
||||
return;
|
||||
}
|
||||
if (await SimpleDialogs(context).askConfirmation(
|
||||
titleText: L10n.of(context).enableEncryptionWarning,
|
||||
contentText: widget.room.client.encryptionEnabled
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).enableEncryptionWarning,
|
||||
message: widget.room.client.encryptionEnabled
|
||||
? L10n.of(context).warningEncryptionInBeta
|
||||
: L10n.of(context).needPantalaimonWarning,
|
||||
confirmText: L10n.of(context).yes,
|
||||
okLabel: L10n.of(context).yes,
|
||||
) ==
|
||||
true) {
|
||||
OkCancelResult.ok) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.enableEncryption(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:circular_check_box/circular_check_box.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
|
|
@ -117,8 +118,11 @@ class ChatListItem extends StatelessWidget {
|
|||
}
|
||||
return success;
|
||||
}
|
||||
final confirmed = await SimpleDialogs(context).askConfirmation();
|
||||
if (!confirmed) return;
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(room.leave());
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/utils/firebase_controller.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
|
|
@ -258,13 +258,15 @@ class MatrixState extends State<Matrix> {
|
|||
return; // ignore share requests by others
|
||||
}
|
||||
final sender = room.getUserByMXIDSync(request.sender);
|
||||
if (await SimpleDialogs(context).askConfirmation(
|
||||
titleText: L10n.of(context).requestToReadOlderMessages,
|
||||
contentText:
|
||||
'${sender.id}\n\n${L10n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${L10n.of(context).identity}:\n${request.requestingDevice.curve25519Key.beautified}',
|
||||
confirmText: L10n.of(context).verify,
|
||||
cancelText: L10n.of(context).deny,
|
||||
)) {
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).requestToReadOlderMessages,
|
||||
message:
|
||||
'${sender.id}\n\n${L10n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${L10n.of(context).identity}:\n${request.requestingDevice.curve25519Key.beautified}',
|
||||
okLabel: L10n.of(context).verify,
|
||||
cancelLabel: L10n.of(context).deny,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
await request.forwardKey();
|
||||
}
|
||||
});
|
||||
|
|
@ -279,10 +281,12 @@ class MatrixState extends State<Matrix> {
|
|||
}
|
||||
hidPopup = true;
|
||||
};
|
||||
if (await SimpleDialogs(context).askConfirmation(
|
||||
titleText: L10n.of(context).newVerificationRequest,
|
||||
contentText: L10n.of(context).askVerificationRequest(request.userId),
|
||||
)) {
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).newVerificationRequest,
|
||||
message: L10n.of(context).askVerificationRequest(request.userId),
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
request.onUpdate = null;
|
||||
hidPopup = true;
|
||||
await request.acceptVerification();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
|
|
@ -23,41 +24,45 @@ class UserBottomSheet extends StatelessWidget {
|
|||
: super(key: key);
|
||||
|
||||
void participantAction(BuildContext context, String action) async {
|
||||
final Function _askConfirmation = () async =>
|
||||
(await showOkCancelAlertDialog(
|
||||
context: context, title: L10n.of(context).areYouSure) ==
|
||||
OkCancelResult.ok);
|
||||
switch (action) {
|
||||
case 'mention':
|
||||
Navigator.of(context).pop();
|
||||
onMention();
|
||||
break;
|
||||
case 'ban':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban());
|
||||
}
|
||||
break;
|
||||
case 'unban':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.unban());
|
||||
}
|
||||
break;
|
||||
case 'kick':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick());
|
||||
}
|
||||
break;
|
||||
case 'admin':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
}
|
||||
break;
|
||||
case 'moderator':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(50));
|
||||
}
|
||||
break;
|
||||
case 'user':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(0));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue