flutter 漂亮的toast组件样式

引用了fluttertoast插件

  static void showToast(
      BuildContext context, ToastType toastType, String content) {
    FlutterToast flutterToast = FlutterToast(context);
    Widget toast = Container(
      constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width/2),
      padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5.0),
        color: Color.fromRGBO(50, 50, 50, 0.9),
      ),
      child: Column(mainAxisSize: MainAxisSize.min, children: [
        toastType == ToastType.OK
            ? Icon(Icons.check, color: Colors.blue)
            : (toastType == ToastType.Error
                ? Icon(Icons.error, color: Colors.red)
                : Icon(Icons.warning, color: Colors.yellow)),
        Padding(
          padding: EdgeInsets.only(top: 10),
          child: Text(content,
              style: TextStyle(
                fontSize: 13,
                color: Colors.white,
              )),
        ),
      ]),
    );

    flutterToast.showToast(
      child: toast,
      gravity: ToastGravity.CENTER,
      toastDuration: Duration(seconds: 2),
    );
  }



enum ToastType { Warning, Error, OK }

可以在页面里直接调用,非常美观

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。