Skip to content

Commit a83ad6b

Browse files
authored
Improve theming (#366)
* Improve theming * Move headerbar to splashscreen
1 parent b6a34cc commit a83ad6b

File tree

5 files changed

+61
-54
lines changed

5 files changed

+61
-54
lines changed

lib/main.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ Future<void> main(List<String> args) async {
7979

8080
registerService<RadioService>(() => RadioService());
8181

82-
runApp(
83-
const MusicPod(),
84-
);
82+
if (Platform.isLinux) {
83+
runApp(const GtkApplication(child: YaruMusicPodApp()));
84+
} else {
85+
runApp(
86+
const MusicPodApp(),
87+
);
88+
}
8589
}

lib/src/app/musicpod.dart

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
11
import 'dart:ui';
22

33
import 'package:flutter/material.dart';
4-
import 'package:gtk/gtk.dart';
54
import 'package:ubuntu_service/ubuntu_service.dart';
65
import 'package:yaru/yaru.dart';
76

87
import '../../app.dart';
9-
import '../../common.dart';
108
import '../../library.dart';
119
import '../../theme.dart';
1210
import '../l10n/l10n.dart';
1311
import 'app.dart';
1412

15-
class MusicPod extends StatelessWidget {
16-
const MusicPod({super.key});
13+
class YaruMusicPodApp extends StatelessWidget {
14+
const YaruMusicPodApp({
15+
super.key,
16+
});
1717

1818
@override
1919
Widget build(BuildContext context) {
20-
if (yaruStyled) {
21-
return YaruTheme(
22-
builder: (context, yaruThemeData, child) {
23-
return GtkApplication(
24-
child: MusicPodApp(
25-
lightTheme: yaruThemeData.theme,
26-
darkTheme: yaruThemeData.darkTheme?.copyWith(
27-
scaffoldBackgroundColor: const Color(0xFF1e1e1e),
28-
),
20+
return YaruTheme(
21+
builder: (context, yaru, child) {
22+
return MusicPodApp(
23+
lightTheme: yaru.theme,
24+
darkTheme: yaru.darkTheme?.copyWith(
25+
scaffoldBackgroundColor: const Color(0xFF1e1e1e),
26+
dividerColor: darkDividerColor,
27+
dividerTheme: const DividerThemeData(
28+
color: darkDividerColor,
29+
space: 1.0,
30+
thickness: 0.0,
2931
),
30-
);
31-
},
32-
);
33-
} else {
34-
return MusicPodApp(
35-
lightTheme: m3Theme(),
36-
darkTheme: m3Theme(brightness: Brightness.dark),
37-
);
38-
}
32+
),
33+
);
34+
},
35+
child: const MusicPodApp(),
36+
);
3937
}
4038
}
4139

42-
class MusicPodApp extends StatelessWidget {
40+
class MusicPodApp extends StatefulWidget {
4341
const MusicPodApp({
4442
super.key,
4543
this.lightTheme,
@@ -48,32 +46,35 @@ class MusicPodApp extends StatelessWidget {
4846

4947
final ThemeData? lightTheme, darkTheme;
5048

49+
@override
50+
State<MusicPodApp> createState() => _MusicPodAppState();
51+
}
52+
53+
class _MusicPodAppState extends State<MusicPodApp> {
54+
bool initialized = false;
55+
56+
@override
57+
void initState() {
58+
super.initState();
59+
getService<LibraryService>().init().then(
60+
(value) {
61+
if (!initialized) {
62+
setState(() => initialized = value);
63+
}
64+
},
65+
);
66+
}
67+
5168
@override
5269
Widget build(BuildContext context) {
53-
const dividerColor = Color.fromARGB(19, 255, 255, 255);
5470
return MaterialApp(
5571
debugShowCheckedModeBanner: false,
56-
theme: lightTheme,
57-
darkTheme: darkTheme?.copyWith(
58-
dividerColor: dividerColor,
59-
dividerTheme: const DividerThemeData(
60-
color: dividerColor,
61-
space: 1.0,
62-
thickness: 0.0,
63-
),
64-
),
72+
theme: widget.lightTheme ?? m3Theme(),
73+
darkTheme: widget.darkTheme ?? m3Theme(brightness: Brightness.dark),
6574
localizationsDelegates: AppLocalizations.localizationsDelegates,
6675
supportedLocales: supportedLocales,
6776
onGenerateTitle: (context) => 'MusicPod',
68-
home: FutureBuilder(
69-
future: getService<LibraryService>().init(),
70-
builder: (context, snapshot) {
71-
if (snapshot.connectionState == ConnectionState.done) {
72-
return App.create();
73-
}
74-
return const Scaffold(appBar: HeaderBar(), body: SplashScreen());
75-
},
76-
),
77+
home: initialized ? App.create() : const SplashScreen(),
7778
scrollBehavior: const MaterialScrollBehavior().copyWith(
7879
dragDevices: {
7980
PointerDeviceKind.mouse,

lib/src/app/splash_screen.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import 'package:flutter/material.dart';
22

33
import '../../build_context_x.dart';
4+
import '../common/common_widgets.dart';
45
import '../common/icons.dart';
56

67
class SplashScreen extends StatefulWidget {
78
const SplashScreen({
89
super.key,
9-
this.color,
1010
});
1111

12-
final Color? color;
13-
1412
@override
1513
State<SplashScreen> createState() => _SplashScreenState();
1614
}
@@ -42,9 +40,10 @@ class _SplashScreenState extends State<SplashScreen>
4240
@override
4341
Widget build(BuildContext context) {
4442
final theme = context.t;
45-
return Material(
46-
color: widget.color ?? theme.scaffoldBackgroundColor,
47-
child: Center(
43+
return Scaffold(
44+
appBar: const HeaderBar(),
45+
backgroundColor: theme.scaffoldBackgroundColor,
46+
body: Center(
4847
child: AnimatedOpacity(
4948
duration: const Duration(milliseconds: 100),
5049
curve: Curves.bounceIn,

lib/src/library/library_service.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,13 @@ class LibraryService {
389389
_neverShowFailedImportsController.add(true);
390390
}
391391

392-
Future<void> init() async {
392+
bool _libraryInitialized = false;
393+
Future<bool> init() async {
393394
await _initSettings();
394395
await _initLibrary();
396+
return _libraryInitialized;
395397
}
396398

397-
bool _libraryInitialized = false;
398399
Future<void> _initLibrary() async {
399400
if (_libraryInitialized) return;
400401
if (_useLocalAudioCache == true) {

lib/src/theme.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import 'package:flutter/material.dart';
44

55
import 'color_scheme_x.dart';
66

7+
const darkDividerColor = Color.fromARGB(19, 255, 255, 255);
8+
79
ThemeData m3Theme({
810
Brightness brightness = Brightness.light,
911
Color color = Colors.greenAccent,
1012
}) {
1113
final dividerColor = brightness == Brightness.light
1214
? const Color.fromARGB(48, 0, 0, 0)
13-
: const Color.fromARGB(18, 255, 255, 255);
15+
: darkDividerColor;
1416
final colorScheme = ColorScheme.fromSeed(
1517
surfaceTint: Colors.transparent,
1618
seedColor: color,

0 commit comments

Comments
 (0)