How to create Toast in Flutter?

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

    Import the lib

    fluttertoast: 3.1.3

    Use like below

    Fluttertoast.showToast(
    msg: "Hello world",
    textColor: Colors.white,
    toastLength: Toast.LENGTH_SHORT,
    timeInSecForIos: 1,
    gravity: ToastGravity.BOTTOM,
    backgroundColor: Colors.indigo,
    

    );

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

    just use SnackBar(content: Text("hello"),) inside any event like onTap and onPress

    you can read more about Snackbar here https://flutter.dev/docs/cookbook/design/snackbars

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

    For the ones that are looking for a Toast what can survive the route changes the SnackBar might not be the best option.

    Have a look at Overlay instead.

    https://api.flutter.dev/flutter/widgets/Overlay-class.html

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

    You can use something like FlutterToast

    Import the lib

    fluttertoast: ^2.1.4
    

    Use like below

    Fluttertoast.showToast(
        msg: "Hello world",
        textColor: Colors.white,
        toastLength: Toast.LENGTH_SHORT,
        timeInSecForIos: 1,
        gravity: ToastGravity.BOTTOM,
        backgroundColor: Colors.indigo,
    );
    

    Thats it..

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