How to create Toast in Flutter?

前端 未结 28 777
小蘑菇
小蘑菇 2020-12-12 10:46

Can I create something similar to Toasts in Flutter? Just a tiny notification window that is not directly in the face of the user and does not lock or fade the view behind i

28条回答
  •  伪装坚强ぢ
    2020-12-12 11:26

    I would like to provide alternative solution to use package flushbar. https://github.com/AndreHaueisen/flushbar
    As the package said: Use this package if you need more customization when notifying your user. For Android developers, it is made to substitute toasts and snackbars.
    Another suggestion to use flushbar How to show snackbar after navigator.pop(context) in Flutter?
    You can also set flushbarPosition to TOP or BOTTOM

        Flushbar(
          title: "Hey Ninja",
          message: "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
          flushbarPosition: FlushbarPosition.TOP,
          flushbarStyle: FlushbarStyle.FLOATING,
          reverseAnimationCurve: Curves.decelerate,
          forwardAnimationCurve: Curves.elasticOut,
          backgroundColor: Colors.red,
          boxShadows: [BoxShadow(color: Colors.blue[800], offset: Offset(0.0, 2.0), blurRadius: 3.0)],
          backgroundGradient: LinearGradient(colors: [Colors.blueGrey, Colors.black]),
          isDismissible: false,
          duration: Duration(seconds: 4),
          icon: Icon(
            Icons.check,
            color: Colors.greenAccent,
          ),
          mainButton: FlatButton(
            onPressed: () {},
            child: Text(
              "CLAP",
              style: TextStyle(color: Colors.amber),
            ),
          ),
          showProgressIndicator: true,
          progressIndicatorBackgroundColor: Colors.blueGrey,
          titleText: Text(
            "Hello Hero",
            style: TextStyle(
                fontWeight: FontWeight.bold, fontSize: 20.0, color: Colors.yellow[600], fontFamily: "ShadowsIntoLightTwo"),
          ),
          messageText: Text(
            "You killed that giant monster in the city. Congratulations!",
            style: TextStyle(fontSize: 18.0, color: Colors.green, fontFamily: "ShadowsIntoLightTwo"),
          ),
        )..show(context);
    

提交回复
热议问题