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: () {},
)
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: () {},
)
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')),
),
],
),
),
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.
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.