Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set snack bar's label color?

Tags:

flutter

How can I set custom color for snackBar's label since it is defined as String?

  final snackBar = SnackBar(
    content: Text(_message),
    action: SnackBarAction(
      label: 'Close',
      onPressed: () {},
    ),
  );
like image 985
rozerro Avatar asked Oct 22 '25 02:10

rozerro


1 Answers

You could change the color of the SnackBarAction label using the textColor parameter. Please see below for a code sample showing how this could be done.

final snackBar = SnackBar(
  content: Text(_message),
  action: SnackBarAction(
    textColor: Colors.red,
    label: 'Close',
    onPressed: () {},
  ),
);

Alternatively, you could set the text color of all SnackBarAction labels using the global snackBarTheme parameter of the application's ThemeData.

return MaterialApp(
  home: HomePage(),
  theme: ThemeData(
    snackBarTheme: SnackBarThemeData(
      actionTextColor: Colors.red,
    ),
  ),
);
like image 50
tnc1997 Avatar answered Oct 24 '25 19:10

tnc1997