Skip to content

AppBar doesn't apply overriden Theme #50606

@feinstein

Description

@feinstein

I have a very simple AppBar outside of a Scaffold, like:

class MyScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          AppBar(
            title: Text('hi'),
            flexibleSpace: Container(color: Colors.purple, height: 200,),
          ),
          Expanded(
            child: Center(
              child: Text('hi again'),
            ),
          ),
        ],
      ),
    );
  }
}

Which renders like:

image

The MaterialApp theme primaryColorBrightness is Brightness.light.

Now, if I change the MaterialApp theme primaryColorBrightness to Brightness.dark the status bar color AND the AppBar icons and text change to white:

image

But if I just want to change the Theme for MyScreen and not the whole app, the status bar changes color to white, but the AppBar doesn't:

class MyScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(primaryColorBrightness: Brightness.dark),
      child: Scaffold(
        body: Column(
          children: <Widget>[
            AppBar(
              title: Text('hi'),
              flexibleSpace: Container(color: Colors.purple, height: 200,),
            ),
            Expanded(
              child: Center(
                child: Text('hi again'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

As can be seen here:

image

This inconsistency seems like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions