提記
如果再回到從前弥奸,我寧愿選擇不認(rèn)識你,不是我后悔奋早,而是我不能面對沒有你的結(jié)局∈Ⅵ現(xiàn)在開始,我只為你乖乖耽装,乖乖的等你愤炸,無論多久
上一課請前往http://www.reibang.com/p/8315ceffd93b
用OverlayState+OverlayEntry 做一個(gè)toast
// Created by zhengxiangke
// des:
//
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ToastUtil {
///顯示toast
static void showToast (String msg, BuildContext context) {
if (context != null) {
OverlayEntry overlayEntry = OverlayEntry(
builder: (BuildContext context) => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container (
padding: EdgeInsets.all(18),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
color: Color(0xffE0E0E0)
),
child: Text(msg, style: TextStyle(
fontSize: 18,
color: Colors.white,
decoration: TextDecoration.none,
),),
),
Image.asset('images/timg.jpeg',fit: BoxFit.contain, width: 200,)
],
)
);
Overlay.of(context).insert(overlayEntry);
///顯示toast 2秒自動消失
Future.delayed(Duration(seconds: 2), () {
overlayEntry.remove();
} );
}
}
}