m3_color_scheme 0.0.1
m3_color_scheme: ^0.0.1 copied to clipboard
A utility package for generating Material 3 (M3) color schemes in Flutter apps.
m3_color_scheme #
Utilities for generating Material 3 ColorScheme and ThemeData from a seed color using the official material_color_utilities algorithms.
This package provides:
M3ColorSchemeextension: Converts aDynamicScheme(frommaterial_color_utilities) into Flutter'sColorScheme.DynamicThemehelper: Builds light and darkThemeDatafrom a single seed color with optional Material 3 and typography configuration.
Installation #
Add to your pubspec.yaml:
dependencies:
m3_color_scheme: ^0.0.1
Then run:
flutter pub get
Quick start #
Create a dynamic Material 3 theme for your app from a seed color:
import 'package:flutter/material.dart';
import 'package:m3_color_scheme/m3_color_scheme.dart';
void main() {
final dynamicTheme = DynamicTheme.fromColor(
const Color(0xFF6750A4), // Your seed color
useMaterial3: true,
fontFamily: 'Inter', // optional
);
runApp(MaterialApp(
theme: dynamicTheme.lightTheme,
darkTheme: dynamicTheme.darkTheme,
themeMode: ThemeMode.system,
home: const MyHomePage(),
));
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('M3 Dynamic Theme')),
body: Center(
child: FilledButton(
onPressed: () {},
child: const Text('Hello'),
),
),
);
}
}
API #
-
extension M3ColorScheme on DynamicSchemeColorScheme toColorScheme()- Maps all fields from a
DynamicScheme(e.g., fromSchemeTonalSpot) to Flutter'sColorScheme, including primary/secondary/tertiary, containers, error, outline, surface variants, inverse colors, shadow, scrim, andbrightness.
- Maps all fields from a
-
class DynamicThemefactory DynamicTheme.fromColor(Color seedColor, { bool? useMaterial3, String? fontFamily, PageTransitionsTheme? pageTransitionsTheme })- Generates both light and dark
ThemeDatausing the Tonal Spot scheme derived from the givenseedColor. - Returns an instance with
lightThemeanddarkThemeproperties.
- Generates both light and dark
Using the extension directly #
If you prefer to work with material_color_utilities yourself, you can build a scheme and convert it:
import 'package:flutter/material.dart';
import 'package:material_color_utilities/material_color_utilities.dart';
import 'package:m3_color_scheme/m3_color_scheme.dart';
final hct = Hct.fromInt(const Color(0xFF006876).value);
final dynamicScheme = SchemeTonalSpot(
sourceColorHct: hct,
isDark: false,
contrastLevel: 0.0,
);
final colorScheme = dynamicScheme.toColorScheme();
final theme = ThemeData(colorScheme: colorScheme, useMaterial3: true);
Notes #
- Built on top of the official
material_color_utilitiespackage. - Ensure you opt in to Material 3 (
useMaterial3: true) if you want M3 components and defaults. fontFamilyandpageTransitionsThemeare optional conveniences passed through to the producedThemeData.
Related links #
- Material Color Utilities:
https://github.com/material-foundation/material-color-utilities
License #
This project is licensed. See LICENSE for details.
Changelog #
See CHANGELOG.md for version history.