Flutter之SnackBar组件

/**
    const SnackBar({
    Key key,
    @required this.content,//显示的内容
    this.backgroundColor,//设置背景颜色
    this.action,//可以添加事件
    this.duration = _kSnackBarDisplayDuration,
    this.animation,
    })
 */
floatingActionButton: Builder( //当BuildContext在Scaffold之前时,调用Scaffold.of(context)会报错。这时可以通过Builder Widget来解决
    builder: (BuildContext context) {
      return FloatingActionButton(
        onPressed: () {
          Scaffold.of(context).showSnackBar(
              SnackBar(
                content: Text("这是一个SnackBar"),
                backgroundColor: Colors.red, //设置背景颜色
                duration: Duration(
                    milliseconds: 1
                ),
                action: SnackBarAction(
                    label: "别点我",
                    onPressed: () {
                      print("SnackBar上面的按钮被点击了");
                    }
                ),
              )
          );
        },
        child: Text("click"),
      );
    }),

码云地址:https://gitee.com/xgljh/Flutter.git

你可能感兴趣的:(Flutter之SnackBar组件)