🐛 Fix post won't refresh after post
This commit is contained in:
parent
a0a3a8d182
commit
cccb3d5c16
@ -100,6 +100,7 @@ abstract class AppRouter {
|
|||||||
reply: arguments?.reply,
|
reply: arguments?.reply,
|
||||||
repost: arguments?.repost,
|
repost: arguments?.repost,
|
||||||
realm: arguments?.realm,
|
realm: arguments?.realm,
|
||||||
|
postListController: arguments?.postListController,
|
||||||
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
|
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,7 @@ import 'package:solian/controllers/post_list_controller.dart';
|
|||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.dart';
|
||||||
import 'package:solian/router.dart';
|
import 'package:solian/router.dart';
|
||||||
import 'package:solian/screens/account/notification.dart';
|
import 'package:solian/screens/account/notification.dart';
|
||||||
|
import 'package:solian/screens/posts/post_editor.dart';
|
||||||
import 'package:solian/theme.dart';
|
import 'package:solian/theme.dart';
|
||||||
import 'package:solian/widgets/app_bar_title.dart';
|
import 'package:solian/widgets/app_bar_title.dart';
|
||||||
import 'package:solian/widgets/current_state_action.dart';
|
import 'package:solian/widgets/current_state_action.dart';
|
||||||
@ -51,7 +52,9 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => const PostCreatePopup(),
|
builder: (context) => PostCreatePopup(
|
||||||
|
controller: _postController,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -118,12 +121,12 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
|
|
||||||
class PostCreatePopup extends StatelessWidget {
|
class PostCreatePopup extends StatelessWidget {
|
||||||
final bool hideDraftBox;
|
final bool hideDraftBox;
|
||||||
final Function? onCreated;
|
final PostListController controller;
|
||||||
|
|
||||||
const PostCreatePopup({
|
const PostCreatePopup({
|
||||||
super.key,
|
super.key,
|
||||||
this.hideDraftBox = false,
|
this.hideDraftBox = false,
|
||||||
this.onCreated,
|
required this.controller,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -140,11 +143,13 @@ class PostCreatePopup extends StatelessWidget {
|
|||||||
label: 'postEditorModeStory'.tr,
|
label: 'postEditorModeStory'.tr,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
AppRouter.instance.pushNamed('postEditor', queryParameters: {
|
AppRouter.instance.pushNamed(
|
||||||
'mode': 0.toString(),
|
'postEditor',
|
||||||
}).then((val) {
|
extra: PostPublishArguments(postListController: controller),
|
||||||
if (val != null && onCreated != null) onCreated!();
|
queryParameters: {
|
||||||
});
|
'mode': 0.toString(),
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -152,11 +157,13 @@ class PostCreatePopup extends StatelessWidget {
|
|||||||
label: 'postEditorModeArticle'.tr,
|
label: 'postEditorModeArticle'.tr,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
AppRouter.instance.pushNamed('postEditor', queryParameters: {
|
AppRouter.instance.pushNamed(
|
||||||
'mode': 1.toString(),
|
'postEditor',
|
||||||
}).then((val) {
|
extra: PostPublishArguments(postListController: controller),
|
||||||
if (val != null && onCreated != null) onCreated!();
|
queryParameters: {
|
||||||
});
|
'mode': 1.toString(),
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:markdown_toolbar/markdown_toolbar.dart';
|
import 'package:markdown_toolbar/markdown_toolbar.dart';
|
||||||
import 'package:solian/controllers/post_editor_controller.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/exts.dart';
|
||||||
import 'package:solian/models/post.dart';
|
import 'package:solian/models/post.dart';
|
||||||
import 'package:solian/models/realm.dart';
|
import 'package:solian/models/realm.dart';
|
||||||
@ -22,8 +23,15 @@ class PostPublishArguments {
|
|||||||
final Post? reply;
|
final Post? reply;
|
||||||
final Post? repost;
|
final Post? repost;
|
||||||
final Realm? realm;
|
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 {
|
class PostPublishScreen extends StatefulWidget {
|
||||||
@ -31,6 +39,7 @@ class PostPublishScreen extends StatefulWidget {
|
|||||||
final Post? reply;
|
final Post? reply;
|
||||||
final Post? repost;
|
final Post? repost;
|
||||||
final Realm? realm;
|
final Realm? realm;
|
||||||
|
final PostListController? postListController;
|
||||||
final int mode;
|
final int mode;
|
||||||
|
|
||||||
const PostPublishScreen({
|
const PostPublishScreen({
|
||||||
@ -39,6 +48,7 @@ class PostPublishScreen extends StatefulWidget {
|
|||||||
this.reply,
|
this.reply,
|
||||||
this.repost,
|
this.repost,
|
||||||
this.realm,
|
this.realm,
|
||||||
|
this.postListController,
|
||||||
required this.mode,
|
required this.mode,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -85,6 +95,9 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
|
|||||||
context.showErrorDialog(resp.bodyString);
|
context.showErrorDialog(resp.bodyString);
|
||||||
} else {
|
} else {
|
||||||
_editorController.localClear();
|
_editorController.localClear();
|
||||||
|
if (widget.postListController != null) {
|
||||||
|
widget.postListController!.reloadAllOver();
|
||||||
|
}
|
||||||
AppRouter.instance.pop(resp.body);
|
AppRouter.instance.pop(resp.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
|
|
||||||
final List<Realm> _realms = List.empty(growable: true);
|
final List<Realm> _realms = List.empty(growable: true);
|
||||||
|
|
||||||
getRealms() async {
|
_getRealms() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
getRealms();
|
_getRealms();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -71,7 +71,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
AppRouter.instance.pushNamed('realmOrganizing').then(
|
AppRouter.instance.pushNamed('realmOrganizing').then(
|
||||||
(value) {
|
(value) {
|
||||||
if (value != null) getRealms();
|
if (value != null) _getRealms();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -84,7 +84,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
body: Obx(() {
|
body: Obx(() {
|
||||||
if (auth.isAuthorized.isFalse) {
|
if (auth.isAuthorized.isFalse) {
|
||||||
return SigninRequiredOverlay(
|
return SigninRequiredOverlay(
|
||||||
onSignedIn: () => getRealms(),
|
onSignedIn: () => _getRealms(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,12 +94,12 @@ class _RealmListScreenState extends State<RealmListScreen> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: CenteredContainer(
|
child: CenteredContainer(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () => getRealms(),
|
onRefresh: () => _getRealms(),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: _realms.length,
|
itemCount: _realms.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final element = _realms[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(
|
return Card(
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||||
|
@ -12,7 +12,6 @@ import 'package:solian/providers/content/posts.dart';
|
|||||||
import 'package:solian/providers/content/realm.dart';
|
import 'package:solian/providers/content/realm.dart';
|
||||||
import 'package:solian/router.dart';
|
import 'package:solian/router.dart';
|
||||||
import 'package:solian/screens/channel/channel_organize.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/theme.dart';
|
||||||
import 'package:solian/widgets/app_bar_leading.dart';
|
import 'package:solian/widgets/app_bar_leading.dart';
|
||||||
import 'package:solian/widgets/channel/channel_list.dart';
|
import 'package:solian/widgets/channel/channel_list.dart';
|
||||||
@ -136,6 +135,7 @@ class _RealmViewScreenState extends State<RealmViewScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return TabBarView(
|
return TabBarView(
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
children: [
|
children: [
|
||||||
RealmPostListWidget(realm: _realm!),
|
RealmPostListWidget(realm: _realm!),
|
||||||
RealmChannelListWidget(
|
RealmChannelListWidget(
|
||||||
@ -189,7 +189,6 @@ class _RealmPostListWidgetState extends State<RealmPostListWidget> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_pagingController.addPageRequestListener(getPosts);
|
_pagingController.addPageRequestListener(getPosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,28 +198,6 @@ class _RealmPostListWidgetState extends State<RealmPostListWidget> {
|
|||||||
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: [
|
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),
|
PostListWidget(controller: _pagingController),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user