Draft box

This commit is contained in:
2024-07-09 22:39:44 +08:00
parent a0fe3f918e
commit fa600d6c69
21 changed files with 914 additions and 676 deletions

View File

@@ -1,13 +1,59 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/feed.dart';
import 'package:solian/models/pagination.dart';
import 'package:solian/models/post.dart';
import 'package:solian/providers/content/feed.dart';
import 'package:solian/screens/feed.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/posts/post_action.dart';
import 'package:solian/widgets/posts/post_owned_list.dart';
import 'package:solian/widgets/prev_page.dart';
class DraftBoxScreen extends StatelessWidget {
class DraftBoxScreen extends StatefulWidget {
const DraftBoxScreen({super.key});
@override
State<DraftBoxScreen> createState() => _DraftBoxScreenState();
}
class _DraftBoxScreenState extends State<DraftBoxScreen> {
final PagingController<int, FeedRecord> _pagingController =
PagingController(firstPageKey: 0);
getPosts(int pageKey) async {
final FeedProvider provider = Get.find();
Response resp;
try {
resp = await provider.listDraft(pageKey);
} catch (e) {
_pagingController.error = e;
return;
}
final PaginationResult result = PaginationResult.fromJson(resp.body);
if (result.count == 0) {
_pagingController.appendLastPage([]);
return;
}
final parsed = result.data?.map((e) => FeedRecord.fromJson(e)).toList();
if (parsed != null && parsed.length >= 10) {
_pagingController.appendPage(parsed, pageKey + parsed.length);
} else if (parsed != null) {
_pagingController.appendLastPage(parsed);
}
}
@override
void initState() {
super.initState();
_pagingController.addPageRequestListener(getPosts);
}
@override
Widget build(BuildContext context) {
return Material(
@@ -20,6 +66,7 @@ class DraftBoxScreen extends StatelessWidget {
leading: const PrevPageButton(),
actions: [
FeedCreationButton(
hideDraftBox: true,
onCreated: () {},
),
SizedBox(
@@ -27,7 +74,44 @@ class DraftBoxScreen extends StatelessWidget {
),
],
),
body: RefreshIndicator(
onRefresh: () => Future.sync(() => _pagingController.refresh()),
child: PagedListView<int, FeedRecord>(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate(
itemBuilder: (context, item, index) {
switch (item.type) {
case 'post':
final data = Post.fromJson(item.data);
return PostOwnedListEntry(
item: data,
onTap: () async {
showModalBottomSheet(
useRootNavigator: true,
context: context,
builder: (context) => PostAction(
item: data,
noReact: true,
),
).then((value) {
if (value != null) _pagingController.refresh();
});
},
).paddingOnly(left: 12, right: 12, bottom: 4);
default:
return const SizedBox();
}
},
),
),
),
),
);
}
@override
void dispose() {
_pagingController.dispose();
super.dispose();
}
}

View File

@@ -3,8 +3,8 @@ import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/feed.dart';
import 'package:solian/models/pagination.dart';
import 'package:solian/providers/content/post.dart';
import 'package:solian/widgets/posts/feed_list.dart';
import 'package:solian/providers/content/feed.dart';
import 'package:solian/widgets/feed/feed_list.dart';
class FeedSearchScreen extends StatefulWidget {
final String? tag;
@@ -21,7 +21,7 @@ class _FeedSearchScreenState extends State<FeedSearchScreen> {
PagingController(firstPageKey: 0);
getPosts(int pageKey) async {
final PostProvider provider = Get.find();
final FeedProvider provider = Get.find();
Response resp;
try {
@@ -68,7 +68,8 @@ class _FeedSearchScreenState extends State<FeedSearchScreen> {
ListTile(
leading: const Icon(Icons.category),
tileColor: Theme.of(context).colorScheme.surfaceContainer,
title: Text('feedSearchWithCategory'.trParams({'key': widget.category!})),
title: Text('feedSearchWithCategory'
.trParams({'key': widget.category!})),
),
Expanded(
child: RefreshIndicator(
@@ -85,4 +86,10 @@ class _FeedSearchScreenState extends State<FeedSearchScreen> {
),
);
}
@override
void dispose() {
_pagingController.dispose();
super.dispose();
}
}