From 2d89866c50a4639a437424fdbd5f7835b96dcfff Mon Sep 17 00:00:00 2001 From: Pierre-Louis <6655696+guidezpl@users.noreply.github.com> Date: Wed, 30 Mar 2022 16:05:27 +0200 Subject: [PATCH] Minor improvements to `ThemeExtension` example (#100693) * Update theme_extension.1.dart * empty commit * update color names to be semantic --- .../lib/material/theme/theme_extension.1.dart | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/api/lib/material/theme/theme_extension.1.dart b/examples/api/lib/material/theme/theme_extension.1.dart index 6ea2bb87ed..85be388b55 100644 --- a/examples/api/lib/material/theme/theme_extension.1.dart +++ b/examples/api/lib/material/theme/theme_extension.1.dart @@ -10,18 +10,18 @@ import 'package:flutter/scheduler.dart'; @immutable class MyColors extends ThemeExtension { const MyColors({ - required this.blue, - required this.red, + required this.brandColor, + required this.danger, }); - final Color? blue; - final Color? red; + final Color? brandColor; + final Color? danger; @override - MyColors copyWith({Color? red, Color? blue}) { + MyColors copyWith({Color? brandColor, Color? danger}) { return MyColors( - blue: blue ?? this.blue, - red: red ?? this.red, + brandColor: brandColor ?? this.brandColor, + danger: danger ?? this.danger, ); } @@ -31,14 +31,14 @@ class MyColors extends ThemeExtension { return this; } return MyColors( - blue: Color.lerp(blue, other.blue, t), - red: Color.lerp(red, other.red, t), + brandColor: Color.lerp(brandColor, other.brandColor, t), + danger: Color.lerp(danger, other.danger, t), ); } // Optional @override - String toString() => 'MyColors(blue: $blue, red: $red)'; + String toString() => 'MyColors(brandColor: $brandColor, danger: $danger)'; } void main() { @@ -68,20 +68,20 @@ class _MyAppState extends State { return MaterialApp( title: MyApp._title, theme: ThemeData.light().copyWith( - extensions: >{ + extensions: >[ const MyColors( - blue: Color(0xFF1E88E5), - red: Color(0xFFE53935), + brandColor: Color(0xFF1E88E5), + danger: Color(0xFFE53935), ), - }, + ], ), darkTheme: ThemeData.dark().copyWith( - extensions: >{ + extensions: >[ const MyColors( - blue: Color(0xFF90CAF9), - red: Color(0xFFEF9A9A), + brandColor: Color(0xFF90CAF9), + danger: Color(0xFFEF9A9A), ), - }, + ], ), themeMode: isLightTheme ? ThemeMode.light : ThemeMode.dark, home: Home( @@ -110,9 +110,9 @@ class Home extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Container(width: 100, height: 100, color: myColors.blue), + Container(width: 100, height: 100, color: myColors.brandColor), const SizedBox(width: 10), - Container(width: 100, height: 100, color: myColors.red), + Container(width: 100, height: 100, color: myColors.danger), const SizedBox(width: 50), IconButton( icon: Icon(isLightTheme ? Icons.nightlight : Icons.wb_sunny),