Flutter primarySwatch changes text colors and icon colors

Viewed 652

I am currently getting into using Themes in Flutter. I don't fully understand the primarySwatch yet.

I am setting an app wide theme in the MaterialApp class. I wan tto change the primarySwatch, so all the buttons I use within the app have the same color. When I use primarySwatch: Colors.blue, the text and icons inside the buttons, inside the appBar and so on are white. When I use primarySwatch: Colors.orange, the text is black. I found out that there are "bright" and "dark" colors, and probably according to that, the text color changes from white to black. But is there a way to use a "bright" color and still have white texts and icons without overriding all of them?

1 Answers

EDIT: I didn't see that the question asked "without overriding all of them"

You may want to create a TextButtonThemeData in your ThemeData like so:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        textButtonTheme: TextButtonThemeData(
          style: ButtonStyle(
            textStyle: MaterialStateProperty.all<TextStyle>(
              TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
Related