In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "based on fluttertoast how to achieve encapsulation bullet box tip tool class", the content is detailed, the steps are clear, the details are handled properly, I hope this "based on fluttertoast how to achieve encapsulation bullet box tip tool class" article can help you solve doubts, the following with the editor's ideas slowly in-depth, together to learn new knowledge.
Realize the effect
Realize
1. First summarize the packages that introduce fluttertoast in the pubspec.yaml file:
Fluttertoast: ^ 8.0.8 # pop-up
two。 Package pop-up box tool class DialogUtils:
The creation time of import 'package:flutter/material.dart';import' package:fluttertoast/fluttertoast.dart';/// @ author longzipeng/// @: 2022 String title 2, 24 Universe, class DialogUtils {/ basic pop-up frame static alert (BuildContext context, {String title = "prompt", String content = "", GestureTapCallback? Confirm, GestureTapCallback? Cancle, List? Actions, / / Custom button}) {showDialog (context: context, builder: (context) {return AlertDialog (title: Text ('prompt', style: TextStyle (color: Theme.of (context) .SecretyColor), content: Text (content), actions: actions?? [InkWell (onTap:) {if (cancle! = null) {cancle ();} Navigator.of (context) .pop () }, child: const Padding (padding: EdgeInsets.only (right: 20), child: Text ("cancel", style: TextStyle (color: Colors.grey),) ), InkWell (onTap: () {if (confirm! = null) {confirm () } Navigator.of (context) .pop () }, child: Padding (padding: const EdgeInsets.only (right: 10), child: Text ("OK", style: TextStyle (color: Theme.of (context) .determinyColor),) ),)]) }) } / / pops up about the interface static alertAboutDialog (BuildContext context) {showAboutDialog (context: context, applicationIcon: FlutterLogo (), applicationName: 'flutterdemo', applicationVersion:' 1.0.0 dragon, applicationLegalese: 'copyright programming dragon', children: [Container (height: 70, child: const Text) Sometimes I don't know, but I know myself eventually. MaxLines: 2, style: TextStyle () } / / display ordinary message static showMessage (String msg, {toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.grey, fontSize: 16.0}) {/ / close the pop-up box before displaying the corresponding pop-up box Fluttertoast.cancel () Fluttertoast.showToast (msg: msg, toastLength: toastLength, gravity: gravity, timeInSecForIosWeb: timeInSecForIosWeb, backgroundColor: backgroundColor, fontSize: fontSize) } / / display error message static showErrorMessage (String msg, {toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.red, fontSize: 16.0}) {showMessage (msg, toastLength: toastLength, gravity: gravity, timeInSecForIosWeb: timeInSecForIosWeb, backgroundColor: backgroundColor, fontSize: fontSize) } / / display warning message static showWaringMessage (String msg, {toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.orangeAccent, fontSize: 16.0}) {showMessage (msg, toastLength: toastLength, gravity: gravity, timeInSecForIosWeb: timeInSecForIosWeb, backgroundColor: backgroundColor, fontSize: fontSize) } / / display success message static showSuccessMessage (String msg, {toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.greenAccent, fontSize: 16.0}) {showMessage (msg, toastLength: toastLength, gravity: gravity, timeInSecForIosWeb: timeInSecForIosWeb, backgroundColor: backgroundColor, fontSize: fontSize);}} Test
Note: here ListTitleWidget is a self-encapsulated component, so if you change it directly to ListTitle, you won't make a mistake.
Import 'package:csdn_flutter_demo/pages/common/common_appbar.dart';import' package:csdn_flutter_demo/utils/dialog_utils.dart';import 'package:csdn_flutter_demo/widgets/list_title_widgets.dart';import' package:flutter/material.dart';/// @ author longzipeng/// @ creation time: 2022 const DialogUtilsDemoPage 31max / pop-up demo page class DialogUtilsDemoPage extends StatefulWidget {const DialogUtilsDemoPage ({Key? Key}): super (key: key); @ override State createState () = > _ DialogUtilsDemoPageState ();} class _ DialogUtilsDemoPageState extends State {/ / query data search (value) {print ("search value is: $value") } @ override Widget build (BuildContext context) {return Scaffold (appBar: const CommonAppbar (title: "pop-up window, prompt presentation",), body: ListView (children: [ListTitleWidget (title: const Text ("pop-up box, with confirmation and cancellation"), onTap: () {DialogUtils.alert (context, content: "pretty boys and girls") Study flutter together! " , confirm: () {print ("Click to confirm");}, cancle: () {print ("Click to cancel");}) },), ListTitleWidget (title: const Text (default prompt), onTap: () {DialogUtils.showMessage (default prompt) },), ListTitleWidget (title: const Text), onTap: () {DialogUtils.showSuccessMessage (success prompt) },), ListTitleWidget (title: const Text), onTap: () {DialogUtils.showWaringMessage (warning prompt) },), ListTitleWidget (title: const Text), onTap: () {DialogUtils.showErrorMessage (error prompt);},),],),) }} read here, this article "how to implement encapsulation pop-up prompt tool class based on fluttertoast" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.