add detail page

This commit is contained in:
jyuesong
2022-01-13 14:10:29 +08:00
parent 6acf427fb6
commit 80670821cd
17 changed files with 502 additions and 42 deletions

View 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;
}
}

View 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!);
},
),
);
}
}

View 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);
}
}
}