From 61098ffc43df384bbf8b1efab0aab0502f710acd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 16 May 2020 11:04:58 +0200 Subject: [PATCH] Start to create user page tablet mode --- lib/ui/screens/user_page_screen.dart | 14 +++-- lib/ui/widgets/posts_list_widget.dart | 29 +++++---- .../widgets/tablet_mode/user_page_tablet.dart | 59 +++++++++++++++++++ 3 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 lib/ui/widgets/tablet_mode/user_page_tablet.dart diff --git a/lib/ui/screens/user_page_screen.dart b/lib/ui/screens/user_page_screen.dart index 099ec53..8809458 100644 --- a/lib/ui/screens/user_page_screen.dart +++ b/lib/ui/screens/user_page_screen.dart @@ -3,6 +3,7 @@ import 'package:comunic/models/advanced_user_info.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/widgets/mobile_mode/user_page_mobile.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; +import 'package:comunic/ui/widgets/tablet_mode/user_page_tablet.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; @@ -99,9 +100,14 @@ class _UserPageScreenState extends SafeState { } Widget _buildBody() { - return UserMobilePage( - userInfo: _userInfo, - onNeedRefresh: () => _refreshIndicatorKey.currentState.show(), - ); + return isTablet(context) + ? UserPageTablet( + userInfo: _userInfo, + onNeedRefresh: () => _refreshIndicatorKey.currentState.show(), + ) + : UserMobilePage( + userInfo: _userInfo, + onNeedRefresh: () => _refreshIndicatorKey.currentState.show(), + ); } } diff --git a/lib/ui/widgets/posts_list_widget.dart b/lib/ui/widgets/posts_list_widget.dart index fdc0ebd..f81619c 100644 --- a/lib/ui/widgets/posts_list_widget.dart +++ b/lib/ui/widgets/posts_list_widget.dart @@ -30,6 +30,7 @@ class PostsListWidget extends StatefulWidget { final bool showPostsTarget; final bool buildListView; final bool userNamesClickable; + final bool disablePullToRefresh; const PostsListWidget({ Key key, @@ -39,10 +40,12 @@ class PostsListWidget extends StatefulWidget { this.buildListView = true, this.getOlder, this.topWidgets, + this.disablePullToRefresh = false, }) : assert(getPostsList != null), assert(showPostsTarget != null), assert(buildListView != null), assert(userNamesClickable != null), + assert(disablePullToRefresh != null), super(key: key); @override @@ -191,16 +194,18 @@ class PostsListWidgetState extends SafeState { ); } - Widget _buildListView() { - return RefreshIndicator( - child: ListView.builder( - // We use max function here to display to post notice in case there are not posts to display but there are custom widgets... - itemCount: max(_list.length, 1) + _numberTopWidgets, + Widget _buildListViewWithRefreshIndicator() => RefreshIndicator( + child: _buildListView(), + onRefresh: () => loadPostsList(), + ); - itemBuilder: _buildItem, - controller: _scrollController, - ), - onRefresh: () => loadPostsList(), + Widget _buildListView() { + return ListView.builder( + // We use max function here to display to post notice in case there are not posts to display but there are custom widgets... + itemCount: max(_list.length, 1) + _numberTopWidgets, + + itemBuilder: _buildItem, + controller: _scrollController, ); } @@ -235,7 +240,11 @@ class PostsListWidgetState extends SafeState { if (_list == null) return buildCenteredProgressBar(); if (_list.length == 0 && _numberTopWidgets == 0) return _buildNoPostNotice(); - return widget.buildListView ? _buildListView() : _buildColumn(); + if (!widget.buildListView) return _buildColumn(); + + if (widget.disablePullToRefresh) return _buildListView(); + + return _buildListViewWithRefreshIndicator(); } void _removePost(Post post) => setState(() => _list.remove(post)); diff --git a/lib/ui/widgets/tablet_mode/user_page_tablet.dart b/lib/ui/widgets/tablet_mode/user_page_tablet.dart new file mode 100644 index 0000000..5ec3b31 --- /dev/null +++ b/lib/ui/widgets/tablet_mode/user_page_tablet.dart @@ -0,0 +1,59 @@ +import 'package:comunic/enums/post_target.dart'; +import 'package:comunic/helpers/posts_helper.dart'; +import 'package:comunic/models/advanced_user_info.dart'; +import 'package:comunic/ui/widgets/post_create_form_widget.dart'; +import 'package:comunic/ui/widgets/posts_list_widget.dart'; +import 'package:flutter/material.dart'; + +/// Tablet mode of user page +/// +/// @author Pierre HUBERT + +class UserPageTablet extends StatefulWidget { + final AdvancedUserInfo userInfo; + final void Function() onNeedRefresh; + + const UserPageTablet({ + Key key, + @required this.userInfo, + @required this.onNeedRefresh, + }) : assert(userInfo != null), + assert(onNeedRefresh != null), + super(key: key); + + @override + _UserPageTabletState createState() => _UserPageTabletState(); +} + +class _UserPageTabletState extends State { + AdvancedUserInfo get _userInfo => widget.userInfo; + + @override + Widget build(BuildContext context) => Flex( + direction: Axis.horizontal, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildLeftColumn(), + Expanded(child: _buildRightColumn()) + ], + ); + + Widget _buildLeftColumn() => Text("Here comes the head"); + + Widget _buildRightColumn() => PostsListWidget( + disablePullToRefresh: true, + topWidgets: [ + _userInfo.canPostTexts + ? PostCreateFormWidget( + postTarget: PostTarget.USER_PAGE, + targetID: _userInfo.id, + onCreated: widget.onNeedRefresh, + ) + : Container() + ], + getPostsList: () => PostsHelper().getUserPosts(_userInfo.id), + getOlder: (from) => + PostsHelper().getUserPosts(_userInfo.id, from: from), + showPostsTarget: false, + ); +}