'flutter: set font of SnackbarAction label

Is there a way to set the font of a SnackBarAction in flutter? It seems to use the default system font.

SnackBarAction(
                label: 'my text', // how to sent font?
                onPressed: () {},
              )


Solution 1:[1]

you can define custom theme for snackbar globally in ThemeData:

runApp(MaterialApp(
    theme: ThemeData(
      snackBarTheme: SnackBarThemeData(contentTextStyle: TextStyle(fontFamily: "customfontName")
    ),
),

to change font of action button inside Snack bar you can define font for text of button itself:

SnackBar(
   content: Row(
      children: [
          Expanded(child: Text('Some Text')),
          TextButton(
            child: Text('Action', 
               style: TextStyle(fontFamily: 'Your Font')),
               ),
             ],
          ),     
        ),

Solution 2:[2]

Declare a common snackBarTheme inside ThemeData which you might have inside your main.dart,

 runApp(MaterialApp(
    theme: ThemeData(
      snackBarTheme: SnackBarThemeData(contentTextStyle: TextStyle(fontFamily: "montserrat")),
    ),
...

Do not forget to restart app completely to test the solution.

Solution 3:[3]

You can customize the Snackbar's action font family by changing the button theme in the app's global theme. This is because the Snackbar's action is considered as a button. For example, set:

MaterialApp(
  theme: ThemeData(
    textTheme: TextTheme(
       button: TextStyle(fontFamily: 'Raleway'),
    ),
  ),
  home: const MyHomePage(title: appName),
);

The actions in Snackbars will be affected as desired if you follow the instructions on https://flutter.dev/docs/cookbook/design/fonts for implementing custom fonts.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3