Home > OS >  How to change flutter text color for dark and light theme?
How to change flutter text color for dark and light theme?

Time:06-20

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:

  1. You can set both a theme and a darkTheme variance in your MaterialApp properties and having it automatically changed whenever the OS theme changes, based on the text properties that you set;
  2. 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.

  • Related