Flutter弹出提示插件awesome_toster的使用
Flutter弹出提示插件awesome_toster的使用
特性
- 显示警告、错误、成功提示。
- 完全自定义的包。
开始使用
- 在你的应用中导入此包:
import 'package:awesome_toster/awesome_toster.dart';
使用方法
尝试以下代码片段:
AwesomeToster().showOverlay(
context: context,
msg: "This is Success Message",
tosterHeight: 50,
msgType: MsgType.SUCCESS,
);
完整示例代码
以下是一个完整的示例代码,展示了如何在Flutter应用中使用awesome_toster
插件来显示不同类型的提示信息(警告、错误和成功)。
import 'package:awesome_toster/awesome_toster.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// 这个小部件是你的应用的根
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Awesome Toster'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
'按下操作按钮以显示警告弹窗',
),
],
),
),
floatingActionButton: Padding(
padding: const EdgeInsets.only(left: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FloatingActionButton(
backgroundColor: Colors.amber,
onPressed: () {
// 显示警告提示
AwesomeToster().showOverlay(
context: context,
msg: "This is Warning Message",
tosterHeight: 50,
prefixIcon: Icons.warning,
msgType: MsgType.WARNING,
);
},
tooltip: 'Warning',
child: const Icon(Icons.warning),
),
FloatingActionButton(
backgroundColor: Colors.red,
onPressed: () {
// 显示错误提示
AwesomeToster().showOverlay(
context: context,
msg: "This is Error Message",
tosterHeight: 50,
prefixIcon: Icons.error,
msgType: MsgType.ERROR,
);
},
tooltip: 'Error',
child: const Icon(Icons.error),
),
FloatingActionButton(
backgroundColor: Colors.green,
onPressed: () {
// 显示成功提示
AwesomeToster().showOverlay(
context: context,
msg: "This is Success Message",
tosterHeight: 50,
msgType: MsgType.SUCCESS,
);
},
tooltip: 'Success',
child: const Icon(Icons.check),
),
],
),
),
);
}
}
更多关于Flutter弹出提示插件awesome_toster的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复