How to create Toast in Flutter?

前端 未结 28 767
小蘑菇
小蘑菇 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:12

    Use this plugin

    Fluttertoast.showToast(
            msg: "This is Toast messaget",
            toastLength: Toast.LENGTH_SHORT,
            gravity: ToastGravity.CENTER,
            timeInSecForIos: 1
        );
    

    0 讨论(0)
  • 2020-12-12 11:12

    For the toast message in flutter use bot_toast library. This library provides Feature-rich, support for displaying notifications, text, loading, attachments, etc. Toast

    0 讨论(0)
  • 2020-12-12 11:12

    For android original graphics toast you can use this: https://pub.dartlang.org/packages/fluttertoast

    Works fine on Android and iOS. enter image description here

    0 讨论(0)
  • 2020-12-12 11:14

    Import cupertino_icons: ^0.1.2 and Write below code

    showToast(BuildContext context, String message) {
     showDialog(
    context: context,
    builder: (BuildContext context) {
    return CupertinoAlertDialog( 
    title: Text("Name of App",
              content: Text(message,
              actions: <Widget>[
                FlatButton(
                  child: Text("OK"),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                )
              ],
            );
          });
    
    0 讨论(0)
  • 2020-12-12 11:15

    In case the Fluttertoast package given so far doesnt work... Then I will suggest you try toast.
    It has no frills and no ceremony.

    It just works.

    I noticed a bug within the example given within its Readme though:

    Toast.show("Toast plugin app", duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);

    While the method requires a context. So do well to add 'context' like this:

    Toast.show("Toast plugin app", context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);

    There is a chance that this would have been fixed by the time you checked though, I already submitted a PR.

    0 讨论(0)
  • 2020-12-12 11:15

    For this, there are different versions.

    1) First of all, you can use SnackBar which is a widget in Flutter.

    2) You can use libraries like toast, flutter_toast from pub.dev.

    3) Third version is creating your custom widget. It can be created using Overlay widget and Animation in Flutter.

    You can this this tutorial to learn more about it. Here is a link

    0 讨论(0)
提交回复
热议问题