mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-29 08:19:05 +08:00
89 lines
2.5 KiB
Dart
89 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'dart:async';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
class HexColor extends Color {
|
|
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
|
|
|
|
static int _getColorFromHex(String hexColor) {
|
|
hexColor = hexColor.toUpperCase().replaceAll('#', '');
|
|
if (hexColor.length == 6) {
|
|
hexColor = 'FF' + hexColor;
|
|
}
|
|
return int.parse(hexColor, radix: 16);
|
|
}
|
|
}
|
|
|
|
class MyTheme {
|
|
static const Color grayBg = Color(0xFFEEEEEE);
|
|
static const Color white = Color(0xFFFFFFFF);
|
|
static const Color accent = Color(0xFF0071FF);
|
|
static const Color accent50 = Color(0x770071FF);
|
|
static const Color canvasColor = Color(0xFF212121);
|
|
}
|
|
|
|
// https://github.com/huangjianke/flutter_easyloading
|
|
void showLoading(String text) {
|
|
dismissLoading();
|
|
EasyLoading.show(status: text);
|
|
}
|
|
|
|
void dismissLoading() {
|
|
EasyLoading.dismiss();
|
|
}
|
|
|
|
void showSuccess(String text) {
|
|
dismissLoading();
|
|
EasyLoading.showSuccess(text);
|
|
}
|
|
|
|
bool _hasDialog = false;
|
|
typedef BuildAlertDailog = Tuple3<Widget, Widget, List<Widget>> Function(
|
|
void Function(void Function()));
|
|
|
|
// https://material.io/develop/flutter/components/dialogs
|
|
Future<T> showAlertDialog<T>(BuildContext context, BuildAlertDailog build,
|
|
[WillPopCallback onWillPop,
|
|
bool barrierDismissible,
|
|
double contentPadding = 20]) async {
|
|
dismissLoading();
|
|
if (_hasDialog) {
|
|
Navigator.pop(context);
|
|
}
|
|
_hasDialog = true;
|
|
var dialog = StatefulBuilder(builder: (context, setState) {
|
|
var widgets = build(setState);
|
|
if (onWillPop == null) onWillPop = () async => false;
|
|
return WillPopScope(
|
|
onWillPop: onWillPop,
|
|
child: AlertDialog(
|
|
title: widgets.item1,
|
|
contentPadding: EdgeInsets.all(contentPadding),
|
|
content: widgets.item2,
|
|
actions: widgets.item3,
|
|
));
|
|
});
|
|
var res = await showDialog<T>(
|
|
context: context,
|
|
barrierDismissible: barrierDismissible,
|
|
builder: (context) => dialog);
|
|
_hasDialog = false;
|
|
return res;
|
|
}
|
|
|
|
void msgbox(String type, String title, String text, BuildContext context) {
|
|
showAlertDialog(
|
|
context,
|
|
(_) => Tuple3(Text(title), Text(text), [
|
|
FlatButton(
|
|
textColor: MyTheme.accent,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
Navigator.pop(context);
|
|
},
|
|
child: Text('OK'),
|
|
),
|
|
]));
|
|
}
|