mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Turn user page route into a screen
This commit is contained in:
@ -1,15 +1,16 @@
|
||||
import 'package:comunic/helpers/account_helper.dart';
|
||||
import 'package:comunic/ui/routes/app_settings_route.dart';
|
||||
import 'package:comunic/ui/routes/user_page_route.dart';
|
||||
import 'package:comunic/ui/screens/conversations_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/group_screen.dart';
|
||||
import 'package:comunic/ui/screens/groups_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/newest_posts.dart';
|
||||
import 'package:comunic/ui/screens/notifications_screen.dart';
|
||||
import 'package:comunic/ui/screens/other_friends_lists_screen.dart';
|
||||
import 'package:comunic/ui/widgets/navbar_widget.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -41,13 +42,18 @@ class CurrPage {
|
||||
|
||||
/// Public interface of home controller
|
||||
abstract class HomeController extends State<HomeRoute> {
|
||||
|
||||
/// Get current instance of Home controller
|
||||
static HomeController of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<HomeController>();
|
||||
|
||||
/// Open user page
|
||||
void openUserPage(int userID);
|
||||
|
||||
/// Open a specific group page specified by its [groupID]
|
||||
void openGroup(int groupID);
|
||||
|
||||
/// Display the list of friends of a user
|
||||
void openUserFriendsList(int userID);
|
||||
}
|
||||
|
||||
/// Private implementation of HomeController
|
||||
@ -129,12 +135,20 @@ class _HomeRouteState extends HomeController {
|
||||
case BarCallbackActions.OPEN_FRIENDS:
|
||||
return FriendsListScreen();
|
||||
|
||||
case BarCallbackActions.OPEN_USER_PAGE:
|
||||
return UserPageRoute(userID: _currTab.args["userID"]);
|
||||
|
||||
case BarCallbackActions.OPEN_GROUPS:
|
||||
return GroupsListScreen();
|
||||
|
||||
case BarCallbackActions.OPEN_GROUP_PAGE:
|
||||
return GroupPageScreen(groupID: _currTab.args["groupID"]);
|
||||
|
||||
case BarCallbackActions.OPEN_USER_FRIENDS_LIST:
|
||||
return OtherUserFriendsListScreen(
|
||||
userID: _currTab.args["userID"],
|
||||
);
|
||||
|
||||
default:
|
||||
throw "Invalid tab : " + _currTab.toString();
|
||||
}
|
||||
@ -164,7 +178,7 @@ class _HomeRouteState extends HomeController {
|
||||
|
||||
/// Open current user page
|
||||
Future<void> _openCurrentUserPage() async {
|
||||
openUserPage(context: context, userID: userID());
|
||||
this.openUserPage(userID());
|
||||
}
|
||||
|
||||
void _openAppSettings() {
|
||||
@ -191,4 +205,16 @@ class _HomeRouteState extends HomeController {
|
||||
_pushPage(CurrPage(BarCallbackActions.OPEN_GROUP_PAGE,
|
||||
args: {"groupID": groupID}));
|
||||
}
|
||||
|
||||
@override
|
||||
void openUserPage(int userID) {
|
||||
_pushPage(
|
||||
CurrPage(BarCallbackActions.OPEN_USER_PAGE, args: {"userID": userID}));
|
||||
}
|
||||
|
||||
@override
|
||||
void openUserFriendsList(int userID) {
|
||||
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,
|
||||
args: {"userID": userID}));
|
||||
}
|
||||
}
|
||||
|
@ -1,114 +0,0 @@
|
||||
import 'package:comunic/helpers/friends_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
import 'package:comunic/ui/tiles/simple_user_tile.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Other friends list route (not intended to display current user friends list)
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class OtherUserFriendsListRoute extends StatefulWidget {
|
||||
final User user;
|
||||
|
||||
const OtherUserFriendsListRoute({
|
||||
Key key,
|
||||
@required this.user,
|
||||
}) : assert(user != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_OtherUserFriendsListRouteState createState() =>
|
||||
_OtherUserFriendsListRouteState();
|
||||
}
|
||||
|
||||
class _OtherUserFriendsListRouteState extends State<OtherUserFriendsListRoute> {
|
||||
final FriendsHelper friendsHelper = FriendsHelper();
|
||||
final UsersHelper usersHelper = UsersHelper();
|
||||
|
||||
UsersList _list;
|
||||
bool _error = false;
|
||||
|
||||
String get _routeName =>
|
||||
tr("Friends of %name%", args: {"name": widget.user.displayName});
|
||||
|
||||
void setError(bool e) => setState(() => _error = e);
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
load();
|
||||
}
|
||||
|
||||
/// Load the list of friends of the user
|
||||
Future<void> load() async {
|
||||
setError(false);
|
||||
|
||||
try {
|
||||
final list = await usersHelper.getListWithThrow(
|
||||
await friendsHelper.getOtherUserList(widget.user.id));
|
||||
|
||||
setState(() {
|
||||
_list = list;
|
||||
});
|
||||
} catch (e, st) {
|
||||
print(e);
|
||||
print(st);
|
||||
setError(true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_error) return _buildError();
|
||||
|
||||
if (_list == null)
|
||||
return buildLoadingPage(
|
||||
showAppBar: true,
|
||||
routeTitle: _routeName,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_routeName),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: _list.length,
|
||||
itemBuilder: (c, i) => SimpleUserTile(
|
||||
user: _list[i],
|
||||
onTap: (u) => openUserPage(
|
||||
context: context,
|
||||
userID: u.id,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildError() {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_routeName),
|
||||
),
|
||||
body: buildErrorCard(
|
||||
tr(
|
||||
"Could not get the list of friends of %name% !",
|
||||
args: {"name": widget.user.displayName},
|
||||
),
|
||||
actions: [
|
||||
FlatButton(
|
||||
child: Text(
|
||||
tr("Try again").toUpperCase(),
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
onPressed: load,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import 'package:comunic/enums/post_target.dart';
|
||||
import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/models/advanced_user_info.dart';
|
||||
import 'package:comunic/ui/routes/other_friends_lists_route.dart';
|
||||
import 'package:comunic/ui/routes/home_route.dart';
|
||||
import 'package:comunic/ui/routes/user_access_denied_route.dart';
|
||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
|
||||
@ -221,13 +221,7 @@ class _UserPageRouteState extends State<UserPageRoute> {
|
||||
void _selectedMenuOption(_MenuOptions value) {
|
||||
switch (value) {
|
||||
case _MenuOptions.FRIENDS_LIST:
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => OtherUserFriendsListRoute(
|
||||
user: _userInfo,
|
||||
),
|
||||
),
|
||||
);
|
||||
HomeController.of(context).openUserFriendsList(_userInfo.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user