79 lines
2.5 KiB
Dart
79 lines
2.5 KiB
Dart
import 'package:fast_cached_network_image/fast_cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:just_audio_background/just_audio_background.dart';
|
|
import 'package:just_audio_media_kit/just_audio_media_kit.dart';
|
|
import 'package:ocarina/api/subsonic/song.dart';
|
|
import 'package:ocarina/views/home_view.dart';
|
|
import 'package:ocarina/widgets/player.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:responsive_sizer/responsive_sizer.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() async {
|
|
JustAudioMediaKit.ensureInitialized();
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await JustAudioBackground.init(
|
|
androidNotificationChannelId: 'wtf.caras.ocarina.bg_playback',
|
|
androidNotificationChannelName: 'Ocarina playback',
|
|
androidNotificationOngoing: true,
|
|
);
|
|
|
|
await FastCachedImageConfig.init(
|
|
clearCacheAfter: const Duration(days: 31),
|
|
subDir: (await getApplicationCacheDirectory()).path,
|
|
);
|
|
|
|
sp = await SharedPreferences.getInstance();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
/// [GlobalKey] used to set the [Player]'s state from other code
|
|
final playerKey = GlobalKey<PlayerState>();
|
|
|
|
/// Instance of [SharedPreferences] used to get shared preferences
|
|
late final SharedPreferences sp;
|
|
|
|
/// Notifier to change theme from inside the app
|
|
final ValueNotifier<ColorScheme> themeNotifier =
|
|
ValueNotifier(ColorScheme.fromSeed(seedColor: Colors.deepPurple));
|
|
|
|
/// Notifier to change theme from inside the app
|
|
final ValueNotifier<Song?> songNotifier = ValueNotifier(null);
|
|
|
|
/// Main app class
|
|
class MyApp extends StatelessWidget {
|
|
/// Main app class
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ResponsiveSizer(
|
|
builder: (context, orientation, screenType) {
|
|
return ValueListenableBuilder<ColorScheme>(
|
|
valueListenable: themeNotifier,
|
|
builder: (BuildContext context, ColorScheme value, Widget? child) {
|
|
return MaterialApp(
|
|
title: 'Ocarina',
|
|
theme: ThemeData(
|
|
colorScheme: value,
|
|
useMaterial3: true,
|
|
),
|
|
home: const HomeView(),
|
|
builder: (context, child) {
|
|
return Stack(
|
|
children: [
|
|
child!,
|
|
Player(
|
|
key: playerKey,
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|