1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Start to create user page tablet mode

This commit is contained in:
Pierre HUBERT 2020-05-16 11:04:58 +02:00
parent b364c7aece
commit 61098ffc43
3 changed files with 88 additions and 14 deletions

View File

@ -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/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/mobile_mode/user_page_mobile.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/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/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -99,7 +100,12 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
} }
Widget _buildBody() { Widget _buildBody() {
return UserMobilePage( return isTablet(context)
? UserPageTablet(
userInfo: _userInfo,
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
)
: UserMobilePage(
userInfo: _userInfo, userInfo: _userInfo,
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(), onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
); );

View File

@ -30,6 +30,7 @@ class PostsListWidget extends StatefulWidget {
final bool showPostsTarget; final bool showPostsTarget;
final bool buildListView; final bool buildListView;
final bool userNamesClickable; final bool userNamesClickable;
final bool disablePullToRefresh;
const PostsListWidget({ const PostsListWidget({
Key key, Key key,
@ -39,10 +40,12 @@ class PostsListWidget extends StatefulWidget {
this.buildListView = true, this.buildListView = true,
this.getOlder, this.getOlder,
this.topWidgets, this.topWidgets,
this.disablePullToRefresh = false,
}) : assert(getPostsList != null), }) : assert(getPostsList != null),
assert(showPostsTarget != null), assert(showPostsTarget != null),
assert(buildListView != null), assert(buildListView != null),
assert(userNamesClickable != null), assert(userNamesClickable != null),
assert(disablePullToRefresh != null),
super(key: key); super(key: key);
@override @override
@ -191,16 +194,18 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
); );
} }
Widget _buildListViewWithRefreshIndicator() => RefreshIndicator(
child: _buildListView(),
onRefresh: () => loadPostsList(),
);
Widget _buildListView() { Widget _buildListView() {
return RefreshIndicator( return ListView.builder(
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... // 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, itemCount: max(_list.length, 1) + _numberTopWidgets,
itemBuilder: _buildItem, itemBuilder: _buildItem,
controller: _scrollController, controller: _scrollController,
),
onRefresh: () => loadPostsList(),
); );
} }
@ -235,7 +240,11 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
if (_list == null) return buildCenteredProgressBar(); if (_list == null) return buildCenteredProgressBar();
if (_list.length == 0 && _numberTopWidgets == 0) if (_list.length == 0 && _numberTopWidgets == 0)
return _buildNoPostNotice(); 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)); void _removePost(Post post) => setState(() => _list.remove(post));

View File

@ -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<UserPageTablet> {
AdvancedUserInfo get _userInfo => widget.userInfo;
@override
Widget build(BuildContext context) => Flex(
direction: Axis.horizontal,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_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,
);
}