This commit is contained in:
@ -1,13 +1,42 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/errors/duplicate_mount_exception.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
|
||||
class MountList with ChangeNotifier {
|
||||
final List<MountConfig> _items = [MountConfig(name: "test")];
|
||||
MountList() {
|
||||
_fetch();
|
||||
}
|
||||
|
||||
List<MountConfig> _items = [];
|
||||
|
||||
UnmodifiableListView get items => UnmodifiableListView(_items);
|
||||
|
||||
Future<void> _fetch() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${Uri.base.origin}/api/v1/mount_list'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<MountConfig> items = [];
|
||||
|
||||
var data = jsonDecode(response.body);
|
||||
data.forEach((key, value) {
|
||||
items.addAll(
|
||||
value.map((name) => MountConfig.fromJson(key, name)).toList(),
|
||||
);
|
||||
});
|
||||
items.sort((a, b) => a.name.compareTo(b.name));
|
||||
_items = items;
|
||||
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void add(MountConfig config) {
|
||||
var item = _items.firstWhereOrNull((cfg) => cfg.name == config.name);
|
||||
if (item != null) {
|
||||
@ -16,6 +45,7 @@ class MountList with ChangeNotifier {
|
||||
|
||||
_items.add(config);
|
||||
_items.sort((a, b) => a.name.compareTo(b.name));
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
class MountConfig {
|
||||
final String _name;
|
||||
MountConfig({required name}) : _name = name;
|
||||
final String _type;
|
||||
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||
|
||||
String get name => _name;
|
||||
String get type => _type;
|
||||
|
||||
factory MountConfig.fromJson(String type, String name) {
|
||||
return MountConfig(name: name, type: type);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class MountWidget extends StatelessWidget {
|
||||
child: Container(
|
||||
height: 40,
|
||||
color: Colors.blue,
|
||||
child: Text(mountConfig.name),
|
||||
child: Text('${mountConfig.type} ${mountConfig.name}'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
|
||||
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.12.0"
|
||||
version: "2.13.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -53,10 +53,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
version: "1.3.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -75,14 +75,30 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.1.2"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
|
||||
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.8"
|
||||
version: "10.0.9"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -208,6 +224,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -220,10 +244,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
|
||||
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.3.1"
|
||||
version: "15.0.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
sdks:
|
||||
dart: ">=3.7.0 <4.0.0"
|
||||
flutter: ">=3.18.0-18.0.pre.54"
|
||||
|
@ -35,6 +35,7 @@ dependencies:
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.8
|
||||
collection: ^1.19.1
|
||||
http: ^1.3.0
|
||||
provider: ^6.1.2
|
||||
|
||||
dev_dependencies:
|
||||
|
Reference in New Issue
Block a user