will-play/lib/utils/showToast.dart

99 lines
2.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
// 普通气泡弹框
// 使用showToast("xxxxxxx");
void showToast(
String text, {
gravity: ToastGravity.CENTER,
toastLength: Toast.LENGTH_SHORT,
}) {
Fluttertoast.showToast(
msg: text,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 3,
backgroundColor: Colors.grey[600], // 灰色背景
fontSize: 16.0,
);
}
// 一个加载中的动画不传text时默认显示文字Loading...
// 使用showLoading(context, 'xxxxxxx');
void showLoading(context, text) {
text = text ?? "Loading...";
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(3.0),
boxShadow: [
// 阴影
BoxShadow(
color: Colors.black12,
//offset: Offset(2.0,2.0),
blurRadius: 10.0,
)
]),
padding: EdgeInsets.all(16),
margin: EdgeInsets.all(16),
constraints: BoxConstraints(minHeight: 120, minWidth: 180),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 30,
width: 30,
child: CircularProgressIndicator(
strokeWidth: 3,
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
text,
style: Theme.of(context).textTheme.bodyMedium,
),
),
],
),
),
);
},
);
}
// 带有确定取消按钮的提示框content是提示框的内容文字confirmCallback是点击确定按钮的回调
// 使用showConfirmDialog(context, '确认xxxxxxx吗', () {print('xxxxxxx');});
void showConfirmDialog(
BuildContext context, String content, Function confirmCallback) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("提示"),
content: Text(content),
actions: <Widget>[
FlatButton(
onPressed: () {
confirmCallback();
Navigator.of(context).pop();
},
child: Text("确认"),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("取消"),
),
],
);
});
}