From 56c5eb335bf9e4993dc31d47b0786006128746eb Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 12 Mar 2022 10:13:32 +0100 Subject: [PATCH] Fix refresh issue --- lib/ui/routes/main_route/main_route.dart | 12 ++++++++---- lib/ui/routes/main_route/page_info.dart | 2 ++ lib/ui/screens/user_page_screen.dart | 18 ++++++++++++------ .../widgets/tablet_mode/user_page_tablet.dart | 3 +++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/ui/routes/main_route/main_route.dart b/lib/ui/routes/main_route/main_route.dart index 316611c..04d3c93 100644 --- a/lib/ui/routes/main_route/main_route.dart +++ b/lib/ui/routes/main_route/main_route.dart @@ -101,10 +101,14 @@ abstract class MainController extends State { PageInfo(type: PageType.LATEST_POSTS_PAGE, child: NewestPostsScreen())); /// Open user page - void openUserPage(int userID) => pushPage(PageInfo( - type: PageType.USER_PAGE, - child: UserPageScreen(userID: userID), - id: userID)); + void openUserPage(int userID) { + final key = GlobalKey(); + pushPage(PageInfo( + type: PageType.USER_PAGE, + child: UserPageScreen(userID: userID, key: key), + id: userID, + widgetKey: key)); + } void openUserAccessDeniedPage(int userID) => pushPage(PageInfo(child: UserAccessDeniedScreen(userID: userID))); diff --git a/lib/ui/routes/main_route/page_info.dart b/lib/ui/routes/main_route/page_info.dart index 9585d27..968f945 100644 --- a/lib/ui/routes/main_route/page_info.dart +++ b/lib/ui/routes/main_route/page_info.dart @@ -24,6 +24,7 @@ class PageInfo { /// Unique identification of this child final key = UniqueKey(); + final GlobalKey? widgetKey; PageInfo({ this.type = PageType.OTHER_PAGE, @@ -31,5 +32,6 @@ class PageInfo { this.id, this.hideNavBar = false, this.canShowAsDialog = false, + this.widgetKey }); } diff --git a/lib/ui/screens/user_page_screen.dart b/lib/ui/screens/user_page_screen.dart index fa1a7b9..0a9d8ad 100644 --- a/lib/ui/screens/user_page_screen.dart +++ b/lib/ui/screens/user_page_screen.dart @@ -20,8 +20,7 @@ enum _PageStatus { LOADING, ERROR, READY } class UserPageScreen extends StatefulWidget { final int userID; - const UserPageScreen({Key? key, required this.userID}) - : super(key: key); + const UserPageScreen({Key? key, required this.userID}) : super(key: key); @override _UserPageScreenState createState() => _UserPageScreenState(); @@ -33,18 +32,23 @@ class _UserPageScreenState extends SafeState { // Objects members _PageStatus _status = _PageStatus.LOADING; - late AdvancedUserInfo _userInfo; + AdvancedUserInfo? _userInfo; FriendStatus? _frienshipStatus; final _refreshIndicatorKey = GlobalKey(); + final _pageKey = GlobalKey(); + _setStatus(_PageStatus s) => setState(() => _status = s); @override void didChangeDependencies() { super.didChangeDependencies(); - _getUserInfo(); + if(_userInfo?.id != widget.userID) + _getUserInfo(); } + + Future _getUserInfo() async { _setStatus(_PageStatus.LOADING); @@ -112,12 +116,14 @@ class _UserPageScreenState extends SafeState { Widget _buildBody() { return isTablet(context) ? UserPageTablet( - userInfo: _userInfo, + key: _pageKey, + userInfo: _userInfo!, onNeedRefresh: () => _refreshIndicatorKey.currentState!.show(), friendshipStatus: _frienshipStatus, ) : UserMobilePage( - userInfo: _userInfo, + key: _pageKey, + userInfo: _userInfo!, onNeedRefresh: () => _refreshIndicatorKey.currentState!.show(), ); } diff --git a/lib/ui/widgets/tablet_mode/user_page_tablet.dart b/lib/ui/widgets/tablet_mode/user_page_tablet.dart index bac03fb..cf02a3c 100644 --- a/lib/ui/widgets/tablet_mode/user_page_tablet.dart +++ b/lib/ui/widgets/tablet_mode/user_page_tablet.dart @@ -38,6 +38,8 @@ class UserPageTablet extends StatefulWidget { } class _UserPageTabletState extends State { + final _formKey = GlobalKey(); + AdvancedUserInfo get _userInfo => widget.userInfo; bool get _isCurrentUser => _userInfo.id == userID(); @@ -70,6 +72,7 @@ class _UserPageTabletState extends State { topWidgets: [ _userInfo.canPostTexts ? PostCreateFormWidget( + key: _formKey, postTarget: PostTarget.USER_PAGE, targetID: _userInfo.id, onCreated: widget.onNeedRefresh,