-
-
Save florentinobenedictus/018ff1248a3848dba06f1e6f449b9d70 to your computer and use it in GitHub Desktop.
lib/src/shared/app.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2022 The Flutter Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
import 'package:dynamic_color/dynamic_color.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'playback/bloc/bloc.dart'; | |
import 'providers/theme.dart'; | |
import 'router.dart'; | |
import 'views/views.dart'; | |
class MyApp extends StatefulWidget { | |
const MyApp({super.key}); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
final settings = ValueNotifier(ThemeSettings( | |
sourceColor: Colors.pink, // Replace this color | |
themeMode: ThemeMode.system, | |
)); | |
@override | |
Widget build(BuildContext context) { | |
return BlocProvider<PlaybackBloc>( | |
create: (context) => PlaybackBloc(), | |
child: DynamicColorBuilder( | |
builder: (lightDynamic, darkDynamic) => ThemeProvider( | |
lightDynamic: lightDynamic, | |
darkDynamic: darkDynamic, | |
settings: settings, | |
child: NotificationListener<ThemeSettingChange>( | |
onNotification: (notification) { | |
settings.value = notification.settings; | |
return true; | |
}, | |
child: ValueListenableBuilder<ThemeSettings>( | |
valueListenable: settings, | |
builder: (context, value, _) { | |
// Create theme instance | |
final theme = ThemeProvider.of(context); // Add this line | |
return MaterialApp.router( | |
debugShowCheckedModeBanner: false, | |
title: 'Flutter Demo', | |
theme: theme.light(settings.value.sourceColor), | |
darkTheme: theme.dark(settings.value.sourceColor), // Add this line | |
themeMode: theme.themeMode(), // Add this line | |
routeInformationParser: appRouter.routeInformationParser, | |
routeInformationProvider: | |
appRouter.routeInformationProvider, | |
routerDelegate: appRouter.routerDelegate, | |
builder: (context, child) { | |
return PlayPauseListener(child: child!); | |
}, | |
); | |
}, | |
), | |
)), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment