Skip to content

MaterialBanner with ScaffoldMessenger: Unable to change the divider color. #123937

@superakabo

Description

@superakabo

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Tap the Tap to reveal the bug button to show the material banner widget.

Expected results:
Since the divider color property of the material banner has been set to green, it must show a green divider color.

Actual results:
The material banner has a red divider color.

Code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Bug Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.blue,
        ),
        bannerTheme: const MaterialBannerThemeData(
          dividerColor: Colors.red,
        ),
      ),
      home: const MyHomePage(title: 'Flutter Material Banner Bug'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 4,
        title: Text(title),
      ),
      body: Column(
        children: [
          MaterialBanner(
            content: const Text(
              'This banner has a red divider\n'
              'because it is using the banner theme\'s divider color.\n'
              'It works as expected.',
            ),
            padding: const EdgeInsets.all(24),
            actions: [
              TextButton(
                onPressed: () {},
                child: const Text('OK'),
              ),
            ],
          ),
          MaterialBanner(
            dividerColor: Colors.yellow,
            content: const Text(
              'This banner has a yellow divider\n'
              'because the divider color has been overridden.\n'
              'It works as expected.',
            ),
            padding: const EdgeInsets.all(24),
            actions: [
              TextButton(
                onPressed: () {},
                child: const Text('OK'),
              ),
            ],
          ),
          const Padding(
            padding: EdgeInsets.only(top: 48),
          ),
          ElevatedButton(
            child: const Text('Tap to reveal the bug'),
            onPressed: () {
              ScaffoldMessenger.of(context).showMaterialBanner(
                MaterialBanner(
                  dividerColor: Colors.green,
                  content: const Text(
                    'This banner should have a green divider\n'
                    'because the divider color has been overridden but it still has a red divider.\n'
                    'It does not work as expected 😔',
                  ),
                  padding: const EdgeInsets.all(24),
                  actions: [
                    TextButton(
                      onPressed: () {
                        ScaffoldMessenger.of(context).clearMaterialBanners();
                      },
                      child: const Text('BUG'),
                    ),
                  ],
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
[✓] Flutter (Channel master, 3.9.0-16.0.pre.7, on macOS 12.6.3 21G419 darwin-x64, locale en-GB)
    • Flutter version 3.9.0-16.0.pre.7 on channel master at /Users/samuel/Library/Flutter/sdk
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ae14df98ba (9 days ago), 2023-03-23 03:18:18 -0400
    • Engine revision 9e25f2f6ea
    • Dart version 3.0.0 (build 3.0.0-358.0.dev)
    • DevTools version 2.22.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/samuel/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (4 available)
    • TECNO KA7 (mobile) • 03744098BW014549          • android-arm    • Android 8.1.0 (API 27)
    • iPhone (mobile)    • 00008101-000131C03C38001E • ios            • iOS 16.4 20E247
    • macOS (desktop)    • macos                     • darwin-x64     • macOS 12.6.3 21G419 darwin-x64
    • Chrome (web)       • chrome                    • web-javascript • Google Chrome 111.0.5563.146

[✓] Network resources
    • All expected network resources are available.

Screenshot 2023-04-01 at 5 07 30 PM

Screenshot 2023-04-01 at 5 11 25 PM

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.found in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions