add others

This commit is contained in:
jyuesong
2022-01-17 16:42:46 +08:00
parent 105d6172b6
commit ad141e4bd1
18 changed files with 291 additions and 128 deletions

View File

@@ -1,14 +1,14 @@
import 'package:drag_and_drop_lists/drag_and_drop_lists.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qinglong_app/base/base_state_widget.dart';
import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/common_dialog.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/ui/empty_widget.dart';
import 'package:qinglong_app/base/ui/menu.dart';
import 'package:qinglong_app/module/env/env_bean.dart';
import 'package:qinglong_app/module/env/env_viewmodel.dart';
import 'package:qinglong_app/utils/utils.dart';
class EnvPage extends StatefulWidget {
const EnvPage({Key? key}) : super(key: key);
@@ -18,29 +18,53 @@ class EnvPage extends StatefulWidget {
}
class _EnvPageState extends State<EnvPage> {
String _searchKey = "";
final TextEditingController _searchController = TextEditingController();
@override
Widget build(BuildContext context) {
return BaseStateWidget<EnvViewModel>(
builder: (ref, model, child) {
return RefreshIndicator(
color: Theme.of(context).primaryColor,
onRefresh: () async {
return model.loadData(false);
},
child: model.list.isEmpty
? const EmptyWidget()
: ListView.builder(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
itemBuilder: (context, index) {
EnvBean item = model.list[index];
List<EnvItemCell> list = [];
return EnvItemCell(item, ref);
for (var value in model.list) {
if (_searchController.text.isEmpty ||
(value.name?.contains(_searchController.text) ?? false) ||
(value.value?.contains(_searchController.text) ?? false) ||
(value.remarks?.contains(_searchController.text) ?? false)) {
list.add(EnvItemCell(value, ref,key: ValueKey(value.sId),));
}
}
return model.list.isEmpty
? const EmptyWidget()
: RefreshIndicator(
color: Theme.of(context).primaryColor,
onRefresh: () async {
return model.loadData(false);
},
child: ReorderableListView(
header: searchCell(ref),
onReorder: (int oldIndex, int newIndex) {
if (list.length != model.list.length) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
failDialog(context, "请先清空搜索关键词");
});
return;
}
setState(() {
//交换数据
if (newIndex > oldIndex) {
newIndex -= 1;
}
final EnvBean item = model.list.removeAt(oldIndex);
model.list.insert(newIndex, item);
model.update();
});
},
itemCount: model.list.length,
children: list,
),
);
);
},
model: envProvider,
onReady: (viewModel) {
@@ -48,6 +72,50 @@ class _EnvPageState extends State<EnvPage> {
},
);
}
Widget searchCell(WidgetRef context) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 10,
),
child: CupertinoSearchTextField(
onSubmitted: (value) {
setState(() {});
},
onSuffixTap: () {
_searchController.text = "";
setState(() {});
},
controller: _searchController,
borderRadius: BorderRadius.circular(
30,
),
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 5,
),
suffixInsets: const EdgeInsets.only(
top: 8,
bottom: 8,
right: 15,
),
prefixInsets: const EdgeInsets.only(
top: 10,
bottom: 6,
left: 15,
),
placeholderStyle: TextStyle(
fontSize: 14,
color: context.watch(themeProvider).themeColor.descColor(),
),
style: const TextStyle(
fontSize: 14,
),
placeholder: "搜索",
),
);
}
}
class EnvItemCell extends StatelessWidget {
@@ -58,51 +126,39 @@ class EnvItemCell extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoContextMenu(
actions: [
QLCupertinoContextMenuAction(
child: const Text("编辑"),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(Routes.route_AddTask, arguments: bean);
},
trailingIcon: CupertinoIcons.pencil_outline,
),
QLCupertinoContextMenuAction(
child: Text(bean.status! == 0 ? "禁用" : "启用"),
onPressed: () {
Navigator.of(context).pop();
enableEnv();
},
isDestructiveAction: true,
trailingIcon: bean.status! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
QLCupertinoContextMenuAction(
child: const Text("删除"),
onPressed: () {
Navigator.of(context).pop();
delEnv(context, ref);
},
isDestructiveAction: true,
trailingIcon: CupertinoIcons.delete,
),
],
previewBuilder: (context, anima, child) {
return IntrinsicWidth(
child: Material(
color: Colors.transparent,
child: Text(
bean.name ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: bean.status == 0 ? const Color(0xffF85152) : ref.watch(themeProvider).themeColor.taskTitleColor(),
fontSize: 18,
),
),
return Slidable(
key: ValueKey(bean.sId),
endActionPane: ActionPane(
motion: const ScrollMotion(),
extentRatio: 0.45,
children: [
SlidableAction(
backgroundColor: Colors.grey,
flex: 1,
onPressed: (_) {},
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(

View File

@@ -60,7 +60,7 @@ class EnvViewModel extends BaseViewModel {
HttpResponse<NullResponse> response = await Api.enableEnv(sId);
if (response.success) {
list.firstWhere((element) => element.sId == sId).status = 1;
list.firstWhere((element) => element.sId == sId).status = 0;
sortList();
success();
} else {
@@ -70,7 +70,7 @@ class EnvViewModel extends BaseViewModel {
HttpResponse<NullResponse> response = await Api.disableEnv(sId);
if (response.success) {
list.firstWhere((element) => element.sId == sId).status = 0;
list.firstWhere((element) => element.sId == sId).status = 1;
sortList();
success();
} else {
@@ -78,4 +78,7 @@ class EnvViewModel extends BaseViewModel {
}
}
}
void update(){
// update
}
}

View File

@@ -89,12 +89,20 @@ class _HomePageState extends ConsumerState<HomePage> {
body: IndexedStack(
index: _index,
children: [
const TaskPage(),
const EnvPage(),
ConfigPage(
key: configKey,
const Positioned.fill(
child: TaskPage(),
),
const Positioned.fill(
child: EnvPage(),
),
Positioned.fill(
child: ConfigPage(
key: configKey,
),
),
const Positioned.fill(
child: OtherPage(),
),
const OtherPage(),
],
),
bottomNavigationBar: BottomNavigationBar(

View File

@@ -1,8 +1,8 @@
import 'package:dio_log/dio_log.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/common_dialog.dart';
import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import 'package:qinglong_app/main.dart';
@@ -24,6 +24,7 @@ class _LoginPageState extends State<LoginPage> {
@override
void initState() {
super.initState();
getIt<UserInfoViewModel>().updateToken("");
}
@override
@@ -197,6 +198,7 @@ class _LoginPageState extends State<LoginPage> {
),
),
onPressed: () {
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>().updateHost(_hostController.text);
model.login(_userNameController.text, _passwordController.text);
@@ -207,7 +209,6 @@ class _LoginPageState extends State<LoginPage> {
),
),
),
],
),
);

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:qinglong_app/base/ql_app_bar.dart';
class OtherPage extends StatefulWidget {
const OtherPage({Key? key}) : super(key: key);
@@ -10,6 +11,14 @@ class OtherPage extends StatefulWidget {
class _OtherPageState extends State<OtherPage> {
@override
Widget build(BuildContext context) {
return Scaffold();
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
],
),
);
}
}

View File

@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/base_state_widget.dart';
import 'package:qinglong_app/base/routes.dart';
@@ -32,42 +33,50 @@ class _TaskPageState extends State<TaskPage> {
Widget build(BuildContext context) {
return BaseStateWidget<TaskViewModel>(
builder: (ref, model, child) {
return DefaultTabController(
length: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TabBar(
tabs: const [
Tab(
text: "全部",
),
Tab(
text: "正在运行",
),
Tab(
text: "已禁用",
),
],
isScrollable: true,
indicator: AbsUnderlineTabIndicator(
wantWidth: 20,
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2,
)),
),
Expanded(
child: TabBarView(
return Column(
mainAxisSize: MainAxisSize.max,
children: [
searchCell(ref),
Expanded(
child: DefaultTabController(
length: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
body(model, model.list, ref),
body(model, model.running, ref),
body(model, model.disabled, ref),
TabBar(
tabs: const [
Tab(
text: "全部",
),
Tab(
text: "正在运行",
),
Tab(
text: "已禁用",
),
],
isScrollable: true,
indicator: AbsUnderlineTabIndicator(
wantWidth: 20,
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2,
)),
),
Expanded(
child: TabBarView(
children: [
body(model, model.list, ref),
body(model, model.running, ref),
body(model, model.disabled, ref),
],
),
),
],
),
),
],
),
),
],
);
},
model: taskProvider,
@@ -103,36 +112,43 @@ class _TaskPageState extends State<TaskPage> {
Widget searchCell(WidgetRef context) {
return Container(
color: context.watch(themeProvider).themeColor.searchBarBg(),
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 10,
),
child: CupertinoSearchTextField(
onSubmitted: (value) {
setState(() {
_searchKey = value;
});
setState(() {});
},
onSuffixTap: () {
_searchController.text = "";
setState(() {
_searchKey = "";
});
setState(() {});
},
controller: _searchController,
borderRadius: BorderRadius.circular(
30,
),
padding: const EdgeInsets.symmetric(
horizontal: 15,
horizontal: 5,
vertical: 5,
),
suffixInsets: const EdgeInsets.only(
top: 8,
bottom: 8,
right: 15,
),
prefixInsets: const EdgeInsets.only(
top: 10,
bottom: 6,
left: 15,
),
placeholderStyle: TextStyle(
fontSize: 14,
color: context.watch(themeProvider).themeColor.descColor(),
),
style: const TextStyle(
fontSize: 14,
),
placeholder: "搜索",
),
);
@@ -364,7 +380,10 @@ class TaskItemCell extends StatelessWidget {
content: InTimeLogPage(bean.sId!, bean.status == 0),
actions: [
CupertinoDialogAction(
child: const Text("知道了"),
child: Text(
"知道了",
style: TextStyle(color: Theme.of(context).primaryColor),
),
onPressed: () {
Navigator.of(context).pop();
},

View File

@@ -48,7 +48,7 @@ class TaskViewModel extends BaseViewModel {
list.firstWhere((element) => element.sId == cron).status = 0;
notifyListeners();
} else {
failed(result.message, notify: true);
failToast(result.message, notify: true);
}
}
@@ -58,7 +58,7 @@ class TaskViewModel extends BaseViewModel {
list.firstWhere((element) => element.sId == cron).status = 1;
notifyListeners();
} else {
failed(result.message, notify: true);
failToast(result.message, notify: true);
}
}
@@ -68,7 +68,7 @@ class TaskViewModel extends BaseViewModel {
list.removeWhere((element) => element.sId == id);
notifyListeners();
} else {
failed(result.message, notify: true);
failToast(result.message, notify: true);
}
}