✨ Support new feed API
✨ Able to add tag onto post
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
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/auth.dart';
|
||||
import 'package:solian/providers/content/post.dart';
|
||||
import 'package:solian/router.dart';
|
||||
@@ -10,7 +10,7 @@ import 'package:solian/screens/account/notification.dart';
|
||||
import 'package:solian/theme.dart';
|
||||
import 'package:solian/widgets/app_bar_title.dart';
|
||||
import 'package:solian/widgets/current_state_action.dart';
|
||||
import 'package:solian/widgets/posts/post_list.dart';
|
||||
import 'package:solian/widgets/posts/feed_list.dart';
|
||||
|
||||
class FeedScreen extends StatefulWidget {
|
||||
const FeedScreen({super.key});
|
||||
@@ -20,7 +20,7 @@ class FeedScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FeedScreenState extends State<FeedScreen> {
|
||||
final PagingController<int, Post> _pagingController =
|
||||
final PagingController<int, FeedRecord> _pagingController =
|
||||
PagingController(firstPageKey: 0);
|
||||
|
||||
getPosts(int pageKey) async {
|
||||
@@ -28,14 +28,14 @@ class _FeedScreenState extends State<FeedScreen> {
|
||||
|
||||
Response resp;
|
||||
try {
|
||||
resp = await provider.listPost(pageKey);
|
||||
resp = await provider.listFeed(pageKey);
|
||||
} catch (e) {
|
||||
_pagingController.error = e;
|
||||
return;
|
||||
}
|
||||
|
||||
final PaginationResult result = PaginationResult.fromJson(resp.body);
|
||||
final parsed = result.data?.map((e) => Post.fromJson(e)).toList();
|
||||
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) {
|
||||
@@ -78,7 +78,7 @@ class _FeedScreenState extends State<FeedScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
PostListWidget(controller: _pagingController),
|
||||
FeedListWidget(controller: _pagingController),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -104,7 +104,7 @@ class FeedCreationButton extends StatelessWidget {
|
||||
icon: const Icon(Icons.add_circle),
|
||||
onPressed: () {
|
||||
AppRouter.instance.pushNamed('postPublishing').then((val) {
|
||||
if (val == true && onCreated != null) {
|
||||
if (val != null && onCreated != null) {
|
||||
onCreated!();
|
||||
}
|
||||
});
|
||||
|
@@ -12,7 +12,9 @@ import 'package:solian/widgets/account/account_avatar.dart';
|
||||
import 'package:solian/widgets/app_bar_title.dart';
|
||||
import 'package:solian/widgets/attachments/attachment_publish.dart';
|
||||
import 'package:solian/widgets/posts/post_item.dart';
|
||||
import 'package:solian/widgets/posts/tags_field.dart';
|
||||
import 'package:solian/widgets/prev_page.dart';
|
||||
import 'package:textfield_tags/textfield_tags.dart';
|
||||
|
||||
class PostPublishingArguments {
|
||||
final Post? edit;
|
||||
@@ -43,6 +45,7 @@ class PostPublishingScreen extends StatefulWidget {
|
||||
|
||||
class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
final _contentController = TextEditingController();
|
||||
final _tagsController = StringTagController();
|
||||
|
||||
bool _isBusy = false;
|
||||
|
||||
@@ -70,6 +73,8 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
|
||||
final payload = {
|
||||
'content': _contentController.value.text,
|
||||
'tags': _tagsController.getTags?.map((x) => {'alias': x}).toList() ??
|
||||
List.empty(),
|
||||
'attachments': _attachments,
|
||||
if (widget.edit != null) 'alias': widget.edit!.alias,
|
||||
if (widget.reply != null) 'reply_to': widget.reply!.id,
|
||||
@@ -242,6 +247,10 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
right: 0,
|
||||
child: Column(
|
||||
children: [
|
||||
TagsField(
|
||||
tagsController: _tagsController,
|
||||
hintText: 'postTagsPlaceholder'.tr,
|
||||
),
|
||||
const Divider(thickness: 0.3, height: 0.3),
|
||||
SizedBox(
|
||||
height: 56,
|
||||
@@ -266,4 +275,11 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_contentController.dispose();
|
||||
_tagsController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user