2020-04-06 22:33:26 +02:00
|
|
|
import 'package:audio_service/audio_service.dart';
|
2020-03-20 16:17:02 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-03-28 11:06:23 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import 'package:mosh/presentation/widgets/injection_widget.dart';
|
2020-03-28 09:39:59 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2020-03-24 22:17:03 +01:00
|
|
|
|
2020-03-28 09:39:59 +01:00
|
|
|
import 'presentation/pages/home_page.dart';
|
|
|
|
import 'presentation/pages/library_page.dart';
|
|
|
|
import 'presentation/pages/settings_page.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import 'presentation/state/music_data_store.dart';
|
2020-03-28 09:39:59 +01:00
|
|
|
import 'presentation/theming.dart';
|
2020-04-06 22:33:26 +02:00
|
|
|
import 'presentation/widgets/audio_service_widget.dart';
|
2020-03-24 22:17:03 +01:00
|
|
|
import 'presentation/widgets/navbar.dart';
|
2020-04-06 22:33:26 +02:00
|
|
|
import 'system/datasources/audio_manager.dart';
|
2020-03-20 16:17:02 +01:00
|
|
|
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-03-28 11:06:23 +01:00
|
|
|
SystemChrome.setPreferredOrientations([
|
|
|
|
DeviceOrientation.portraitUp,
|
|
|
|
]);
|
|
|
|
|
2020-03-20 16:17:02 +01:00
|
|
|
return MaterialApp(
|
2020-04-07 21:25:01 +02:00
|
|
|
title: 'mucke',
|
2020-03-28 09:39:59 +01:00
|
|
|
theme: theme(),
|
2020-04-07 21:25:01 +02:00
|
|
|
home: const AudioServiceWidget(
|
|
|
|
child: InjectionWidget(
|
|
|
|
child: RootPage(),
|
2020-03-20 16:17:02 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RootPage extends StatefulWidget {
|
2020-04-06 22:33:26 +02:00
|
|
|
const RootPage({Key key}) : super(key: key);
|
2020-03-20 16:17:02 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
_RootPageState createState() => _RootPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RootPageState extends State<RootPage> {
|
|
|
|
var navIndex = 0;
|
|
|
|
|
2020-04-07 21:25:01 +02:00
|
|
|
final List<Widget> _pages = <Widget>[
|
|
|
|
HomePage(),
|
|
|
|
const LibraryPage(
|
|
|
|
key: PageStorageKey('LibraryPage'),
|
|
|
|
),
|
|
|
|
const SettingsPage(
|
|
|
|
key: PageStorageKey('SettingsPage'),
|
|
|
|
),
|
|
|
|
];
|
2020-03-28 09:39:59 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
2020-04-07 21:25:01 +02:00
|
|
|
final MusicDataStore _musicStore = Provider.of<MusicDataStore>(context);
|
2020-03-28 09:39:59 +01:00
|
|
|
_musicStore.fetchAlbums();
|
2020-04-03 13:55:15 +02:00
|
|
|
_musicStore.fetchSongs();
|
2020-03-28 09:39:59 +01:00
|
|
|
|
2020-04-07 21:25:01 +02:00
|
|
|
// TODO: don't do this here...
|
2020-04-07 22:06:43 +02:00
|
|
|
AudioService.start(
|
|
|
|
backgroundTaskEntrypoint: _backgroundTaskEntrypoint,
|
|
|
|
enableQueue: true,
|
|
|
|
androidStopOnRemoveTask: true,
|
|
|
|
);
|
2020-04-06 22:33:26 +02:00
|
|
|
|
2020-03-28 09:39:59 +01:00
|
|
|
super.didChangeDependencies();
|
|
|
|
}
|
2020-03-20 16:17:02 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-04-03 15:51:43 +02:00
|
|
|
body: IndexedStack(
|
|
|
|
index: navIndex,
|
|
|
|
children: _pages,
|
2020-04-03 13:55:15 +02:00
|
|
|
),
|
2020-03-20 16:17:02 +01:00
|
|
|
bottomNavigationBar: NavBar(
|
|
|
|
onTap: (int index) {
|
|
|
|
setState(() {
|
|
|
|
navIndex = index;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
currentIndex: navIndex,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-04-06 22:33:26 +02:00
|
|
|
|
|
|
|
void _backgroundTaskEntrypoint() {
|
|
|
|
AudioServiceBackground.run(() => AudioPlayerTask());
|
|
|
|
}
|