This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce `YaruTheme` widget The `YaruTheme` widget detects the appropriate flavor and accent color from the system, and applies the appropriate Yaru theme to its descendants. ```dart MaterialApp( home: YaruTheme( child: ... ), ) ``` Applications may choose a specific flavor and accent color by manually setting the `accent` and `flavor` properties, respectively. ```dart YaruTheme( accent: YaruAccent.red, flavor: YaruFlavor.ubuntu, child: ... ) ``` * example: use the YaruTheme widget
- Loading branch information
Showing
9 changed files
with
612 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:yaru/yaru.dart'; | ||
import 'package:yaru_example/view/home_page.dart'; | ||
|
||
void main() { | ||
runApp(MultiProvider( | ||
providers: [ | ||
ChangeNotifierProvider(create: (_) => LightTheme(yaruLight)), | ||
ChangeNotifierProvider(create: (_) => DarkTheme(yaruDark)), | ||
ChangeNotifierProvider(create: (_) => AppTheme(ThemeMode.light)), | ||
], | ||
child: MyApp(), | ||
)); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: HomePage(), | ||
home: Builder(builder: (context) { | ||
return YaruTheme( | ||
data: AppTheme.of(context), | ||
child: HomePage(), | ||
); | ||
}), | ||
debugShowCheckedModeBanner: false, | ||
themeMode: context.watch<AppTheme>().value, | ||
theme: context.watch<LightTheme>().value, | ||
darkTheme: context.watch<DarkTheme>().value, | ||
); | ||
} | ||
} | ||
|
||
class LightTheme extends ValueNotifier<ThemeData> { | ||
LightTheme(ThemeData value) : super(value); | ||
} | ||
|
||
class DarkTheme extends ValueNotifier<ThemeData> { | ||
DarkTheme(ThemeData value) : super(value); | ||
} | ||
class AppTheme { | ||
static YaruThemeData of(BuildContext context) { | ||
return SharedAppData.getValue(context, 'theme', () => YaruThemeData()); | ||
} | ||
|
||
class AppTheme extends ValueNotifier<ThemeMode> { | ||
AppTheme(ThemeMode value) : super(value); | ||
static void apply( | ||
BuildContext context, { | ||
YaruAccent? accent, | ||
YaruFlavor? flavor, | ||
bool? highContrast, | ||
ThemeMode? themeMode, | ||
}) { | ||
SharedAppData.setValue( | ||
context, | ||
'theme', | ||
AppTheme.of(context).copyWith( | ||
themeMode: themeMode, | ||
accent: accent, | ||
flavor: flavor, | ||
highContrast: highContrast, | ||
), | ||
); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ environment: | |
dependencies: | ||
flutter: | ||
sdk: flutter | ||
provider: ^6.0.2 | ||
yaru: | ||
path: ../ | ||
|
||
|
Oops, something went wrong.