mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add detail page
This commit is contained in:
63
lib/module/task/task_detail/task_detail_bean.dart
Normal file
63
lib/module/task/task_detail/task_detail_bean.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
||||
|
||||
@JsonConversion()
|
||||
class TaskDetailBean {
|
||||
String? name;
|
||||
String? command;
|
||||
String? schedule;
|
||||
bool? saved;
|
||||
String? sId;
|
||||
int? created;
|
||||
int? status;
|
||||
String? timestamp;
|
||||
int? isSystem;
|
||||
int? isDisabled;
|
||||
String? logPath;
|
||||
int? isPinned;
|
||||
|
||||
TaskDetailBean(
|
||||
{this.name,
|
||||
this.command,
|
||||
this.schedule,
|
||||
this.saved,
|
||||
this.sId,
|
||||
this.created,
|
||||
this.status,
|
||||
this.timestamp,
|
||||
this.isSystem,
|
||||
this.isDisabled,
|
||||
this.logPath,
|
||||
this.isPinned});
|
||||
|
||||
TaskDetailBean.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'];
|
||||
command = json['command'];
|
||||
schedule = json['schedule'];
|
||||
saved = json['saved'];
|
||||
sId = json['_id'];
|
||||
created = json['created'];
|
||||
status = json['status'];
|
||||
timestamp = json['timestamp'];
|
||||
isSystem = json['isSystem'];
|
||||
isDisabled = json['isDisabled'];
|
||||
logPath = json['log_path'];
|
||||
isPinned = json['isPinned'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['name'] = this.name;
|
||||
data['command'] = this.command;
|
||||
data['schedule'] = this.schedule;
|
||||
data['saved'] = this.saved;
|
||||
data['_id'] = this.sId;
|
||||
data['created'] = this.created;
|
||||
data['status'] = this.status;
|
||||
data['timestamp'] = this.timestamp;
|
||||
data['isSystem'] = this.isSystem;
|
||||
data['isDisabled'] = this.isDisabled;
|
||||
data['log_path'] = this.logPath;
|
||||
data['isPinned'] = this.isPinned;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
36
lib/module/task/task_detail/task_detail_page.dart
Normal file
36
lib/module/task/task_detail/task_detail_page.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_state_widget.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_detail/task_detail_viewmodel.dart';
|
||||
|
||||
class TaskDetailPage extends ConsumerStatefulWidget {
|
||||
final TaskBean taskBean;
|
||||
|
||||
const TaskDetailPage(this.taskBean, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TaskDetailPageState createState() => _TaskDetailPageState();
|
||||
}
|
||||
|
||||
class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: QlAppBar(
|
||||
canBack: true,
|
||||
title: widget.taskBean.name ?? "",
|
||||
),
|
||||
body: BaseStateWidget<TaskDetailViewModel>(
|
||||
model: taskDetailProvider,
|
||||
builder: (WidgetRef context, TaskDetailViewModel value, Widget? child) {
|
||||
return Container();
|
||||
},
|
||||
onReady: (model){
|
||||
model.loadDetail(widget.taskBean.sId!);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
lib/module/task/task_detail/task_detail_viewmodel.dart
Normal file
28
lib/module/task/task_detail/task_detail_viewmodel.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
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/task/task_detail/task_detail_bean.dart';
|
||||
|
||||
var taskDetailProvider = AutoDisposeChangeNotifierProvider<TaskDetailViewModel>((ref) {
|
||||
return TaskDetailViewModel();
|
||||
});
|
||||
|
||||
class TaskDetailViewModel extends BaseViewModel {
|
||||
TaskDetailBean? bean;
|
||||
|
||||
TaskDetailViewModel();
|
||||
|
||||
Future<void> loadDetail(String id) async {
|
||||
loading(notify: true);
|
||||
|
||||
HttpResponse<TaskDetailBean> response = await Api.taskDetail(id);
|
||||
|
||||
if (response.success) {
|
||||
bean = response.bean;
|
||||
success();
|
||||
} else {
|
||||
failed(response.message, notify: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user