2024-05-23 19:14:08 +02:00
|
|
|
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';
|
2024-05-24 00:10:11 +02:00
|
|
|
import 'package:ocarina/api/subsonic/song.dart';
|
2024-05-23 19:14:08 +02:00
|
|
|
import 'package:ocarina/views/home_view.dart';
|
|
|
|
import 'package:ocarina/widgets/player.dart';
|
2024-05-23 20:36:42 +02:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2024-05-23 19:14:08 +02:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2024-05-23 20:36:42 +02:00
|
|
|
await FastCachedImageConfig.init(
|
|
|
|
clearCacheAfter: const Duration(days: 31),
|
|
|
|
subDir: (await getApplicationCacheDirectory()).path,
|
|
|
|
);
|
2024-05-24 00:10:11 +02:00
|
|
|
|
2024-05-23 19:14:08 +02:00
|
|
|
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;
|
|
|
|
|
2024-05-24 00:10:11 +02:00
|
|
|
/// 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
|
2024-05-23 19:14:08 +02:00
|
|
|
class MyApp extends StatelessWidget {
|
2024-05-24 00:10:11 +02:00
|
|
|
/// Main app class
|
2024-05-23 19:14:08 +02:00
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ResponsiveSizer(
|
|
|
|
builder: (context, orientation, screenType) {
|
2024-05-24 00:10:11 +02:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2024-05-23 19:14:08 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|