优化任务列表,环境变量

This commit is contained in:
jyuesong
2022-05-30 13:04:33 +08:00
parent 2c64038fda
commit 578bb926fa
5 changed files with 383 additions and 327 deletions

View File

@@ -23,6 +23,14 @@ class EnvPage extends StatefulWidget {
class _EnvPageState extends State<EnvPage> {
final TextEditingController _searchController = TextEditingController();
@override
void initState() {
super.initState();
_searchController.addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return BaseStateWidget<EnvViewModel>(
@@ -37,7 +45,7 @@ class _EnvPageState extends State<EnvPage> {
(value.remarks?.contains(_searchController.text) ?? false)) {
list.add(EnvItemCell(
value,
i + 1,
i,
ref,
key: ValueKey(value.sId),
));
@@ -51,32 +59,34 @@ class _EnvPageState extends State<EnvPage> {
onRefresh: () async {
return model.loadData(false);
},
child: ReorderableListView(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
header: searchCell(ref),
onReorder: (int oldIndex, int newIndex) {
if (list.length != model.list.length) {
"请先清空搜索关键词".toast();
return;
}
setState(() {
//交换数据
if (newIndex > oldIndex) {
newIndex -= 1;
child: SlidableAutoCloseBehavior(
child: ReorderableListView(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
header: searchCell(ref),
onReorder: (int oldIndex, int newIndex) {
if (list.length != model.list.length) {
"请先清空搜索关键词".toast();
return;
}
final EnvBean item = model.list.removeAt(oldIndex);
model.list.insert(newIndex, item);
model.update(item.sId ?? "", newIndex, oldIndex);
});
},
children: list,
setState(() {
//交换数据
if (newIndex > oldIndex) {
newIndex -= 1;
}
final EnvBean item = model.list.removeAt(oldIndex);
model.list.insert(newIndex, item);
model.update(item.sId ?? "", newIndex, oldIndex);
});
},
children: list,
),
),
);
},
model: envProvider,
onReady: (viewModel) {
viewModel.loadData();
viewModel.loadData(context);
},
);
}
@@ -133,185 +143,181 @@ class EnvItemCell extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(Routes.routeEnvDetail, arguments: bean);
},
child: ColoredBox(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: Slidable(
key: ValueKey(bean.sId),
endActionPane: ActionPane(
motion: const ScrollMotion(),
extentRatio: 0.45,
return ColoredBox(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: Slidable(
key: ValueKey(bean.sId),
endActionPane: ActionPane(
motion: const StretchMotion(),
extentRatio: 0.5,
children: [
SlidableAction(
backgroundColor: const Color(0xff5D5E70),
onPressed: (_) {
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.pencil_outline,
),
SlidableAction(
backgroundColor: const Color(0xffA356D6),
onPressed: (_) {
enableEnv(context);
},
foregroundColor: Colors.white,
icon: bean.status == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: const Color(0xffEA4D3E),
onPressed: (_) {
delEnv(context, ref);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SlidableAction(
backgroundColor: Colors.grey,
flex: 1,
onPressed: (_) {
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.pencil_outline,
),
SlidableAction(
backgroundColor: Colors.orange,
flex: 1,
onPressed: (_) {
enableEnv();
},
foregroundColor: Colors.white,
icon: bean.status == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: Colors.red,
flex: 1,
onPressed: (_) {
delEnv(context, ref);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 8,
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
Material(
color: Colors.transparent,
child: Text(
bean.name ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 18,
Material(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: InkWell(
onTap: () {
Navigator.of(context).pushNamed(Routes.routeEnvDetail, arguments: bean);
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 8,
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 18,
color: Color(0xffEA4D3E),
)
: Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
),
child: Text(
"${getIndexByIndex(context, index)}",
style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12),
),
),
const SizedBox(
width: 5,
),
Material(
color: Colors.transparent,
child: Text(
bean.name ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 16,
),
),
),
),
],
),
),
const SizedBox(
width: 5,
),
Material(
color: Colors.transparent,
child: Text(
Utils.formatGMTTime(bean.timestamp ?? ""),
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
),
child: Text(
"$index",
style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12),
const SizedBox(
width: 5,
),
Expanded(
child: Visibility(
visible: bean.remarks != null && bean.remarks!.isNotEmpty,
child: Material(
color: Colors.transparent,
child: Text(
"(${bean.remarks})",
maxLines: 1,
style: TextStyle(
height: 1,
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
),
),
],
),
),
const SizedBox(
width: 5,
),
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 12,
color: Colors.red,
)
: const SizedBox.shrink(),
const SizedBox(
width: 5,
width: 15,
),
Material(
color: Colors.transparent,
child: Text(
bean.remarks ?? "-",
Utils.formatGMTTime(bean.timestamp ?? ""),
maxLines: 1,
style: TextStyle(
height: 1,
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
const Spacer(),
],
),
),
const SizedBox(
height: 8,
),
Material(
color: Colors.transparent,
child: Text(
bean.value ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
const SizedBox(
height: 15,
),
Material(
color: Colors.transparent,
child: Text(
bean.value ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
),
],
],
),
),
),
const Divider(
height: 1,
indent: 15,
),
],
),
),
const Divider(
height: 1,
indent: 15,
),
],
),
),
),
);
}
void enableEnv() {
void enableEnv(BuildContext context) {
ref.read(envProvider).enableEnv(bean.sId!, bean.status!);
}
void delEnv(BuildContext context, WidgetRef ref) {
showCupertinoDialog(
useRootNavigator: false,
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text("确认删除"),
@@ -344,4 +350,17 @@ class EnvItemCell extends StatelessWidget {
),
);
}
int getIndexByIndex(BuildContext context, int index) {
var list = ref.watch(envProvider.notifier).list;
int result = 0;
for (int i = 0; i <= index; i++) {
if (list.length > index && list[i].status == 0) {
result++;
}
}
return result;
}
}

View File

@@ -1,3 +1,4 @@
/// @author NewTab
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
@@ -11,6 +12,98 @@ class SystemBean {
version = json['version'];
}
//2.12.2 以及以上版本,日志从dirs换成了data
bool isUpperVersion2_12_2() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) >= 021202) {
return true;
}
return false;
} catch (e) {
return false;
}
}
//2.13.0 以及以上版本日志详情接口参数有变化
bool isUpperVersion2_13_0() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) >= 021300) {
return true;
}
return false;
} catch (e) {
return false;
}
}
// 2.10.13以上版本,针对任务,环境变量编辑做了修改
bool isUpperVersion() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) > 021013) {
return true;
}
return false;
} catch (e) {
return false;
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['version'] = this.version;
@@ -20,4 +113,4 @@ class SystemBean {
static SystemBean jsonConversion(Map<String, dynamic> json) {
return SystemBean.fromJson(json);
}
}
}