mucke/lib/presentation/pages/settings_page.dart

76 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:file_picker/file_picker.dart';
2020-03-28 09:39:59 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2020-03-30 23:19:02 +02:00
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:provider/provider.dart';
2020-03-28 09:39:59 +01:00
import '../state/music_data_store.dart';
import '../theming.dart';
2020-03-28 09:39:59 +01:00
class SettingsPage extends StatelessWidget {
const SettingsPage({Key key}) : super(key: key);
2020-03-28 09:39:59 +01:00
@override
Widget build(BuildContext context) {
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',
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
}),
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(
title: const Text('Select library folders'),
2020-08-12 20:59:00 +02:00
trailing: const Icon(Icons.chevron_right),
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
],
);
}
Future<void> _openFilePicker(MusicDataStore store) async {
try {
store.addLibraryFolder(await FilePicker.platform.getDirectoryPath());
} on PlatformException catch (e) {
print('Unsupported operation' + e.toString());
} catch (ex) {
print(ex);
}
}
2020-03-28 09:39:59 +01:00
}