So, it looks like default text color for ElevatedButton is white while default text color for (deprecated) RaisedButton is black.
I would like the text color to be automatically modified based on the background color (light color -> black, dark color -> white).
Based on this answer I used a custom ButtonThemeData but this doesn't apply to ElevatedButton. I know there exist ElevatedButtonTheme and ElevatedButtonThemeData but I'm a bit lost about how to override them properly.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary)),
home: Scaffold(body: Center(child: Buttons())),
);
}
}
class Buttons extends StatefulWidget {
const Buttons({Key key}) : super(key: key);
@override
_ButtonsState createState() => _ButtonsState();
}
class _ButtonsState extends State<Buttons> {
var color = Colors.white;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
child: Text("RaisedButton (set black)"),
color: color,
onPressed: () => setState(() => color = Colors.black),
),
ElevatedButton(
child: Text("ElevatedButton (set white)"),
style: TextButton.styleFrom(backgroundColor: color),
onPressed: () => setState(() => color = Colors.white),
),
],
);
}
}
Please, how can I get the same result for my ElevatedButton, without having to specify the text color in TextButton.styleFrom()?
For what it's worth, I noticed this change while switching from Flutter 2.0.6 to 2.2.3.
