From c4e2deb2d7ef951fc21e7ea12f89c354f26ead61 Mon Sep 17 00:00:00 2001 From: Lea Date: Sat, 23 Sep 2023 22:01:51 +0200 Subject: [PATCH] proper theming --- lib/main.dart | 53 +++++++++++++++++++------------------------ pubspec.lock | 9 ++++++++ pubspec.yaml | 1 + test/widget_test.dart | 2 +- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8e94089..033adf8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,43 +1,36 @@ +import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; void main() { - runApp(const MyApp()); + runApp(const App()); } -class MyApp extends StatelessWidget { - const MyApp({super.key}); +class App extends StatelessWidget { + const App({super.key}); - // This widget is the root of your application. @override Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a purple toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), + return DynamicColorBuilder( + builder: ((lightDynamic, darkDynamic) => MaterialApp( + title: "HRT", + theme: ThemeData( + brightness: Brightness.light, + useMaterial3: true, + colorScheme: lightDynamic, + ), + darkTheme: ThemeData( + brightness: Brightness.dark, + useMaterial3: true, + colorScheme: darkDynamic, + ), + themeMode: ThemeMode.system, + home: const HomePage(title: "HRT"))), ); } } -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); +class HomePage extends StatefulWidget { + const HomePage({super.key, required this.title}); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect @@ -51,10 +44,10 @@ class MyHomePage extends StatefulWidget { final String title; @override - State createState() => _MyHomePageState(); + State createState() => _HomePageState(); } -class _MyHomePageState extends State { +class _HomePageState extends State { int _counter = 0; void _incrementCounter() { diff --git a/pubspec.lock b/pubspec.lock index bf5c98e..fa4db00 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.6" + dynamic_color: + dependency: "direct main" + description: + name: dynamic_color + sha256: "96bff3df72e3d428bda2b874c7a521e8c86f592cae626ea594922fcc8d166e0c" + url: "https://pub.dev" + source: hosted + version: "1.6.7" fake_async: dependency: transitive description: @@ -186,3 +194,4 @@ packages: version: "0.1.4-beta" sdks: dart: ">=3.2.0-134.1.beta <4.0.0" + flutter: ">=3.4.0-17.0.pre" diff --git a/pubspec.yaml b/pubspec.yaml index 6431c7f..18a9b4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + dynamic_color: ^1.6.7 dev_dependencies: flutter_test: diff --git a/test/widget_test.dart b/test/widget_test.dart index ca66a0b..581b1bd 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:hrt/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(const App()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);