135 lines
4.3 KiB
Dart
135 lines
4.3 KiB
Dart
import 'package:bruno/bruno.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DialogUtils {
|
|
|
|
/// 弹出一个信息展示框
|
|
static void showMessage(BuildContext context, String title, String message, {String btnLabel = '确定'}) {
|
|
BrnDialogManager.showSingleButtonDialog(context,
|
|
label: btnLabel,
|
|
title: title,
|
|
message: message,
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
}
|
|
);
|
|
}
|
|
|
|
/// 弹出一个成功的提示框
|
|
static void showSuccessMessage(BuildContext context, String title, String message, {String btnLabel = '确定'}) {
|
|
BrnDialogManager.showSingleButtonDialog(context,
|
|
showIcon: true,
|
|
iconWidget: Image.asset("lib/images/ico/round_success.png"),
|
|
label: btnLabel,
|
|
title: title,
|
|
message: message,
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
}
|
|
);
|
|
}
|
|
|
|
/// 弹出一个警告提示框
|
|
static void showWarningMessage(BuildContext context, String title, String message, {String btnLabel = '确定'}) {
|
|
BrnDialogManager.showSingleButtonDialog(context,
|
|
showIcon: true,
|
|
iconWidget: Image.asset("lib/images/ico/round_warning.png"),
|
|
label: btnLabel,
|
|
title: title,
|
|
message: message,
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
}
|
|
);
|
|
}
|
|
|
|
/// 弹出一个错误提示框
|
|
static void showErrorMessage(BuildContext context, String title, String message, {String btnLabel = '确定'}) {
|
|
BrnDialogManager.showSingleButtonDialog(context,
|
|
showIcon: true,
|
|
iconWidget: Image.asset("lib/images/ico/round_error.png"),
|
|
label: btnLabel,
|
|
title: title,
|
|
message: message,
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
}
|
|
);
|
|
}
|
|
|
|
/// 弹出一个问题框
|
|
static void showConfirmMessage(BuildContext context, String title, String message, {Function()? cancel, Function()? confirm, String cancelLabel = '取消', String confirmBtn = '确定'}) {
|
|
BrnDialogManager.showConfirmDialog(context,
|
|
showIcon: true,
|
|
iconWidget: Image.asset("lib/images/ico/round_question.png"),
|
|
title: title,
|
|
confirm: confirmBtn,
|
|
cancel: cancelLabel,
|
|
message: message, onConfirm: () {
|
|
Navigator.of(context).pop();
|
|
if(confirm != null) {
|
|
confirm();
|
|
}
|
|
}, onCancel: () {
|
|
Navigator.of(context).pop();
|
|
if(cancel != null) {
|
|
cancel();
|
|
}
|
|
});
|
|
}
|
|
|
|
/// 展示一个输入框
|
|
static void showInputMessage(BuildContext context, String title, {String? hintText, String? message, Function()? cancel, Function(String)? confirm, String cancelLabel = '取消', String confirmBtn = '确定'}) {
|
|
BrnMiddleInputDialog(
|
|
title: title,
|
|
message: message,
|
|
hintText: hintText,
|
|
cancelText: cancelLabel,
|
|
confirmText: confirmBtn,
|
|
autoFocus: true,
|
|
maxLength: 1000,
|
|
maxLines: 1,
|
|
dismissOnActionsTap: false,
|
|
barrierDismissible: true,
|
|
onConfirm: (value) {
|
|
Navigator.pop(context);
|
|
if(confirm != null) {
|
|
confirm(value);
|
|
}
|
|
},
|
|
onCancel: () {
|
|
Navigator.pop(context);
|
|
if(cancel != null) {
|
|
cancel();
|
|
}
|
|
}).show(context);
|
|
}
|
|
|
|
/// 展示一个单选框
|
|
static void showSingleSelectDialog(BuildContext context, String title, List<String> conditions, {Function(int, String?)? onSubmitClick, String msg = "", String submitText = "确定"}) {
|
|
int selectedIndex = 0;
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) => StatefulBuilder(
|
|
builder: (context, state) {
|
|
return BrnSingleSelectDialog(
|
|
isClose: true,
|
|
title: title,
|
|
messageText: msg,
|
|
checkedItem: conditions[selectedIndex],
|
|
submitText: submitText,
|
|
isCustomFollowScroll: true,
|
|
conditions: conditions,
|
|
onSubmitClick: (data) {
|
|
if(onSubmitClick != null) {
|
|
onSubmitClick(selectedIndex, data);
|
|
}
|
|
},
|
|
onItemClick: (BuildContext context, int index) {
|
|
selectedIndex = index;
|
|
});
|
|
}
|
|
));
|
|
}
|
|
|
|
} |