display error if mount location is not found
This commit is contained in:
parent
7605be809c
commit
52d210974b
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:repertory/constants.dart' as constants;
|
||||||
import 'package:repertory/helpers.dart';
|
import 'package:repertory/helpers.dart';
|
||||||
import 'package:repertory/models/mount_list.dart';
|
import 'package:repertory/models/mount_list.dart';
|
||||||
import 'package:repertory/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
@ -73,9 +74,9 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mount(bool unmount, {String? location}) async {
|
Future<bool> mount(bool unmount, {String? location}) async {
|
||||||
try {
|
try {
|
||||||
await http.post(
|
final response = await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
|
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
|
||||||
@ -83,10 +84,16 @@ class Mount with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return refresh();
|
if (response.statusCode == 500) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('$e');
|
debugPrint('$e');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
|
@ -158,10 +158,23 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
|
|
||||||
mount
|
mount
|
||||||
.mount(isActive, location: location)
|
.mount(isActive, location: location)
|
||||||
.then((_) {
|
.then((success) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isActive || !context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: const Text(
|
||||||
|
"Mount location not found",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catchError((_) {
|
.catchError((_) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user