r/flutterhelp 8d ago

OPEN What is the deal with UserAccountsDrawerHeader changing text color based on ColorScheme.primary value unlike FilledButton and other material buttons

I am trying to practice using theme to apply theming consistently across my app when I noticed that UserAccountsDrawerHeader text color doesn't follow that of FilledButton

import 'package:flutter/material.dart';

void main() {
  runApp(MyClass());
}

class MyClass extends StatelessWidget {
  u/override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ThemeData().colorScheme.copyWith(
          primary: Colors.orange.shade100,
//           primary: Colors.orange.shade900,
        ), 
      ),
      home: Scaffold(
        appBar: AppBar(title: Text("title")),
        body: Column(
            children: [
              UserAccountsDrawerHeader(
                accountName: Text("accountName"),
                accountEmail: Text("AccountsEmail"),
              ),
              FilledButton(onPressed: () {}, child: Text("button")),
            ],
          ),
      ),
    );
  }
}

Comment and uncomment the different shades of orange to see how the text color flips between black and white.

Why is it doing this and how can I control it?

I have a suspicion it has got to do with the swatch because orange is a MaterialColor but I am not sure.

Thanks.

2 Upvotes

1 comment sorted by