1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-27 05:18:50 +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/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<UserPageScreen> {
}
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(),
);
}
}

View File

@ -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<PostsListWidget> {
);
}
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<PostsListWidget> {
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));

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,
);
}