2024-07-09 13:23:38 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2024-07-09 14:39:44 +00:00
|
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
|
|
import 'package:solian/models/pagination.dart';
|
|
|
|
import 'package:solian/models/post.dart';
|
2024-07-23 10:09:41 +00:00
|
|
|
import 'package:solian/providers/content/posts.dart';
|
2024-07-12 08:19:54 +00:00
|
|
|
import 'package:solian/screens/home.dart';
|
2024-07-09 13:23:38 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-07-12 14:31:45 +00:00
|
|
|
import 'package:solian/widgets/app_bar_leading.dart';
|
2024-07-09 13:23:38 +00:00
|
|
|
import 'package:solian/widgets/app_bar_title.dart';
|
2024-07-09 14:39:44 +00:00
|
|
|
import 'package:solian/widgets/posts/post_action.dart';
|
|
|
|
import 'package:solian/widgets/posts/post_owned_list.dart';
|
2024-07-09 13:23:38 +00:00
|
|
|
|
2024-07-09 14:39:44 +00:00
|
|
|
class DraftBoxScreen extends StatefulWidget {
|
2024-07-09 13:23:38 +00:00
|
|
|
const DraftBoxScreen({super.key});
|
|
|
|
|
2024-07-09 14:39:44 +00:00
|
|
|
@override
|
|
|
|
State<DraftBoxScreen> createState() => _DraftBoxScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DraftBoxScreenState extends State<DraftBoxScreen> {
|
2024-07-23 10:09:41 +00:00
|
|
|
final PagingController<int, Post> _pagingController =
|
2024-07-09 14:39:44 +00:00
|
|
|
PagingController(firstPageKey: 0);
|
|
|
|
|
|
|
|
getPosts(int pageKey) async {
|
2024-07-23 10:09:41 +00:00
|
|
|
final PostProvider provider = Get.find();
|
2024-07-09 14:39:44 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-07-23 10:09:41 +00:00
|
|
|
final parsed = result.data?.map((e) => Post.fromJson(e)).toList();
|
2024-07-09 14:39:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-07-09 13:23:38 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2024-07-12 14:37:58 +00:00
|
|
|
leading: AppBarLeadingButton.adaptive(context),
|
2024-07-09 13:23:38 +00:00
|
|
|
title: AppBarTitle('draftBox'.tr),
|
|
|
|
centerTitle: false,
|
|
|
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
|
|
|
actions: [
|
|
|
|
FeedCreationButton(
|
2024-07-09 14:39:44 +00:00
|
|
|
hideDraftBox: true,
|
2024-07-09 13:23:38 +00:00
|
|
|
onCreated: () {},
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-07-09 14:39:44 +00:00
|
|
|
body: RefreshIndicator(
|
|
|
|
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
2024-07-23 10:09:41 +00:00
|
|
|
child: PagedListView<int, Post>(
|
2024-07-09 14:39:44 +00:00
|
|
|
pagingController: _pagingController,
|
|
|
|
builderDelegate: PagedChildBuilderDelegate(
|
|
|
|
itemBuilder: (context, item, index) {
|
2024-07-23 10:09:41 +00:00
|
|
|
return PostOwnedListEntry(
|
|
|
|
item: item,
|
|
|
|
onTap: () async {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => PostAction(
|
|
|
|
item: item,
|
|
|
|
noReact: true,
|
|
|
|
),
|
|
|
|
).then((value) {
|
|
|
|
if (value != null) _pagingController.refresh();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
).paddingOnly(left: 12, right: 12, bottom: 4);
|
2024-07-09 14:39:44 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-07-09 13:23:38 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-07-09 14:39:44 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_pagingController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2024-07-09 13:23:38 +00:00
|
|
|
}
|