💄 Dynamic app color based on playing track

This commit is contained in:
2025-12-16 23:24:26 +08:00
parent 29edbfbb8a
commit 5edc9cf2ca
9 changed files with 482 additions and 35 deletions

View File

@@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
import 'package:groovybox/logic/audio_handler.dart';
import 'package:groovybox/providers/audio_provider.dart';
import 'package:groovybox/providers/theme_provider.dart';
import 'package:groovybox/ui/shell.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:media_kit/media_kit.dart';
import 'package:audio_service/audio_service.dart' as audio_service;
import 'logic/audio_handler.dart';
import 'providers/audio_provider.dart';
import 'ui/shell.dart';
late AudioHandler _audioHandler;
@@ -25,42 +26,33 @@ Future<void> main() async {
// Set the audio handler for the provider
setAudioHandler(_audioHandler);
runApp(const ProviderScope(child: MyApp()));
runApp(
ProviderScope(
child: Builder(
builder: (context) {
// Get the provider container and set it on the audio handler
final container = ProviderScope.containerOf(context);
_audioHandler.setProviderContainer(container);
return const GroovyApp();
},
),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class GroovyApp extends ConsumerWidget {
const GroovyApp({super.key});
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeProvider);
return MaterialApp(
title: 'GroovyBox',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
),
useMaterial3: true,
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(Radius.circular(12)),
),
),
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
),
useMaterial3: true,
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(Radius.circular(12)),
),
),
),
themeMode: ThemeMode.system,
theme: ref.watch(lightThemeProvider),
darkTheme: ref.watch(darkThemeProvider),
themeMode: themeMode,
home: const Shell(),
);
}