Flutter: How to set TextButton Style in ThemeData

Viewed 369

I am trying to set the TextButtonTheme in my ThemeData file.

ButtonThemeData _basicButtonTheme(ButtonThemeData base) {
    return base.copyWith(
      buttonColor: Colors.orange,
    );
  }

  TextButtonThemeData _basicTextButtonTheme(TextButtonThemeData base) {
    return base.copyWith(ButtonStyle());
  }

However, I can not quite set the theme for TextButton. I've read about TextButtonTheme on Flutter Doc. But, I can't figure it out how I can set it as TextButton variable. How can I set the theme for TextButton to pass down to my ThemeData.copyWith()?

1 Answers

To set the theme for a textbutton you can do the following in your MaterialApp:

@override
Widget build(BuildContext context) {
  return MaterialApp(
    theme: ThemeData(
      primarySwatch: Colors.blue,
      colorScheme: ColorScheme.fromSwatch(
        primarySwatch: Colors.blue,
      ).copyWith(),      
    ),
    home: Home(),
  );
}
Related