add material you (dynamic colors) support

This commit is contained in:
Michael 2025-04-27 19:42:53 +03:00
parent fcdf02ed9b
commit f3382303fc
8 changed files with 38 additions and 14 deletions

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:openstore/app_page.dart'; import 'package:openstore/app_page.dart';
import 'package:openstore/search_page.dart'; import 'package:openstore/search_page.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:dynamic_color/dynamic_color.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -38,20 +39,23 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application. // This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp.router( return DynamicColorBuilder(
builder: (lightColorScheme, darkColorScheme) => MaterialApp.router(
title: 'OpenStore', title: 'OpenStore',
theme: ThemeData( theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(builders: { pageTransitionsTheme: const PageTransitionsTheme(builders: {
TargetPlatform.android: PredictiveBackPageTransitionsBuilder(), TargetPlatform.android:
PredictiveBackPageTransitionsBuilder(),
}), }),
colorScheme: ColorScheme.fromSeed( colorScheme: darkColorScheme ??
ColorScheme.fromSeed(
seedColor: Colors.blue, seedColor: Colors.blue,
brightness: Brightness.dark, brightness: Brightness.dark,
), ),
useMaterial3: true, useMaterial3: true,
), ),
routerConfig: _router, routerConfig: _router,
); ));
} }
} }

View file

@ -6,9 +6,13 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
url_launcher_linux url_launcher_linux
) )

View file

@ -5,8 +5,10 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import dynamic_color
import url_launcher_macos import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
} }

View file

@ -49,6 +49,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.8" version: "1.0.8"
dynamic_color:
dependency: "direct main"
description:
name: dynamic_color
sha256: eae98052fa6e2826bdac3dd2e921c6ce2903be15c6b7f8b6d8a5d49b5086298d
url: "https://pub.dev"
source: hosted
version: "1.7.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:

View file

@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.6 cupertino_icons: ^1.0.6
http: ^1.2.1 http: ^1.2.1
go_router: ^15.1.1 go_router: ^15.1.1
dynamic_color: ^1.7.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -6,9 +6,12 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
url_launcher_windows url_launcher_windows
) )