How to change flutter text color for dark theme and light theme, can anyone answer me ?
title: Text('Kitchen Name', )
CodePudding user response:
There are two ways of doing so:
- You can set both a
theme
and adarkTheme
variance in yourMaterialApp
properties and having it automatically changed whenever the OS theme changes, based on the text properties that you set; - Or, you can manually check for the current brightness in your
Text
style's property (when the brightness is dark, the OS should be using a dark theme, and a light when it's light).
title: Text(
'Kitchen Name',
style: Theme.of(context).brightness == Brightness.dark ? TextStyle(color: Colors.white) : TextStyle(color: Colors.black),
),
I'd pick the 1 since it's the most correct way of doing it.