2020-12-24 14:16:31 +01:00
|
|
|
import 'package:file_picker/file_picker.dart';
|
2020-03-28 09:39:59 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-12-24 14:16:31 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2020-03-30 23:19:02 +02:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-03-28 09:39:59 +01:00
|
|
|
|
2020-04-07 21:25:01 +02:00
|
|
|
import '../state/music_data_store.dart';
|
2021-02-06 14:00:04 +01:00
|
|
|
import '../theming.dart';
|
2020-03-28 09:39:59 +01:00
|
|
|
|
|
|
|
class SettingsPage extends StatelessWidget {
|
2020-04-07 21:25:01 +02:00
|
|
|
const SettingsPage({Key key}) : super(key: key);
|
2020-03-28 09:39:59 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-07 21:25:01 +02:00
|
|
|
final MusicDataStore store = Provider.of<MusicDataStore>(context);
|
|
|
|
|
2020-03-28 09:39:59 +01:00
|
|
|
return ListView(
|
|
|
|
children: [
|
2020-04-04 21:02:42 +02:00
|
|
|
Container(
|
|
|
|
height: 12.0,
|
|
|
|
),
|
2020-08-08 19:02:03 +02:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
2020-03-30 23:19:02 +02:00
|
|
|
horizontal: 16.0,
|
2020-04-04 21:02:42 +02:00
|
|
|
vertical: 4.0,
|
2020-03-30 23:19:02 +02:00
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
'Library',
|
2021-02-06 14:00:04 +01:00
|
|
|
style: TEXT_HEADER,
|
2020-03-30 23:19:02 +02:00
|
|
|
),
|
|
|
|
),
|
2020-03-28 09:39:59 +01:00
|
|
|
ListTile(
|
2020-03-30 23:19:02 +02:00
|
|
|
title: const Text('Update library'),
|
|
|
|
subtitle: Observer(builder: (_) {
|
2020-12-30 18:28:16 +01:00
|
|
|
final int artistCount = store.artistStream.value.length;
|
|
|
|
final int albumCount = store.albumStream.value.length;
|
|
|
|
final int songCount = store.songStream.value.length;
|
|
|
|
return Text('$artistCount artists, $albumCount albums, $songCount songs');
|
2020-03-30 23:19:02 +02:00
|
|
|
}),
|
2020-12-24 14:16:31 +01:00
|
|
|
onTap: () => store.updateDatabase(),
|
2020-03-30 23:19:02 +02:00
|
|
|
trailing: Observer(builder: (_) {
|
|
|
|
if (store.isUpdatingDatabase) {
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
height: 0,
|
|
|
|
width: 0,
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2020-04-04 21:02:42 +02:00
|
|
|
const Divider(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
2020-03-30 23:19:02 +02:00
|
|
|
ListTile(
|
2020-04-07 21:25:01 +02:00
|
|
|
title: const Text('Select library folders'),
|
2020-08-12 20:59:00 +02:00
|
|
|
trailing: const Icon(Icons.chevron_right),
|
2020-12-28 16:41:03 +01:00
|
|
|
onTap: () => _openFilePicker(store),
|
2020-03-30 23:19:02 +02:00
|
|
|
),
|
2020-04-04 21:02:42 +02:00
|
|
|
const Divider(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
2020-03-28 09:39:59 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2020-12-24 14:16:31 +01:00
|
|
|
|
2020-12-28 16:41:03 +01:00
|
|
|
Future<void> _openFilePicker(MusicDataStore store) async {
|
2020-12-24 14:16:31 +01:00
|
|
|
try {
|
2020-12-28 16:41:03 +01:00
|
|
|
store.addLibraryFolder(await FilePicker.platform.getDirectoryPath());
|
2020-12-24 14:16:31 +01:00
|
|
|
} on PlatformException catch (e) {
|
|
|
|
print('Unsupported operation' + e.toString());
|
|
|
|
} catch (ex) {
|
|
|
|
print(ex);
|
|
|
|
}
|
|
|
|
}
|
2020-03-28 09:39:59 +01:00
|
|
|
}
|