怎么在颤振中利用面包实现一个消息提示框

  介绍

怎么在颤振中利用面包实现一个消息提示框?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

使用方法

//默认是显示在中间的   Toast.toast(上下文、味精:,“中间显示的,“),,,,,,   味精,Toast.toast(上下文:,“中间显示的,“,位置:,ToastPostion.center);   Toast.toast(上下文、味精:“顶部显示的,Toast  _count"美元;,位置:,ToastPostion.top);   Toast.toast(上下文、味精:“底部显示的,Toast  _count"美元;,位置:,ToastPostion.bottom);

吐司源码

import  & # 39;包:颤振/cupertino.dart& # 39;;   import  & # 39;包:颤振/material.dart& # 39;;//Toast 显示位置控制,   enum  ToastPostion  {   ,,   ,中心,   ,底部,   }      class  Toast  {   ,//面包靠它加到屏幕上   ,static  OverlayEntry  _overlayEntry;   ,//面包是否正在显示   ,static  bool  _showing =,假;   ,//开启一个新土司的当前时间,用于对比是否已经展示了足够时间   ,static  DateTime  _startedTime;   ,//提示内容   ,static  String  _msg;   ,//面包显示时间   ,static  int  _showTime;   ,//背景颜色   ,static  Color  _bgColor;   ,//文本颜色   ,static  Color  _textColor;   ,//文字大小   ,static  double  _textSize;   ,//显示位置   ,static  ToastPostion  _toastPosition;   ,//左右边距   ,static  double  _pdHorizontal;   ,//上下边距   ,static  double  _pdVertical;   ,static  void 面包(   BuildContext 上下文,才能,{//才能显示的文本   String 才能;味精,//才能显示的时间,单位毫秒   int 才能;showTime =, 1000年,//才能显示的背景   Color 才能;bgColor =, Colors.black,//才能显示的文本颜色   Color 才能;textColor =, Colors.white,//才能显示的文字大小   double 才能;textSize =, 14.0,//才能显示的位置   ToastPostion 才能;position =, ToastPostion.center,//才能文字水平方向的内边距   double 才能;pdHorizontal =, 20.0,//才能文字垂直方向的内边距   double 才能;pdVertical =, 10.0,   ,})async  {   维护才能(msg  !=, null);=_msg 才能、味精;   时间=_startedTime 才能;DateTime.now ();   _showTime 才能=,showTime;   _bgColor =,才能告诉我们;   _textColor =,才能输入textColor;   时间=_textSize 才能;textSize;   时间=_toastPosition 才能;位置;   时间=_pdHorizontal 才能;pdHorizontal;   时间=_pdVertical 才能;pdVertical;//才能获取OverlayState   OverlayState 才能;OverlayState =, Overlay.of(上下文);   _showing =,才能正确;   if 才能;(_overlayEntry ==, null), {   ,,//OverlayEntry负责构建布的局   ,,//通过OverlayEntry将构建的布局插入到整个布局的最上层   ,,_overlayEntry =, OverlayEntry (   ,,,,建设者:,(BuildContext 上下文),=祝辞,定位(   ,,,,,,,//前值,可以改变这个值来改变烤面包在屏幕中的位置   ,,,,,,,:,buildToastPosition(上下文),   ,,,,,,,孩子:,容器(   ,,,,,,,,,对齐:,Alignment.center,   ,,,,,,,,,宽度:,MediaQuery.of .size.width(上下文),   ,,,,,,,,,孩子:,填充(   ,,,,,,,,,,填充:,EdgeInsets.symmetric(水平:40.0),   ,,,,,,,,,,孩子:,AnimatedOpacity (   ,,,,,,,,,,,不透明度:,_showing  ?, 1.0,:, 0.0,,//目标透明度   ,,,,,,,,,,,时间:_showing   ,,,,,,,,,,,,,?,持续时间(毫秒:100)   ,,,,,,,,,,,,,,,时间(毫秒:400),   ,,,,,,,,,,,孩子:,_buildToastWidget (),   ,,,,,,,,,,),   ,,,,,,,,,),   ,,,,,,));   ,,//插入到整个布局的最上层   ,,overlayState.insert (_overlayEntry);   ,,},{else    ,,//重新绘制UI,类似设置状态   ,,_overlayEntry.markNeedsBuild ();   ,,}//才能,等待时间   await 才能Future.delayed(持续时间(毫秒:_showTime));   ,,//2秒后,到底消失不消失   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在颤振中利用面包实现一个消息提示框