mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 00:59:28 +01:00
add snackbar method for errors
test (ping) server before saving source display error message when saving source
This commit is contained in:
parent
889be2ff2c
commit
67f0c926c4
@ -12,6 +12,7 @@ import '../../log.dart';
|
||||
import '../../models/settings.dart';
|
||||
import '../../services/settings_service.dart';
|
||||
import '../items.dart';
|
||||
import '../snackbars.dart';
|
||||
|
||||
class SourcePage extends HookConsumerWidget {
|
||||
final int? id;
|
||||
@ -164,6 +165,7 @@ class SourcePage extends HookConsumerWidget {
|
||||
}
|
||||
} catch (e, st) {
|
||||
// TOOD: toast the error or whatever
|
||||
showErrorSnackbar(context, e.toString());
|
||||
log.severe('Saving source', e, st);
|
||||
error = true;
|
||||
} finally {
|
||||
|
||||
14
lib/app/snackbars.dart
Normal file
14
lib/app/snackbars.dart
Normal file
@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void showErrorSnackbar(BuildContext context, String message) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(message, style: TextStyle(color: colors.onErrorContainer)),
|
||||
backgroundColor: colors.errorContainer,
|
||||
showCloseIcon: true,
|
||||
closeIconColor: colors.onErrorContainer,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 10),
|
||||
));
|
||||
}
|
||||
@ -53,6 +53,8 @@ class SettingsService extends _$SettingsService {
|
||||
ref.read(httpClientProvider),
|
||||
);
|
||||
|
||||
await client.test();
|
||||
|
||||
final features = IList([
|
||||
if (await client.testFeature(SubsonicFeature.emptyQuerySearch))
|
||||
SubsonicFeature.emptyQuerySearch,
|
||||
@ -66,6 +68,10 @@ class SettingsService extends _$SettingsService {
|
||||
}
|
||||
|
||||
Future<void> updateSource(SubsonicSettings source) async {
|
||||
final client = SubsonicClient(source, ref.read(httpClientProvider));
|
||||
|
||||
await client.test();
|
||||
|
||||
await _db.updateSource(source);
|
||||
await init();
|
||||
}
|
||||
|
||||
@ -98,6 +98,8 @@ class SubsonicClient {
|
||||
return subsonicResponse;
|
||||
}
|
||||
|
||||
Future<void> test() => get('ping');
|
||||
|
||||
Future<bool> testFeature(SubsonicFeature feature) async {
|
||||
switch (feature) {
|
||||
case SubsonicFeature.emptyQuerySearch:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user