feat: 收藏夹新建/编辑
This commit is contained in:
@ -55,6 +55,22 @@ class _FavPageState extends State<FavPage> {
|
||||
tooltip: 'Ta的订阅',
|
||||
)
|
||||
: const SizedBox.shrink()),
|
||||
|
||||
// 新建收藏夹
|
||||
Obx(() => _favController.isOwner.value
|
||||
? IconButton(
|
||||
onPressed: () async {
|
||||
await Get.toNamed('/favEdit');
|
||||
_favController.hasMore.value = true;
|
||||
_favController.currentPage = 1;
|
||||
setState(() {
|
||||
_futureBuilderFuture = _favController.queryFavFolder();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.add_outlined),
|
||||
tooltip: '新建收藏夹',
|
||||
)
|
||||
: const SizedBox.shrink()),
|
||||
IconButton(
|
||||
onPressed: () => Get.toNamed(
|
||||
'/favSearch?searchType=1&mediaId=${_favController.favFolderData.value.list!.first.id}'),
|
||||
|
@ -115,4 +115,17 @@ class FavDetailController extends GetxController {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
onEditFavFolder() async {
|
||||
Get.toNamed(
|
||||
'/favEdit',
|
||||
arguments: {
|
||||
'mediaId': mediaId.toString(),
|
||||
'title': item!.title,
|
||||
'intro': item!.intro,
|
||||
'cover': item!.cover,
|
||||
'privacy': item!.attr,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,11 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
position: PopupMenuPosition.under,
|
||||
onSelected: (String type) {},
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
onTap: () => _favDetailController.onEditFavFolder(),
|
||||
value: 'edit',
|
||||
child: const Text('编辑收藏夹'),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
onTap: () => _favDetailController.onDelFavFolder(),
|
||||
value: 'pause',
|
||||
|
77
lib/pages/fav_edit/controller.dart
Normal file
77
lib/pages/fav_edit/controller.dart
Normal file
@ -0,0 +1,77 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/fav.dart';
|
||||
|
||||
class FavEditController extends GetxController {
|
||||
final GlobalKey formKey = GlobalKey<FormState>();
|
||||
final TextEditingController titleController = TextEditingController();
|
||||
final TextEditingController contentController = TextEditingController();
|
||||
|
||||
final FocusNode titleTextFieldNode = FocusNode();
|
||||
final FocusNode contentTextFieldNode = FocusNode();
|
||||
|
||||
// 默认新建
|
||||
RxString type = 'add'.obs;
|
||||
|
||||
String? mediaId;
|
||||
String cover = ''; // 封面
|
||||
String title = ''; // 名称
|
||||
String intro = ''; // 简介
|
||||
RxInt privacy = 0.obs; // 是否公开 0公开 1私密
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
var args = Get.arguments;
|
||||
if (args != null) {
|
||||
type.value = 'edit';
|
||||
mediaId = args['mediaId'];
|
||||
title = args['title'];
|
||||
intro = args['intro'];
|
||||
cover = args['cover'];
|
||||
privacy.value = args['privacy'];
|
||||
titleController.text = title;
|
||||
contentController.text = intro;
|
||||
}
|
||||
}
|
||||
|
||||
void onSubmit() async {
|
||||
// 表单验证
|
||||
if ((formKey.currentState as FormState).validate()) {
|
||||
if (type.value == 'edit') {
|
||||
await editFolder();
|
||||
} else {
|
||||
await addFolder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> editFolder() async {
|
||||
var res = await FavHttp.editFolder(
|
||||
title: title,
|
||||
intro: intro,
|
||||
mediaId: mediaId!,
|
||||
cover: cover,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('编辑成功');
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addFolder() async {
|
||||
var res = await FavHttp.addFolder(
|
||||
title: title,
|
||||
intro: intro,
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('新建成功');
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
4
lib/pages/fav_edit/index.dart
Normal file
4
lib/pages/fav_edit/index.dart
Normal file
@ -0,0 +1,4 @@
|
||||
library fav_edit;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
111
lib/pages/fav_edit/view.dart
Normal file
111
lib/pages/fav_edit/view.dart
Normal file
@ -0,0 +1,111 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
class FavEditPage extends StatefulWidget {
|
||||
const FavEditPage({super.key});
|
||||
|
||||
@override
|
||||
State<FavEditPage> createState() => _FavEditPageState();
|
||||
}
|
||||
|
||||
class _FavEditPageState extends State<FavEditPage> {
|
||||
final FavEditController _favEditController = Get.put(FavEditController());
|
||||
String title = '';
|
||||
String content = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
title: Obx(
|
||||
() => _favEditController.type.value == 'add'
|
||||
? Text(
|
||||
'新建收藏夹',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
)
|
||||
: Text(
|
||||
'编辑收藏夹',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
Obx(
|
||||
() => _favEditController.privacy.value == 0
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
_favEditController.privacy.value = 1;
|
||||
},
|
||||
icon: const Icon(Icons.lock_open_outlined))
|
||||
: IconButton(
|
||||
onPressed: () {
|
||||
_favEditController.privacy.value = 0;
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.lock_outlined,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _favEditController.onSubmit, child: const Text('保存')),
|
||||
const SizedBox(width: 14),
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _favEditController.formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.disabled,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 10, 14, 5),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Theme.of(context).dividerColor.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TextFormField(
|
||||
autofocus: true,
|
||||
controller: _favEditController.titleController,
|
||||
focusNode: _favEditController.titleTextFieldNode,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "收藏夹名称",
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
// 校验标题
|
||||
validator: (v) {
|
||||
return v!.trim().isNotEmpty ? null : "请输入收藏夹名称";
|
||||
},
|
||||
onChanged: (val) {
|
||||
_favEditController.title = val;
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 14, vertical: 5),
|
||||
child: TextFormField(
|
||||
controller: _favEditController.contentController,
|
||||
minLines: 1,
|
||||
maxLines: 5,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '输入收藏夹简介', border: InputBorder.none),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
onChanged: (val) {
|
||||
_favEditController.intro = val;
|
||||
},
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user