mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add config
This commit is contained in:
46
lib/module/config/config_viewmodel.dart
Normal file
46
lib/module/config/config_viewmodel.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/module/config/config_bean.dart';
|
||||
|
||||
var configProvider = ChangeNotifierProvider((ref) => ConfigViewModel());
|
||||
|
||||
class ConfigViewModel extends BaseViewModel {
|
||||
List<ConfigBean> list = [];
|
||||
|
||||
String content = "";
|
||||
String title = "";
|
||||
|
||||
Future<void> loadData([isLoading = true]) async {
|
||||
if (isLoading) {
|
||||
loading(notify: true);
|
||||
}
|
||||
|
||||
HttpResponse<List<ConfigBean>> result = await Api.files();
|
||||
|
||||
if (result.success && result.bean != null) {
|
||||
list.clear();
|
||||
list.addAll(result.bean!);
|
||||
title = list[0].value!;
|
||||
success();
|
||||
loadContent(list[0].value!);
|
||||
} else {
|
||||
list.clear();
|
||||
failed(result.message, notify: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadContent(String name) async {
|
||||
title = name;
|
||||
notifyListeners();
|
||||
HttpResponse<String> result = await Api.content(name);
|
||||
|
||||
if (result.success && result.bean != null) {
|
||||
content = result.bean!;
|
||||
success();
|
||||
} else {
|
||||
failToast(result.message, notify: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user