Tried to change the background color and text color in Flutter toast. But its not working properly

Viewed 1644

While trying to change the background color and text color of toast message in flutter, the changes are not reflecting.

Help me with the solution.

      Fluttertoast.showToast(
              msg: text,
              toastLength: Toast.LENGTH_SHORT,
              gravity: ToastGravity.CENTER,
              timeInSecForIosWeb: 1,
              backgroundColor: Colors.red,
              textColor: Colors.white,
              fontSize: 16.0
          );

enter image description here

4 Answers
Fluttertoast.showToast(
    msg: "This is Center Short Toast",
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIosWeb: 1,
    backgroundColor: Colors.red,
    textColor: Colors.white,
    fontSize: 16.0
);

If this didn't work run flutter clean and restart the app

Try below code hope its helpful to you. Using this dependency

Your FlutterTost Widget.

Fluttertoast.showToast(
  msg: "Invalid Username or Password",
  toastLength: Toast.LENGTH_SHORT,
  gravity: ToastGravity.CENTER,
  timeInSecForIosWeb: 1,
  backgroundColor: Colors.blue,       
);

Your result blue color Screen-> Image 1

Your result green color Screen->enter image description here

I faced the same problem. It seems to be a problem with android 11. The code is working in android 10. More infos here.

What worked for me is using the toast with buildcontext. You can create your own child and render it as the toast.

add below lines...

webPosition: "center",
webBgColor: "linear-gradient(to right, #dc1c13, #dc1c13)",

for web you have to give webBgColor...

Related