opt dialog style

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-01-30 17:56:35 +08:00
parent d2c5ba058d
commit dec1820694
5 changed files with 155 additions and 92 deletions

View File

@ -613,6 +613,7 @@ class CustomAlertDialog extends StatelessWidget {
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {
if (!scopeNode.hasFocus) scopeNode.requestFocus(); if (!scopeNode.hasFocus) scopeNode.requestFocus();
}); });
const double padding = 16;
return FocusScope( return FocusScope(
node: scopeNode, node: scopeNode,
autofocus: true, autofocus: true,
@ -637,8 +638,8 @@ class CustomAlertDialog extends StatelessWidget {
child: AlertDialog( child: AlertDialog(
scrollable: true, scrollable: true,
title: title, title: title,
contentPadding: EdgeInsets.symmetric( contentPadding: EdgeInsets.fromLTRB(
horizontal: contentPadding ?? 25, vertical: 10), contentPadding ?? padding, 25, contentPadding ?? padding, 10),
content: ConstrainedBox( content: ConstrainedBox(
constraints: contentBoxConstraints, constraints: contentBoxConstraints,
child: Theme( child: Theme(
@ -648,6 +649,7 @@ class CustomAlertDialog extends StatelessWidget {
), ),
child: content)), child: content)),
actions: actions, actions: actions,
actionsPadding: EdgeInsets.fromLTRB(0, 0, padding, padding),
), ),
); );
} }
@ -701,9 +703,8 @@ void msgBox(String id, String type, String title, String text, String link,
} }
dialogManager.show( dialogManager.show(
(setState, close) => CustomAlertDialog( (setState, close) => CustomAlertDialog(
title: _msgBoxTitle(title), title: null,
content: content: msgboxContent(type, title, text),
SelectableText(translate(text), style: const TextStyle(fontSize: 15)),
actions: buttons, actions: buttons,
onSubmit: hasOk ? submit : null, onSubmit: hasOk ? submit : null,
onCancel: hasCancel == true ? cancel : null, onCancel: hasCancel == true ? cancel : null,
@ -712,30 +713,74 @@ void msgBox(String id, String type, String title, String text, String link,
); );
} }
Widget msgBoxButton(String text, void Function() onPressed) { Color? _msgboxColor(String type) {
return ButtonTheme( if (type == "input-password" || type == "custom-os-password") {
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), return Color(0xFFAD448E);
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, }
//limits the touch area to the button area if (type.contains("success")) {
minWidth: 0, return Color(0xFF32bea6);
//wraps child's width }
height: 0, if (type.contains("error") || type == "re-input-password") {
child: TextButton( return Color(0xFFE04F5F);
style: flatButtonStyle, }
onPressed: onPressed, return Color(0xFF2C8CFF);
child:
Text(translate(text), style: TextStyle(color: MyTheme.accent))));
} }
Widget _msgBoxTitle(String title) => Widget msgboxIcon(String type) {
Text(translate(title), style: TextStyle(fontSize: 21)); IconData? iconData;
if (type.contains("error") || type == "re-input-password") {
iconData = Icons.cancel;
}
if (type.contains("success")) {
iconData = Icons.check_circle;
}
if (type == "wait-uac" || type == "wait-remote-accept-nook") {
iconData = Icons.hourglass_top;
}
if (type == 'on-uac' || type == 'on-foreground-elevated') {
iconData = Icons.admin_panel_settings;
}
if (type == "info") {
iconData = Icons.info;
}
if (iconData != null) {
return Icon(iconData, size: 50, color: _msgboxColor(type))
.marginOnly(right: 16);
}
return Offstage();
}
// title should be null
Widget msgboxContent(String type, String title, String text) {
return Row(
children: [
msgboxIcon(type),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
translate(title),
style: TextStyle(fontSize: 21),
).marginOnly(bottom: 10),
Text(translate(text), style: const TextStyle(fontSize: 15)),
],
),
),
],
);
}
void msgBoxCommon(OverlayDialogManager dialogManager, String title, void msgBoxCommon(OverlayDialogManager dialogManager, String title,
Widget content, List<Widget> buttons, Widget content, List<Widget> buttons,
{bool hasCancel = true}) { {bool hasCancel = true}) {
dialogManager.dismissAll(); dialogManager.dismissAll();
dialogManager.show((setState, close) => CustomAlertDialog( dialogManager.show((setState, close) => CustomAlertDialog(
title: _msgBoxTitle(title), title: Text(
translate(title),
style: TextStyle(fontSize: 21),
),
content: content, content: content,
actions: buttons, actions: buttons,
onCancel: hasCancel ? close : null, onCancel: hasCancel ? close : null,
@ -1589,7 +1634,8 @@ class ServerConfig {
Widget dialogButton(String text, Widget dialogButton(String text,
{required VoidCallback? onPressed, {required VoidCallback? onPressed,
bool isOutline = false, bool isOutline = false,
TextStyle? style}) { TextStyle? style,
ButtonStyle? buttonStyle}) {
if (isDesktop) { if (isDesktop) {
if (isOutline) { if (isOutline) {
return OutlinedButton( return OutlinedButton(
@ -1598,7 +1644,7 @@ Widget dialogButton(String text,
); );
} else { } else {
return ElevatedButton( return ElevatedButton(
style: ElevatedButton.styleFrom(elevation: 0), style: ElevatedButton.styleFrom(elevation: 0).merge(buttonStyle),
onPressed: onPressed, onPressed: onPressed,
child: Text(translate(text), style: style), child: Text(translate(text), style: style),
); );

View File

@ -1426,12 +1426,8 @@ void showConfirmSwitchSidesDialog(
} }
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate('Switch Sides')), content: msgboxContent('info', 'Switch Sides',
content: Column( 'Please confirm if you want to share your desktop?'),
children: [
Text(translate('Please confirm if you want to share your desktop?')),
],
),
actions: [ actions: [
dialogButton('Cancel', onPressed: close, isOutline: true), dialogButton('Cancel', onPressed: close, isOutline: true),
dialogButton('OK', onPressed: submit), dialogButton('OK', onPressed: submit),

View File

@ -9,7 +9,7 @@ import '../../models/model.dart';
import '../../models/platform_model.dart'; import '../../models/platform_model.dart';
void clientClose(String id, OverlayDialogManager dialogManager) { void clientClose(String id, OverlayDialogManager dialogManager) {
msgBox(id, '', 'Close', 'Are you sure to close the connection?', '', msgBox(id, 'info', 'Close', 'Are you sure to close the connection?', '',
dialogManager); dialogManager);
} }
@ -33,8 +33,10 @@ void showRestartRemoteDevice(
]), ]),
content: Text( content: Text(
"${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"), "${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
onCancel: close,
onSubmit: () => close(true),
actions: [ actions: [
dialogButton("Cancel", onPressed: () => close(), isOutline: true), dialogButton("Cancel", onPressed: close, isOutline: true),
dialogButton("OK", onPressed: () => close(true)), dialogButton("OK", onPressed: () => close(true)),
], ],
)); ));
@ -48,6 +50,18 @@ void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
var validateLength = false; var validateLength = false;
var validateSame = false; var validateSame = false;
dialogManager.show((setState, close) { dialogManager.show((setState, close) {
submit() async {
close();
dialogManager.showLoading(translate("Waiting"));
if (await gFFI.serverModel.setPermanentPassword(p0.text)) {
dialogManager.dismissAll();
showSuccess();
} else {
dialogManager.dismissAll();
showError();
}
}
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate('Set your own password')), title: Text(translate('Set your own password')),
content: Form( content: Form(
@ -94,29 +108,17 @@ void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
}, },
), ),
])), ])),
onCancel: close,
onSubmit: (validateLength && validateSame) ? submit : null,
actions: [ actions: [
dialogButton( dialogButton(
'Cancel', 'Cancel',
onPressed: () { onPressed: close,
close();
},
isOutline: true, isOutline: true,
), ),
dialogButton( dialogButton(
'OK', 'OK',
onPressed: (validateLength && validateSame) onPressed: (validateLength && validateSame) ? submit : null,
? () async {
close();
dialogManager.showLoading(translate("Waiting"));
if (await gFFI.serverModel.setPermanentPassword(p0.text)) {
dialogManager.dismissAll();
showSuccess();
} else {
dialogManager.dismissAll();
showError();
}
}
: null,
), ),
], ],
); );
@ -205,26 +207,36 @@ void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
}); });
} }
void wrongPasswordDialog(String id, OverlayDialogManager dialogManager) { void wrongPasswordDialog(
dialogManager.show((setState, close) => CustomAlertDialog( String id, OverlayDialogManager dialogManager, type, title, text) {
title: Text(translate('Wrong Password')), dialogManager.dismissAll();
content: Text(translate('Do you want to enter again?')), dialogManager.show((setState, close) {
cancel() {
close();
closeConnection();
}
submit() {
enterPasswordDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
onSubmit: submit,
onCancel: cancel,
actions: [ actions: [
dialogButton( dialogButton(
'Cancel', 'Cancel',
onPressed: () { onPressed: cancel,
close();
closeConnection();
},
isOutline: true, isOutline: true,
), ),
dialogButton( dialogButton(
'Retry', 'Retry',
onPressed: () { onPressed: submit,
enterPasswordDialog(id, dialogManager);
},
), ),
])); ]);
});
} }
void showServerSettingsWithValue( void showServerSettingsWithValue(
@ -352,13 +364,15 @@ void showServerSettingsWithValue(
}); });
} }
void showWaitUacDialog(String id, OverlayDialogManager dialogManager) { void showWaitUacDialog(
String id, OverlayDialogManager dialogManager, String type) {
dialogManager.dismissAll(); dialogManager.dismissAll();
dialogManager.show( dialogManager.show(
tag: '$id-wait-uac', tag: '$id-wait-uac',
(setState, close) => CustomAlertDialog( (setState, close) => CustomAlertDialog(
title: Text(translate('Wait')), title: null,
content: Text(translate('wait_accept_uac_tip')).marginAll(10), content: msgboxContent(type, 'Wait', 'wait_accept_uac_tip')
.marginOnly(bottom: 10),
)); ));
} }
@ -516,16 +530,6 @@ void showOnBlockDialog(
dialogManager.existing('$id-request-elevation')) { dialogManager.existing('$id-request-elevation')) {
return; return;
} }
var content = Column(children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"${translate(text)}${type.contains('uac') ? '\n' : '\n\n'}${translate('request_elevation_tip')}",
textAlign: TextAlign.left,
style: TextStyle(fontWeight: FontWeight.w400),
).marginSymmetric(vertical: 15),
),
]);
dialogManager.show(tag: '$id-$type', (setState, close) { dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() { void submit() {
close(); close();
@ -533,12 +537,11 @@ void showOnBlockDialog(
} }
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate(title)), title: null,
content: content, content: msgboxContent(type, title,
"${translate(text)}${type.contains('uac') ? '\n' : '\n\n'}${translate('request_elevation_tip')}"),
actions: [ actions: [
dialogButton('Wait', onPressed: () { dialogButton('Wait', onPressed: close, isOutline: true),
close();
}, isOutline: true),
dialogButton('Request Elevation', onPressed: submit), dialogButton('Request Elevation', onPressed: submit),
], ],
onSubmit: submit, onSubmit: submit,
@ -556,8 +559,8 @@ void showElevationError(String id, String type, String title, String text,
} }
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate(title)), title: null,
content: Text(translate(text)), content: msgboxContent(type, title, text),
actions: [ actions: [
dialogButton('Cancel', onPressed: () { dialogButton('Cancel', onPressed: () {
close(); close();
@ -570,6 +573,25 @@ void showElevationError(String id, String type, String title, String text,
}); });
} }
void showWaitAcceptDialog(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.dismissAll();
dialogManager.show((setState, close) {
onCancel() {
closeConnection();
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
dialogButton('Cancel', onPressed: onCancel, isOutline: true),
],
onCancel: onCancel,
);
});
}
Future<String?> validateAsync(String value) async { Future<String?> validateAsync(String value) async {
value = value.trim(); value = value.trim();
if (value.isEmpty) { if (value.isEmpty) {

View File

@ -263,19 +263,18 @@ class FfiModel with ChangeNotifier {
final text = evt['text']; final text = evt['text'];
final link = evt['link']; final link = evt['link'];
if (type == 're-input-password') { if (type == 're-input-password') {
wrongPasswordDialog(id, dialogManager); wrongPasswordDialog(id, dialogManager, type, title, text);
} else if (type == 'input-password') { } else if (type == 'input-password') {
enterPasswordDialog(id, dialogManager); enterPasswordDialog(id, dialogManager);
} else if (type == 'restarting') { } else if (type == 'restarting') {
showMsgBox(id, type, title, text, link, false, dialogManager, showMsgBox(id, type, title, text, link, false, dialogManager,
hasCancel: false); hasCancel: false);
} else if (type == 'wait-remote-accept-nook') { } else if (type == 'wait-remote-accept-nook') {
msgBoxCommon(dialogManager, title, Text(translate(text)), showWaitAcceptDialog(id, type, title, text, dialogManager);
[dialogButton("Cancel", onPressed: closeConnection)]);
} else if (type == 'on-uac' || type == 'on-foreground-elevated') { } else if (type == 'on-uac' || type == 'on-foreground-elevated') {
showOnBlockDialog(id, type, title, text, dialogManager); showOnBlockDialog(id, type, title, text, dialogManager);
} else if (type == 'wait-uac') { } else if (type == 'wait-uac') {
showWaitUacDialog(id, dialogManager); showWaitUacDialog(id, dialogManager, type);
} else if (type == 'elevation-error') { } else if (type == 'elevation-error') {
showElevationError(id, type, title, text, dialogManager); showElevationError(id, type, title, text, dialogManager);
} else { } else {

View File

@ -1104,7 +1104,7 @@ impl<T: InvokeUiSession> Remote<T> {
Some(misc::Union::PortableServiceRunning(b)) => { Some(misc::Union::PortableServiceRunning(b)) => {
if b { if b {
self.handler.msgbox( self.handler.msgbox(
"custom-nocancel", "custom-nocancel-success",
"Successful", "Successful",
"Elevate successfully", "Elevate successfully",
"", "",