flutter_desktop: custom image quality

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-08-31 18:41:55 +08:00
parent 59f0ffa82f
commit 4b9805b0f3
8 changed files with 240 additions and 121 deletions

View File

@@ -427,7 +427,45 @@ class CustomAlertDialog extends StatelessWidget {
void msgBox(
String type, String title, String text, OverlayDialogManager dialogManager,
{bool? hasCancel}) {
var wrap = (String text, void Function() onPressed) => ButtonTheme(
dialogManager.dismissAll();
List<Widget> buttons = [];
if (type != "connecting" && type != "success" && !type.contains("nook")) {
buttons.insert(
0,
getMsgBoxButton(translate('OK'), () {
dialogManager.dismissAll();
// https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
if (!type.contains("custom")) {
closeConnection();
}
}));
}
hasCancel ??= !type.contains("error") &&
!type.contains("nocancel") &&
type != "restarting";
if (hasCancel) {
buttons.insert(
0,
getMsgBoxButton(translate('Cancel'), () {
dialogManager.dismissAll();
}));
}
// TODO: test this button
if (type.contains("hasclose")) {
buttons.insert(
0,
getMsgBoxButton(translate('Close'), () {
dialogManager.dismissAll();
}));
}
dialogManager.show((setState, close) => CustomAlertDialog(
title: Text(translate(title), style: TextStyle(fontSize: 21)),
content: Text(translate(text), style: TextStyle(fontSize: 15)),
actions: buttons));
}
Widget getMsgBoxButton(String text, void Function() onPressed) {
return ButtonTheme(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
//limits the touch area to the button area
@@ -439,44 +477,14 @@ void msgBox(
onPressed: onPressed,
child:
Text(translate(text), style: TextStyle(color: MyTheme.accent))));
}
void msgBoxCommon(OverlayDialogManager dialogManager, String title,
Widget content, List<Widget> buttons) {
dialogManager.dismissAll();
List<Widget> buttons = [];
if (type != "connecting" && type != "success" && type.indexOf("nook") < 0) {
buttons.insert(
0,
wrap(translate('OK'), () {
dialogManager.dismissAll();
// https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
if (type.indexOf("custom") < 0) {
closeConnection();
}
}));
}
if (hasCancel == null) {
// hasCancel = type != 'error';
hasCancel = type.indexOf("error") < 0 &&
type.indexOf("nocancel") < 0 &&
type != "restarting";
}
if (hasCancel) {
buttons.insert(
0,
wrap(translate('Cancel'), () {
dialogManager.dismissAll();
}));
}
// TODO: test this button
if (type.indexOf("hasclose") >= 0) {
buttons.insert(
0,
wrap(translate('Close'), () {
dialogManager.dismissAll();
}));
}
dialogManager.show((setState, close) => CustomAlertDialog(
title: Text(translate(title), style: TextStyle(fontSize: 21)),
content: Text(translate(text), style: TextStyle(fontSize: 15)),
content: content,
actions: buttons));
}
@@ -495,13 +503,13 @@ const G = M * K;
String readableFileSize(double size) {
if (size < K) {
return size.toStringAsFixed(2) + " B";
return "${size.toStringAsFixed(2)} B";
} else if (size < M) {
return (size / K).toStringAsFixed(2) + " KB";
return "${(size / K).toStringAsFixed(2)} KB";
} else if (size < G) {
return (size / M).toStringAsFixed(2) + " MB";
return "${(size / M).toStringAsFixed(2)} MB";
} else {
return (size / G).toStringAsFixed(2) + " GB";
return "${(size / G).toStringAsFixed(2)} GB";
}
}