How to set snack bar's label color?

Viewed 1300

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: () {},
    ),
  );
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,
    ),
  ),
);
Related