1

I am new to flutter, I don't know if it is possible to do this. I would like to put an icon on the left side of the text.

SnackBar(    
  backgroundColor: Colors.red,
  content: Text(_accion_toast + ". " + mensaje),
  duration: Duration(milliseconds: 1500),
);

2 Answers 2

7

The content property of the Snackbar takes a Widget.

In your case, you can pass the Row widget since you want to place items side by side( your icon and your text).

Check the code below, it works fine:

   SnackBar(
      // background color of your snack-bar
      backgroundColor: Colors.red,
      // make the content property take a Row
      content: Row(
        children: <Widget>[
          // add your preferred icon here
          Icon(
            Icons.close,
            color: Colors.white,
          ),
          // add your preferred text content here
          Text(_accion_toast + ". " + mensaje),
        ],
      ),
      // the duration of your snack-bar
      duration: Duration(milliseconds: 1500),
    );
  }
5

You can change the content parameter of the SnackBar to a row containing first the Icon and then the Text. An example:

SnackBar(    
  backgroundColor: Colors.red,
  content: Row(
    children: <Widget>[
      //Icon widget of your choice HERE,
      Text(_accion_toast + ". " + mensaje)
    ]
  ),
  duration: Duration(milliseconds: 1500),
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.