Flutter Example SnackBar

《Flutter Example SnackBar》

import 'package:flutter/material.dart';

void main() => runApp(new MaterialApp(
      home: new ContactPage(),
    ));

class ContactPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
          title: new Center(
        child: new Text("Using SnackBar"),
      )),
      body: new Center(
        child: new MyButton(),
      ),
    );
  }
}

class MyButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new RaisedButton(
      child: new Text("Show SnackBar"),
      onPressed: () {
        Scaffold.of(context).showSnackBar(new SnackBar(
          content: new Text("Hello! I am SnackBar:"),
          duration: new Duration(seconds: 2),
          action: new SnackBarAction(
            label: "Hit Me",
            onPressed: () {
              Scaffold.of(context).showSnackBar(new SnackBar(
                content:
                    new Text("Hello! I am shown becoz you pressed Action:"),
              ));
            },
          ),
        ));
      },
    );
  }
}

    原文作者:三只仓鼠
    原文地址: https://www.jianshu.com/p/55cf66f7676e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞