mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Start to create user page tablet mode
This commit is contained in:
parent
b364c7aece
commit
61098ffc43
@ -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,9 +100,14 @@ class _UserPageScreenState extends SafeState<UserPageScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBody() {
|
Widget _buildBody() {
|
||||||
return UserMobilePage(
|
return isTablet(context)
|
||||||
userInfo: _userInfo,
|
? UserPageTablet(
|
||||||
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
|
userInfo: _userInfo,
|
||||||
);
|
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
|
||||||
|
)
|
||||||
|
: UserMobilePage(
|
||||||
|
userInfo: _userInfo,
|
||||||
|
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 _buildListView() {
|
Widget _buildListViewWithRefreshIndicator() => RefreshIndicator(
|
||||||
return RefreshIndicator(
|
child: _buildListView(),
|
||||||
child: ListView.builder(
|
onRefresh: () => loadPostsList(),
|
||||||
// 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,
|
Widget _buildListView() {
|
||||||
controller: _scrollController,
|
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...
|
||||||
onRefresh: () => loadPostsList(),
|
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 == 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));
|
||||||
|
59
lib/ui/widgets/tablet_mode/user_page_tablet.dart
Normal file
59
lib/ui/widgets/tablet_mode/user_page_tablet.dart
Normal 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,
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user