简体   繁体   中英

How to change the text default colour when ExpansionTile is expanded flutter

I want to change this blue Colour when the ExpansionTile expands, unfortunately I just found that you can easily change the Background Colour of the whole header with this collapsedBackgroundColor: , but is there also a way to change the texts background colour?

在此处输入图像描述

Try this

class MyExpansionTile extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return ExpansionTile(
            title: Text(
              'Example',
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500),
            ),
            collapsedTextColor: Colors.green,
            textColor: Colors.blue
          );
      }
  }

for more details Collapsed Text Color

You can modify the textColor and iconColor and its corresponding collapsed variants.

          child: ExpansionTile(
            textColor: Colors.amber,
            iconColor: Colors.amber,
            collapsedTextColor: Colors.purpleAccent,
            collapsedIconColor: Colors.purpleAccent,

See the colors: 代码

The ExpansionTile collapsed

折叠

And expanded

展开

create ThemeData and define expansionTileTheme in it. You can also create different themes for dark and light modes

final appTheme = ThemeData(
        colorScheme:ColorScheme(
          //....
              ),
      expansionTileTheme:ExpansionTileThemeData(
        textColor: Colors.grey,
        iconColor: Colors.grey
      ),// This Part
      cardColor: Colors.grey[900],
      appBarTheme: AppBarTheme(
        color: Colors.lightBlueAccent[500],
        foregroundColor: Colors.white70
      ),
      scaffoldBackgroundColor: Colors.black,
      fontFamily: 'Montserrat',
    );

add it to materialApp

MaterialApp(
      navigatorKey: navigatorKey,
      scaffoldMessengerKey: scaffoldMessengerKey,
      theme: appTheme,
      darkTheme: darkTheme,
      themeMode:  brightness == null
          ? ThemeMode.system
          : brightness == Brightness.dark
              ? ThemeMode.dark
              : ThemeMode.light,
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM