mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add task
This commit is contained in:
@@ -50,7 +50,7 @@ class _BaseStateWidgetState<T extends BaseViewModel> extends ConsumerState<BaseS
|
|||||||
if (viewModel.currentState == PageState.FAILED) {
|
if (viewModel.currentState == PageState.FAILED) {
|
||||||
return Container(
|
return Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text("请求失败"),
|
child: Text(viewModel.failReason ??""),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
|
class ViewModel extends ChangeNotifier {}
|
||||||
class ViewModel extends ChangeNotifier{}
|
|
||||||
|
|
||||||
|
|
||||||
class BaseViewModel extends ViewModel {
|
class BaseViewModel extends ViewModel {
|
||||||
PageState currentState = PageState.START;
|
PageState currentState = PageState.START;
|
||||||
|
String? failReason;
|
||||||
|
|
||||||
void loading({bool notify = false}) {
|
void loading({bool notify = false}) {
|
||||||
currentState = PageState.LOADING;
|
currentState = PageState.LOADING;
|
||||||
@@ -21,8 +20,9 @@ class BaseViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void failed({bool notify = false}) {
|
void failed(String? reason, {bool notify = false}) {
|
||||||
currentState = PageState.FAILED;
|
currentState = PageState.FAILED;
|
||||||
|
failReason = reason;
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|||||||
21
lib/base/http/api.dart
Normal file
21
lib/base/http/api.dart
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:qinglong_app/base/http/http.dart';
|
||||||
|
import 'package:qinglong_app/module/login/login_bean.dart';
|
||||||
|
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||||
|
|
||||||
|
import 'url.dart';
|
||||||
|
|
||||||
|
class Api {
|
||||||
|
static Future<HttpResponse<LoginBean>> login(String userName, String passWord) async {
|
||||||
|
return await Http.post<LoginBean>(
|
||||||
|
Url.LOGIN,
|
||||||
|
{
|
||||||
|
"username": userName,
|
||||||
|
"password": passWord,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<List<TaskBean>>> crons() async {
|
||||||
|
return await Http.get<List<TaskBean>>(Url.TASKS, {"searchValue": ""});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:dio_log/dio_log.dart';
|
import 'package:dio_log/dio_log.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@@ -27,48 +30,111 @@ class Http {
|
|||||||
_dio?.interceptors.add(TokenInterceptor());
|
_dio?.interceptors.add(TokenInterceptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<T>> post<T>(String uri, Map<String, dynamic> json, {bool compute = true}) async {
|
static void _init() {
|
||||||
if (userInfoViewModel.host == null || userInfoViewModel.host!.isEmpty) {
|
|
||||||
return HttpResponse(success: false, code: NOT_LOGIN, message: "未登录");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_dio == null) {
|
if (_dio == null) {
|
||||||
initDioConfig(UserInfoViewModel.getInstance().host!);
|
initDioConfig(UserInfoViewModel.getInstance().host!);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<T>> get<T>(String uri, Map<String, String> json, {bool compute = true}) async {
|
||||||
|
_init();
|
||||||
|
var response = await _dio!.get(uri, queryParameters: json);
|
||||||
|
|
||||||
|
return decodeResponse<T>(response, compute);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<T>> post<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||||
|
_init();
|
||||||
var response = await _dio!.post(uri, data: json);
|
var response = await _dio!.post(uri, data: json);
|
||||||
|
|
||||||
return decodeResponse<T>(response, compute);
|
return decodeResponse<T>(response, compute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<T>> delete<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||||
|
_init();
|
||||||
|
var response = await _dio!.delete(uri, data: json);
|
||||||
|
|
||||||
|
return decodeResponse<T>(response, compute);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<HttpResponse<T>> put<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||||
|
_init();
|
||||||
|
var response = await _dio!.put(uri, data: json);
|
||||||
|
|
||||||
|
return decodeResponse<T>(response, compute);
|
||||||
|
}
|
||||||
|
|
||||||
static HttpResponse<T> decodeResponse<T>(
|
static HttpResponse<T> decodeResponse<T>(
|
||||||
Response<dynamic> response,
|
Response<dynamic> response,
|
||||||
bool compute,
|
bool compute,
|
||||||
) {
|
) {
|
||||||
late HttpResponse<T> result;
|
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
if (compute) {
|
|
||||||
try {
|
try {
|
||||||
if (response.data["code"] == 200) {
|
if (response.data["code"] == 200) {
|
||||||
|
if (response.data["data"] != null) {
|
||||||
|
if (T is Void) {
|
||||||
|
return HttpResponse<T>(
|
||||||
|
success: true,
|
||||||
|
code: 200,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
dynamic data = response.data["data"];
|
dynamic data = response.data["data"];
|
||||||
T bean = DeserializeAction.invokeJson(DeserializeAction<T>(data));
|
T t;
|
||||||
result = HttpResponse<T>(success: true, code: 200, bean: bean);
|
if (T is String) {
|
||||||
|
if (data is String) {
|
||||||
|
t = data as T;
|
||||||
} else {
|
} else {
|
||||||
result = HttpResponse<T>(success: false, code: -1000, message: "服务器返回数据异常");
|
t = jsonEncode(data) as T;
|
||||||
|
}
|
||||||
|
return HttpResponse<T>(
|
||||||
|
success: true,
|
||||||
|
code: 200,
|
||||||
|
bean: t,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
T bean;
|
||||||
|
if (compute) {
|
||||||
|
bean = DeserializeAction.invokeJson(DeserializeAction<T>(data));
|
||||||
|
} else {
|
||||||
|
bean = JsonConversion$Json.fromJson<T>(data);
|
||||||
|
}
|
||||||
|
return HttpResponse<T>(
|
||||||
|
success: true,
|
||||||
|
code: 200,
|
||||||
|
bean: bean,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return HttpResponse<T>(
|
||||||
|
success: false,
|
||||||
|
code: 200,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return HttpResponse<T>(
|
||||||
|
success: false,
|
||||||
|
code: -1000,
|
||||||
|
message: "服务器返回数据异常",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result = HttpResponse<T>(success: false, code: -1000, message: "json解析失败");
|
return HttpResponse<T>(
|
||||||
}
|
success: false,
|
||||||
|
code: -1000,
|
||||||
|
message: "json解析失败",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code = response.statusCode ?? 0;
|
code = response.statusCode ?? 0;
|
||||||
result = HttpResponse(success: false, code: code, message: response.statusMessage);
|
return HttpResponse(
|
||||||
|
success: false,
|
||||||
|
code: code,
|
||||||
|
message: response.statusMessage,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
class Url {
|
class Url {
|
||||||
static const LOGIN = "api/user/login";
|
static const LOGIN = "/api/user/login";
|
||||||
|
static const TASKS = "/api/crons";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,15 @@ var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel());
|
|||||||
class ThemeViewModel extends ChangeNotifier {
|
class ThemeViewModel extends ChangeNotifier {
|
||||||
ThemeData currentTheme = lightTheme;
|
ThemeData currentTheme = lightTheme;
|
||||||
|
|
||||||
|
ThemeColors themeColor = LightartThemeColors();
|
||||||
|
|
||||||
void changeTheme() {
|
void changeTheme() {
|
||||||
if (currentTheme == darkTheme) {
|
if (currentTheme == darkTheme) {
|
||||||
currentTheme = lightTheme;
|
currentTheme = lightTheme;
|
||||||
|
themeColor = LightartThemeColors();
|
||||||
} else {
|
} else {
|
||||||
currentTheme = darkTheme;
|
currentTheme = darkTheme;
|
||||||
|
themeColor = DartThemeColors();
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@@ -23,3 +27,21 @@ ThemeData darkTheme = ThemeData.dark().copyWith(
|
|||||||
ThemeData lightTheme = ThemeData.light().copyWith(
|
ThemeData lightTheme = ThemeData.light().copyWith(
|
||||||
primaryColor: Color(0xFF0F77FE),
|
primaryColor: Color(0xFF0F77FE),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
abstract class ThemeColors {
|
||||||
|
Color taskTitleColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
class LightartThemeColors extends ThemeColors {
|
||||||
|
@override
|
||||||
|
Color taskTitleColor() {
|
||||||
|
return Color(0xff333333);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DartThemeColors extends ThemeColors {
|
||||||
|
@override
|
||||||
|
Color taskTitleColor() {
|
||||||
|
return Colors.white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class UserInfoViewModel {
|
|||||||
|
|
||||||
UserInfoViewModel._() {
|
UserInfoViewModel._() {
|
||||||
String userInfoJson = SpUtil.getString(sp_UserINfo);
|
String userInfoJson = SpUtil.getString(sp_UserINfo);
|
||||||
_host = SpUtil.getString(sp_Host);
|
_host = SpUtil.getString(sp_Host,defValue: "http://49.234.59.95:5700");
|
||||||
if (userInfoJson.isNotEmpty) {
|
if (userInfoJson.isNotEmpty) {
|
||||||
_token = userInfoJson;
|
_token = userInfoJson;
|
||||||
}
|
}
|
||||||
@@ -34,4 +34,8 @@ class UserInfoViewModel {
|
|||||||
String? get token => _token;
|
String? get token => _token;
|
||||||
|
|
||||||
String? get host => _host;
|
String? get host => _host;
|
||||||
|
|
||||||
|
bool isLogined() {
|
||||||
|
return token != null && token!.isNotEmpty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio_log/overlay_draggable_button.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
import 'package:qinglong_app/base/theme.dart';
|
import 'package:qinglong_app/base/theme.dart';
|
||||||
import 'package:qinglong_app/module/login/login_page.dart';
|
import 'package:qinglong_app/module/login/login_page.dart';
|
||||||
|
import 'package:qinglong_app/utils/sp_utils.dart';
|
||||||
|
|
||||||
import 'base/routes.dart';
|
import 'base/routes.dart';
|
||||||
import 'base/userinfo_viewmodel.dart';
|
import 'base/userinfo_viewmodel.dart';
|
||||||
@@ -15,9 +17,9 @@ late UserInfoViewModel userInfoViewModel;
|
|||||||
|
|
||||||
var logger = Logger();
|
var logger = Logger();
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await SpUtil.getInstance();
|
||||||
userInfoViewModel = UserInfoViewModel.getInstance();
|
userInfoViewModel = UserInfoViewModel.getInstance();
|
||||||
runApp(
|
runApp(
|
||||||
ProviderScope(
|
ProviderScope(
|
||||||
@@ -48,8 +50,13 @@ class MyApp extends ConsumerWidget {
|
|||||||
onGenerateRoute: (setting) {
|
onGenerateRoute: (setting) {
|
||||||
return Routes.generateRoute(setting);
|
return Routes.generateRoute(setting);
|
||||||
},
|
},
|
||||||
// home: ref.read<UserInfoViewModel>(userInfoProvider).userInfoBean != null ? const HomePage() : LoginPage(),
|
home: Builder(
|
||||||
home: LoginPage(),
|
builder: (context) {
|
||||||
|
showDebugBtn(context, btnColor: Colors.blue);
|
||||||
|
return userInfoViewModel.isLogined() ? const HomePage() : LoginPage();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// home: LoginPage(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
showDebugBtn(context, btnColor: Colors.blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:qinglong_app/base/base_viewmodel.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/base/http/http.dart';
|
||||||
import 'package:qinglong_app/base/http/url.dart';
|
import 'package:qinglong_app/base/http/url.dart';
|
||||||
import 'package:qinglong_app/main.dart';
|
import 'package:qinglong_app/main.dart';
|
||||||
@@ -19,13 +20,7 @@ class LoginViewModel extends ViewModel {
|
|||||||
msg = "";
|
msg = "";
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
HttpResponse<LoginBean> response = await Http.post<LoginBean>(
|
HttpResponse<LoginBean> response = await Api.login(userName, password);
|
||||||
Url.LOGIN,
|
|
||||||
{
|
|
||||||
"username": userName,
|
|
||||||
"password": password,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
userInfoViewModel.updateToken(response.bean?.token ?? "");
|
userInfoViewModel.updateToken(response.bean?.token ?? "");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
||||||
|
|
||||||
@JsonConversion()
|
@JsonConversion()
|
||||||
@@ -7,14 +9,14 @@ class TaskBean {
|
|||||||
String? schedule;
|
String? schedule;
|
||||||
bool? saved;
|
bool? saved;
|
||||||
String? sId;
|
String? sId;
|
||||||
int? created;
|
num? created;
|
||||||
int? status;
|
int? status;
|
||||||
String? timestamp;
|
String? timestamp;
|
||||||
int? isSystem;
|
int? isSystem;
|
||||||
int? isDisabled;
|
int? isDisabled;
|
||||||
String? logPath;
|
String? logPath;
|
||||||
int? isPinned;
|
int? isPinned;
|
||||||
int? lastExecutionTime;
|
num? lastExecutionTime;
|
||||||
int? lastRunningTime;
|
int? lastRunningTime;
|
||||||
String? pid;
|
String? pid;
|
||||||
|
|
||||||
@@ -36,21 +38,26 @@ class TaskBean {
|
|||||||
this.pid});
|
this.pid});
|
||||||
|
|
||||||
TaskBean.fromJson(Map<String, dynamic> json) {
|
TaskBean.fromJson(Map<String, dynamic> json) {
|
||||||
name = json['name'];
|
try {
|
||||||
command = json['command'];
|
name = json['name'].toString();
|
||||||
schedule = json['schedule'];
|
command = json['command'].toString();
|
||||||
|
schedule = json['schedule'].toString();
|
||||||
saved = json['saved'];
|
saved = json['saved'];
|
||||||
sId = json['_id'];
|
sId = json['_id'].toString();
|
||||||
created = json['created'];
|
created = json['created'];
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
timestamp = json['timestamp'];
|
timestamp = json['timestamp'].toString();
|
||||||
isSystem = json['isSystem'];
|
isSystem = json['isSystem'];
|
||||||
isDisabled = json['isDisabled'];
|
isDisabled = json['isDisabled'];
|
||||||
logPath = json['log_path'];
|
logPath = json['log_path'].toString();
|
||||||
isPinned = json['isPinned'];
|
isPinned = json['isPinned'];
|
||||||
lastExecutionTime = json['last_execution_time'];
|
lastExecutionTime = json['last_execution_time'];
|
||||||
lastRunningTime = json['last_running_time'];
|
lastRunningTime = json['last_running_time'];
|
||||||
pid = json['pid'];
|
pid = json['pid'].toString();
|
||||||
|
} catch (e) {
|
||||||
|
print(jsonEncode(json));
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||||
import 'package:qinglong_app/base/base_state_widget.dart';
|
import 'package:qinglong_app/base/base_state_widget.dart';
|
||||||
|
import 'package:qinglong_app/base/theme.dart';
|
||||||
|
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||||
import 'package:qinglong_app/module/task/task_viewmodel.dart';
|
import 'package:qinglong_app/module/task/task_viewmodel.dart';
|
||||||
|
|
||||||
class TaskPage extends StatefulWidget {
|
class TaskPage extends StatefulWidget {
|
||||||
@@ -19,18 +21,18 @@ class _TaskPageState extends State<TaskPage> {
|
|||||||
builder: (context, model, child) {
|
builder: (context, model, child) {
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
return Future.delayed(Duration(seconds: 1), () {});
|
return model.loadData(false);
|
||||||
},
|
},
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 15,
|
vertical: 15,
|
||||||
),
|
),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return TaskItemCell();
|
return TaskItemCell(model.list[index]);
|
||||||
},
|
},
|
||||||
itemCount: model.list.length,
|
itemCount: model.list.length,
|
||||||
separatorBuilder: (BuildContext context, int index) {
|
separatorBuilder: (BuildContext context, int index) {
|
||||||
return SizedBox(
|
return const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -45,11 +47,13 @@ class _TaskPageState extends State<TaskPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TaskItemCell extends StatelessWidget {
|
class TaskItemCell extends ConsumerWidget {
|
||||||
const TaskItemCell({Key? key}) : super(key: key);
|
final TaskBean bean;
|
||||||
|
|
||||||
|
const TaskItemCell(this.bean, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return Slidable(
|
return Slidable(
|
||||||
key: const ValueKey(0),
|
key: const ValueKey(0),
|
||||||
startActionPane: ActionPane(
|
startActionPane: ActionPane(
|
||||||
@@ -98,34 +102,49 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: const [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"东东农场",
|
bean.name ?? "",
|
||||||
|
maxLines: 1,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w500,
|
overflow: TextOverflow.ellipsis,
|
||||||
|
color: bean.isDisabled == 1 ? Color(0xffF85152) : ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
const SizedBox(
|
||||||
width: 5,
|
width: 5,
|
||||||
),
|
),
|
||||||
SizedBox(
|
bean.status == 1
|
||||||
|
? const SizedBox.shrink()
|
||||||
|
: const SizedBox(
|
||||||
width: 15,
|
width: 15,
|
||||||
height: 15,
|
height: 15,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Spacer(),
|
const Spacer(),
|
||||||
Text("2020/12/12 12:23"),
|
Text(
|
||||||
|
"${bean.lastRunningTime ?? "-"}",
|
||||||
|
maxLines: 1,
|
||||||
|
style: const TextStyle(
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
color: Color(0xff999999),
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 5,
|
height: 5,
|
||||||
),
|
),
|
||||||
const Text(
|
Text(
|
||||||
"12/12/12",
|
bean.schedule ?? "",
|
||||||
style: TextStyle(
|
maxLines: 1,
|
||||||
|
style: const TextStyle(
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
color: Color(0xff999999),
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,31 +1,37 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:qinglong_app/base/base_viewmodel.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/task/task_bean.dart';
|
||||||
|
|
||||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||||
|
|
||||||
class TaskViewModel extends BaseViewModel {
|
class TaskViewModel extends BaseViewModel {
|
||||||
List<String> list = [];
|
List<TaskBean> list = [];
|
||||||
|
|
||||||
void loadData() {
|
Future<void> loadData([isLoading = true]) async {
|
||||||
|
if (isLoading) {
|
||||||
loading(notify: true);
|
loading(notify: true);
|
||||||
|
}
|
||||||
|
|
||||||
Future.delayed(Duration(seconds: 2), () {
|
HttpResponse<List<TaskBean>> result = await Api.crons();
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
if (result.success && result.bean != null) {
|
||||||
list.add("sdfsf");
|
list.clear();
|
||||||
list.add("sdfsf");
|
list.addAll(result.bean!);
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
list.sort((a, b) {
|
||||||
list.add("sdfsf");
|
return a.isDisabled! - b.isDisabled!;
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
list.add("sdfsf");
|
|
||||||
success();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
list.sort((a, b) {
|
||||||
|
return a.status! - b.status!;
|
||||||
|
});
|
||||||
|
|
||||||
|
success();
|
||||||
|
} else {
|
||||||
|
list.clear();
|
||||||
|
failed(result.message, notify: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
lib/utils/extension.dart
Normal file
12
lib/utils/extension.dart
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
extension ContextExt on BuildContext {
|
||||||
|
T read<T>(ProviderBase<T> provider) {
|
||||||
|
return (this as WidgetRef).read<T>(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
T watch<T>(ProviderBase<T> provider) {
|
||||||
|
return (this as WidgetRef).watch<T>(provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,4 +16,7 @@ import 'package:qinglong_app/module/login/login_viewmodel.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
|
testWidgets("", (_){
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user