通知消息控件
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. int _page = 0; @override Widget build(BuildContext context) { const bgColor = [Colors.red,Colors.green,Colors.yellow]; bool isCheck = true; return MaterialApp( home: HomePage() ); } } class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { int num = 1; double _left = 0; double _top = 0; double _maxWidth = 0; double _maxHeight = 0; double _width = 300; double _height = 200; TextEditingController _controll=TextEditingController(); GlobalKey _gKey = GlobalKey(); @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_){ print("addPostFrameCallback"); _maxWidth = _gKey.currentContext.size.width; _maxHeight = _gKey.currentContext.size.height; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('LOL',style: TextStyle(color: Colors.yellow),), ), body: Builder( builder: (ctx) { return Center( child: RaisedButton( child: Text("按钮", ), onPressed: () { Scaffold.of(ctx).showSnackBar(SnackBar( content: Text("你有未读消息!"), duration: Duration(seconds: 3), action: SnackBarAction( label: "忽略", onPressed: (){ print("点击了按钮"); }, ), )); }, ), ); } ), ); } }