From dc36748a4ca568233738f0f331f4abab952a98ba Mon Sep 17 00:00:00 2001 From: Reuben Turner Date: Tue, 13 Apr 2021 15:12:45 -0400 Subject: [PATCH] Add primaryColor to Style (#19) Renames MacosApp's primaryColor to simply "color" as a result. --- example/lib/main.dart | 6 +++--- lib/src/layout/scaffold.dart | 2 +- lib/src/macos_app.dart | 8 ++++---- lib/src/styles/theme.dart | 12 ++++++++++-- lib/src/util.dart | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 0a6e6fba..3894cc46 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -17,11 +17,11 @@ class MyApp extends StatelessWidget { title: 'macos_ui example', style: Style( brightness: Brightness.light, - accentColor: CupertinoColors.systemIndigo, + primaryColor: CupertinoColors.systemIndigo, ), darkStyle: Style( brightness: Brightness.dark, - accentColor: CupertinoColors.systemIndigo, + primaryColor: CupertinoColors.systemIndigo, ), themeMode: appTheme.mode, debugShowCheckedModeBanner: false, //yay! @@ -43,7 +43,7 @@ class Demo extends StatelessWidget { child: Container( height: 50.0, width: 50.0, - color: context.theme.accentColor, + color: context.style.primaryColor, ), ), ); diff --git a/lib/src/layout/scaffold.dart b/lib/src/layout/scaffold.dart index 4ba12870..eb39757d 100644 --- a/lib/src/layout/scaffold.dart +++ b/lib/src/layout/scaffold.dart @@ -66,7 +66,7 @@ class Scaffold extends StatelessWidget { Widget build(BuildContext context) { debugCheckHasMacosTheme(context); - final style = context.theme; + final style = context.style; late Color bodyColor; late Color sidebarColor; late Color gripColor; diff --git a/lib/src/macos_app.dart b/lib/src/macos_app.dart index 6f60758c..47ba08fe 100644 --- a/lib/src/macos_app.dart +++ b/lib/src/macos_app.dart @@ -52,7 +52,7 @@ class MacosApp extends StatefulWidget { this.builder, this.title = '', this.onGenerateTitle, - this.primaryColor, + this.color, this.locale, this.localizationsDelegates, this.localeListResolutionCallback, @@ -85,7 +85,7 @@ class MacosApp extends StatefulWidget { this.builder, this.title = '', this.onGenerateTitle, - this.primaryColor, + this.color, this.locale, this.localizationsDelegates, this.localeListResolutionCallback, @@ -170,7 +170,7 @@ class MacosApp extends StatefulWidget { final GenerateAppTitle? onGenerateTitle; /// {@macro flutter.widgets.widgetsApp.color} - final Color? primaryColor; + final Color? color; /// {@macro flutter.widgets.widgetsApp.locale} final Locale? locale; @@ -329,7 +329,7 @@ class _MacosAppState extends State { } Widget _buildApp(BuildContext context) { - final defaultColor = widget.primaryColor ?? CupertinoColors.systemBlue; + final defaultColor = widget.color ?? CupertinoColors.systemBlue; if (_usesRouter) { return c.CupertinoApp.router( key: GlobalObjectKey(this), diff --git a/lib/src/styles/theme.dart b/lib/src/styles/theme.dart index 4029595c..ed10d265 100644 --- a/lib/src/styles/theme.dart +++ b/lib/src/styles/theme.dart @@ -32,8 +32,8 @@ class MacosTheme extends InheritedWidget { } extension themeContext on BuildContext { - Style get theme => MacosTheme.of(this); - Style? get maybeTheme => MacosTheme.maybeOf(this); + Style get style => MacosTheme.of(this); + Style? get maybeStyle => MacosTheme.maybeOf(this); } extension brightnessExtension on Brightness { @@ -48,11 +48,14 @@ class Style with Diagnosticable { const Style({ this.typography, this.brightness, + this.primaryColor, this.accentColor, this.animationCurve, this.mediumAnimationDuration, }); + final CupertinoDynamicColor? primaryColor; + final CupertinoDynamicColor? accentColor; final Curve? animationCurve; @@ -69,6 +72,7 @@ class Style with Diagnosticable { brightness: brightness, typography: Typography.defaultTypography(brightness: brightness) .copyWith(typography), + primaryColor: primaryColor ?? CupertinoColors.systemBlue, accentColor: accentColor ?? CupertinoColors.systemBlue, mediumAnimationDuration: Duration(milliseconds: 300), animationCurve: Curves.easeInOut, @@ -90,6 +94,8 @@ class Style with Diagnosticable { animationCurve: other.animationCurve ?? animationCurve, mediumAnimationDuration: other.mediumAnimationDuration ?? mediumAnimationDuration, + primaryColor: other.primaryColor ?? primaryColor, + accentColor: other.accentColor ?? accentColor, ); } @@ -97,5 +103,7 @@ class Style with Diagnosticable { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(EnumProperty('brightness', brightness)); + properties.add(EnumProperty('primaryColor', primaryColor)); + properties.add(EnumProperty('accentColor', accentColor)); } } diff --git a/lib/src/util.dart b/lib/src/util.dart index ed9b55e5..8416a156 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -1,7 +1,7 @@ import 'package:macos_ui/macos_ui.dart'; bool debugCheckHasMacosTheme(BuildContext context, [bool check = true]) { - final has = context.maybeTheme != null; + final has = context.maybeStyle != null; if (check) assert( has,