material-foundation / flutter-packages

A collection of useful Material Design packages
https://pub.dev/publishers/material.io
Apache License 2.0
834 stars 157 forks source link

Dynamic color doesn't seem to render colors correctly #303

Open MaxYablochkin opened 1 year ago

MaxYablochkin commented 1 year ago

Both examples show the problem in both light and dark mode.

  1. When returning to the main screen:

https://user-images.githubusercontent.com/102767277/211525680-26063ed1-46e9-464d-b2e6-d6e44d6207a8.mp4

  1. When changing the theme, and then returning to the main screen:

https://user-images.githubusercontent.com/102767277/211526673-2e6c25a8-b713-4abb-bebc-ccf65b21efc5.mp4

[✓] Flutter (Channel master, 3.7.0-16.0.pre.14, on Microsoft Windows [Version 10.0.22621.963], locale ru-UA)
    • Flutter version 3.7.0-16.0.pre.14 on channel master at C:\Flutter-SDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 583a8122bc (73 minutes ago), 2023-01-10 01:18:03 -0800
    • Engine revision 716bb9172c
    • Dart version 3.0.0 (build 3.0.0-103.0.dev)
    • DevTools version 2.20.0

[✗] Windows Version (Unable to confirm if installed Windows version is 10 or greater)

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\yablo\AppData\Local\Android\sdk
    • Platform android-TiramisuPrivacySandbox, build-tools 32.1.0-rc1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33205.214
    • Windows 10 SDK version 10.0.22000.0

[✓] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.1
    • Flutter plugin version 71.0.2
    • Dart plugin version 212.5744

[✓] VS Code (version 1.74.2)
    • VS Code at C:\Users\yablo\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.963]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 108.0.5359.125
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 108.0.1462.76

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
MaxYablochkin commented 1 year ago
import 'package:flutter/material.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:google_fonts/google_fonts.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return DynamicColorBuilder(
      builder: (lightDynamic, darkDynamic) {
        return MaterialApp(
          title: 'Test AppBar',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            useMaterial3: true,
            brightness: Brightness.light,
            colorScheme: lightDynamic,
          ),
          darkTheme: ThemeData(
            useMaterial3: true,
            brightness: Brightness.dark,
            colorScheme: darkDynamic,
          ),
          home: IterableList(),
        );
      },
    );
  }
}

class IterableList extends StatefulWidget {
  const IterableList({super.key});

  @override
  State<IterableList> createState() => _IterableListState();
}

class _IterableListState extends State<IterableList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Small TopAppBar'),
        actions: [
          IconButton(onPressed: () {}, icon: Icon(Icons.favorite)),
          IconButton(onPressed: () {}, icon: Icon(Icons.favorite)),
        ],
        shape: Border.all(color: Colors.transparent),
        toolbarHeight: 64,
      ),
      drawer: MyNavigationDrawer(),
      body: ListView.builder(
        itemCount: 76,
        itemBuilder: (context, index) {
          return Padding(
            padding: EdgeInsets.only(left: 15, bottom: 6),
            child: Text(index.toString(), style: TextStyle(fontSize: 16)),
          );
        },
      ),
    );
  }
}

class MyNavigationDrawer extends StatefulWidget {
  const MyNavigationDrawer({super.key});

  @override
  State<MyNavigationDrawer> createState() => _MyNavigationDrawerState();
}

class _MyNavigationDrawerState extends State<MyNavigationDrawer> {
  int selectedIndex = 0;

  void onDestinationSelected(int index) {
    setState(() {
      selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return NavigationDrawer(
      selectedIndex: selectedIndex,
      onDestinationSelected: onDestinationSelected,
      children: [
        Padding(
          padding: EdgeInsets.only(left: 28),
          child: Text(
            'Navigation Drawer',
            style: GoogleFonts.manrope(
              fontWeight: FontWeight.w500,
              textStyle: Theme.of(context).textTheme.titleLarge,
              height: 3,
            ),
          ),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.token_outlined),
          selectedIcon: Icon(Icons.token),
          label: Text('Inbox'),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.mail_outline),
          selectedIcon: Icon(Icons.mail),
          label: Text('OutBox'),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.favorite_border_outlined),
          selectedIcon: Icon(Icons.favorite),
          label: Text('Favorites'),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.delete_outline),
          selectedIcon: Icon(Icons.delete),
          label: Text('Trash'),
        ),
        Divider(indent: 28, endIndent: 28),
        NavigationDrawerDestination(
          icon: Icon(Icons.circle_outlined),
          label: Text('Label circle'),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.change_history),
          label: Text('Label triagle'),
        ),
        NavigationDrawerDestination(
          icon: Icon(Icons.square_outlined),
          label: Text('Label square'),
        ),
        Divider(indent: 28, endIndent: 28),
        Center(
          child: TextButton(
            onPressed: () {},
            child: Text('Navigation Drawer'),
          ),
        ),
        Center(
          child: OutlinedButton(
            onPressed: () {},
            child: Text('Navigation Drawer'),
          ),
        ),
        Center(
          child: ElevatedButton(
            onPressed: () {},
            child: Text('Navigation Drawer'),
          ),
        ),
        Center(
          child: FilledButton(
            onPressed: () {},
            child: Text('Navigation Drawer'),
          ),
        ),
        Center(
          child: FilledButton.tonal(
            onPressed: () {},
            child: Text('Navigation Drawer'),
          ),
        ),
        Center(
          child: FilledButton.tonalIcon(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => CardScreen()),
              );
            },
            icon: Icon(Icons.replay_circle_filled_outlined),
            label: Text('Cards screen'),
          ),
        ),
      ],
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Cards',
          style: GoogleFonts.manrope(
            fontWeight: FontWeight.w500,
            textStyle: Theme.of(context).textTheme.titleLarge,
          ),
        ),
        shape: Border.all(color: Colors.transparent),
      ),
      body: ListView(
        padding: EdgeInsets.all(20),
        children: [
          Card(
            child: SizedBox(
              width: 300,
              height: 150,
              child: Center(child: Text('Elevated Card')),
            ),
          ),
          Card(
            elevation: 0,
            color: Theme.of(context).colorScheme.surfaceVariant,
            child: SizedBox(
              width: 300,
              height: 150,
              child: Center(child: Text('Filled Card')),
            ),
          ),
          Card(
            elevation: 0,
            shape: RoundedRectangleBorder(
              side: BorderSide(color: Theme.of(context).colorScheme.outline),
              borderRadius: BorderRadius.circular(12),
            ),
            child: SizedBox(
              width: 300,
              height: 150,
              child: Center(child: Text('Outlined Card')),
            ),
          ),
          Card(
            child: InkWell(
              onTap: () {},
              radius: 150,
              borderRadius: BorderRadius.circular(12),
              child: SizedBox(
                width: 300,
                height: 150,
                child: Center(child: Text('Elevated Card (clickable)')),
              ),
            ),
          ),
          Card(
            elevation: 0,
            color: Theme.of(context).colorScheme.surfaceVariant,
            child: InkWell(
              onTap: () {},
              radius: 150,
              borderRadius: BorderRadius.circular(12),
              child: SizedBox(
                width: 300,
                height: 150,
                child: Center(child: Text('Filled Card (clickable)')),
              ),
            ),
          ),
          Card(
            elevation: 0,
            shape: RoundedRectangleBorder(
              side: BorderSide(color: Theme.of(context).colorScheme.outline),
              borderRadius: BorderRadius.circular(12),
            ),
            child: InkWell(
              onTap: () {},
              radius: 150,
              borderRadius: BorderRadius.circular(12),
              child: SizedBox(
                width: 300,
                height: 150,
                child: Center(child: Text('Outlined Card (clickable)')),
              ),
            ),
          ),
        ],
      ),
    );
  }
}