🐛 Fix post won't refresh after post

This commit is contained in:
LittleSheep 2024-08-02 01:00:31 +08:00
parent a0a3a8d182
commit cccb3d5c16
5 changed files with 43 additions and 45 deletions

View File

@ -100,6 +100,7 @@ abstract class AppRouter {
reply: arguments?.reply,
repost: arguments?.repost,
realm: arguments?.realm,
postListController: arguments?.postListController,
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
);
},

View File

@ -4,6 +4,7 @@ import 'package:solian/controllers/post_list_controller.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart';
import 'package:solian/screens/posts/post_editor.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/current_state_action.dart';
@ -51,7 +52,9 @@ class _HomeScreenState extends State<HomeScreen>
useRootNavigator: true,
isScrollControlled: true,
context: context,
builder: (context) => const PostCreatePopup(),
builder: (context) => PostCreatePopup(
controller: _postController,
),
);
},
),
@ -118,12 +121,12 @@ class _HomeScreenState extends State<HomeScreen>
class PostCreatePopup extends StatelessWidget {
final bool hideDraftBox;
final Function? onCreated;
final PostListController controller;
const PostCreatePopup({
super.key,
this.hideDraftBox = false,
this.onCreated,
required this.controller,
});
@override
@ -140,11 +143,13 @@ class PostCreatePopup extends StatelessWidget {
label: 'postEditorModeStory'.tr,
onTap: () {
Navigator.pop(context);
AppRouter.instance.pushNamed('postEditor', queryParameters: {
'mode': 0.toString(),
}).then((val) {
if (val != null && onCreated != null) onCreated!();
});
AppRouter.instance.pushNamed(
'postEditor',
extra: PostPublishArguments(postListController: controller),
queryParameters: {
'mode': 0.toString(),
},
);
},
),
(
@ -152,11 +157,13 @@ class PostCreatePopup extends StatelessWidget {
label: 'postEditorModeArticle'.tr,
onTap: () {
Navigator.pop(context);
AppRouter.instance.pushNamed('postEditor', queryParameters: {
'mode': 1.toString(),
}).then((val) {
if (val != null && onCreated != null) onCreated!();
});
AppRouter.instance.pushNamed(
'postEditor',
extra: PostPublishArguments(postListController: controller),
queryParameters: {
'mode': 1.toString(),
},
);
},
),
(

View File

@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:markdown_toolbar/markdown_toolbar.dart';
import 'package:solian/controllers/post_editor_controller.dart';
import 'package:solian/controllers/post_list_controller.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/post.dart';
import 'package:solian/models/realm.dart';
@ -22,8 +23,15 @@ class PostPublishArguments {
final Post? reply;
final Post? repost;
final Realm? realm;
final PostListController? postListController;
PostPublishArguments({this.edit, this.reply, this.repost, this.realm});
PostPublishArguments({
this.edit,
this.reply,
this.repost,
this.realm,
this.postListController,
});
}
class PostPublishScreen extends StatefulWidget {
@ -31,6 +39,7 @@ class PostPublishScreen extends StatefulWidget {
final Post? reply;
final Post? repost;
final Realm? realm;
final PostListController? postListController;
final int mode;
const PostPublishScreen({
@ -39,6 +48,7 @@ class PostPublishScreen extends StatefulWidget {
this.reply,
this.repost,
this.realm,
this.postListController,
required this.mode,
});
@ -85,6 +95,9 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
context.showErrorDialog(resp.bodyString);
} else {
_editorController.localClear();
if (widget.postListController != null) {
widget.postListController!.reloadAllOver();
}
AppRouter.instance.pop(resp.body);
}

View File

@ -26,7 +26,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
final List<Realm> _realms = List.empty(growable: true);
getRealms() async {
_getRealms() async {
final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return;
@ -48,7 +48,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
@override
void initState() {
super.initState();
getRealms();
_getRealms();
}
@override
@ -71,7 +71,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
onPressed: () {
AppRouter.instance.pushNamed('realmOrganizing').then(
(value) {
if (value != null) getRealms();
if (value != null) _getRealms();
},
);
},
@ -84,7 +84,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
body: Obx(() {
if (auth.isAuthorized.isFalse) {
return SigninRequiredOverlay(
onSignedIn: () => getRealms(),
onSignedIn: () => _getRealms(),
);
}
@ -94,12 +94,12 @@ class _RealmListScreenState extends State<RealmListScreen> {
Expanded(
child: CenteredContainer(
child: RefreshIndicator(
onRefresh: () => getRealms(),
onRefresh: () => _getRealms(),
child: ListView.builder(
itemCount: _realms.length,
itemBuilder: (context, index) {
final element = _realms[index];
return buildRealm(element);
return _buildEntry(element);
},
),
),
@ -112,7 +112,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
);
}
Widget buildRealm(Realm element) {
Widget _buildEntry(Realm element) {
return Card(
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(8)),

View File

@ -12,7 +12,6 @@ import 'package:solian/providers/content/posts.dart';
import 'package:solian/providers/content/realm.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/screens/posts/post_editor.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_leading.dart';
import 'package:solian/widgets/channel/channel_list.dart';
@ -136,6 +135,7 @@ class _RealmViewScreenState extends State<RealmViewScreen> {
}
return TabBarView(
physics: const NeverScrollableScrollPhysics(),
children: [
RealmPostListWidget(realm: _realm!),
RealmChannelListWidget(
@ -189,7 +189,6 @@ class _RealmPostListWidgetState extends State<RealmPostListWidget> {
@override
void initState() {
super.initState();
_pagingController.addPageRequestListener(getPosts);
}
@ -199,28 +198,6 @@ class _RealmPostListWidgetState extends State<RealmPostListWidget> {
onRefresh: () => Future.sync(() => _pagingController.refresh()),
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: ListTile(
leading: const Icon(Icons.post_add),
contentPadding: const EdgeInsets.only(left: 24, right: 8),
tileColor: Theme.of(context).colorScheme.surfaceContainer,
title: Text('postNew'.tr),
subtitle: Text(
'postNewInRealmHint'
.trParams({'realm': '#${widget.realm.alias}'}),
),
onTap: () {
AppRouter.instance
.pushNamed(
'postEditor',
extra: PostPublishArguments(realm: widget.realm),
)
.then((value) {
if (value != null) _pagingController.refresh();
});
},
),
),
PostListWidget(controller: _pagingController),
],
),