forked from mirrors/material_3_expressive
Bump m3e_design to 0.2.1; add .toM3EThemeData() extension for simplified theme creation, update documentation, and refactor BuildContext extension for fallback handling.
This commit is contained in:
parent
eef97c0938
commit
c6e843f238
5 changed files with 88 additions and 20 deletions
|
|
@ -110,3 +110,21 @@ extension M3EThemeAccessors on ThemeData {
|
|||
return e ?? M3ETheme.defaults(colorScheme);
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience creation helpers to install M3ETheme with minimal boilerplate.
|
||||
extension M3EColorSchemeAccessors on ColorScheme {
|
||||
/// Creates a ThemeData from this ColorScheme and installs the M3ETheme
|
||||
/// extension in one call.
|
||||
///
|
||||
/// Example:
|
||||
/// final theme = ColorScheme.fromSeed(seedColor: Colors.teal).toM3EThemeData();
|
||||
ThemeData toM3EThemeData({
|
||||
bool useMaterial3 = true,
|
||||
M3ETheme? override,
|
||||
ThemeData? base,
|
||||
}) {
|
||||
final ThemeData seed =
|
||||
base ?? ThemeData(useMaterial3: useMaterial3, colorScheme: this);
|
||||
return withM3ETheme(seed, override: override);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ import 'package:flutter/material.dart';
|
|||
import '../theme/m3e_theme.dart';
|
||||
|
||||
extension BuildContextM3EX on BuildContext {
|
||||
M3ETheme get m3e => Theme.of(this).m3e;
|
||||
M3ETheme get m3e =>
|
||||
Theme.of(this).extension<M3ETheme>() ?? M3ETheme.defaults(Theme.of(this).colorScheme);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue