我可以在Flutter中创建类似Toasts的东西吗?
只是一个很小的通知窗口,不直接面对用户,也不锁定或淡出它后面的视图。
我可以在Flutter中创建类似Toasts的东西吗?
只是一个很小的通知窗口,不直接面对用户,也不锁定或淡出它后面的视图。
当前回答
将flutter_just_toast添加到Pubspecs中的依赖项中。yaml文件。
依赖关系:
flutter_just_toast: ^1.0.1
接下来将包导入到你的类中:
import 'package:flutter_just_toast/flutter_just_toast.dart';
用一条消息实现Toast:
Toast.show(message: "Your toast message",
duration: Delay.SHORT,
textColor: Colors.black);
其他回答
颤振里没有任何烤面包的小部件。你可以去这个插件。
用例:
Fluttertoast.showToast(
msg: "My toast message",
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
timeInSecForIos: 1,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.indigo,);
你可以直接使用小吃店的元素
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Successfully!"),
behavior: SnackBarBehavior.floating,
margin: EdgeInsets.all(20),
shape: StadiumBorder(),
action: SnackBarAction(
label: 'Dismiss',
disabledTextColor: Colors.white,
textColor: Colors.blue,
onPressed: () {
//Do whatever you want
},
),
),
);
要显示Toast消息,您可以使用FlutterToast插件。要使用这个插件,你必须:
将此依赖项添加到您的pubspec中。Yaml文件:fluttertoast: ^8.0.8 要获取包,必须运行以下命令:$ flutter packages get 导入包:导入'package:fluttertoast/fluttertoast.dart';
像这样使用它:
Fluttertoast.showToast(
msg: "your message",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM // Also possible "TOP" and "CENTER"
backgroundColor: "#e74c3c",
textColor: '#ffffff');
要了解更多信息,请查看这个。
将flutter_just_toast添加到Pubspecs中的依赖项中。yaml文件。
依赖关系:
flutter_just_toast: ^1.0.1
接下来将包导入到你的类中:
import 'package:flutter_just_toast/flutter_just_toast.dart';
用一条消息实现Toast:
Toast.show(message: "Your toast message",
duration: Delay.SHORT,
textColor: Colors.black);
fluttertoast: ^ 3.1.3
import 'package:fluttertoast/fluttertoast.dart';
Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIos: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);