1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Add friend tab

This commit is contained in:
Pierre HUBERT 2021-03-17 17:14:53 +01:00
parent 20e486fe26
commit 160a3e1f27
4 changed files with 41 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:comunic/enums/user_page_visibility.dart'; import 'package:comunic/enums/user_page_visibility.dart';
import 'package:comunic/helpers/serialization/base_serialization_helper.dart'; import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
import 'package:comunic/lists/custom_emojies_list.dart'; import 'package:comunic/lists/custom_emojies_list.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
@ -44,6 +45,8 @@ class User implements SerializableElement<User> {
bool get hasVirtualDirectory => bool get hasVirtualDirectory =>
virtualDirectory != null && virtualDirectory.length > 0; virtualDirectory != null && virtualDirectory.length > 0;
bool get isCurrentUser => id == userID();
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"id": id, "id": id,
"firstName": firstName, "firstName": firstName,

View File

@ -20,6 +20,10 @@ import 'package:flutter/material.dart';
enum _ErrorsLevel { NONE, MINOR, MAJOR } enum _ErrorsLevel { NONE, MINOR, MAJOR }
class FriendsListScreen extends StatefulWidget { class FriendsListScreen extends StatefulWidget {
final bool showAppBar;
const FriendsListScreen({Key key, this.showAppBar = true}) : super(key: key);
@override @override
State<StatefulWidget> createState() => _FriendsListScreenState(); State<StatefulWidget> createState() => _FriendsListScreenState();
} }
@ -103,9 +107,11 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
@override @override
Widget build(BuildContext context) => Scaffold( Widget build(BuildContext context) => Scaffold(
appBar: AppBar( appBar: widget.showAppBar
title: Text(tr("Your friends list")), ? AppBar(
), title: Text(tr("Your friends list")),
)
: null,
body: _buildBody(), body: _buildBody(),
); );

View File

@ -13,11 +13,14 @@ import 'package:flutter/material.dart';
class OtherUserFriendsListScreen extends StatefulWidget { class OtherUserFriendsListScreen extends StatefulWidget {
final int userID; final int userID;
final bool enableAppBar;
const OtherUserFriendsListScreen({ const OtherUserFriendsListScreen({
Key key, Key key,
@required this.userID, @required this.userID,
this.enableAppBar = true,
}) : assert(userID != null), }) : assert(userID != null),
assert(enableAppBar != null),
super(key: key); super(key: key);
@override @override
@ -74,9 +77,11 @@ class _OtherUserFriendsListScreenState
if (_usersInfo == null) return buildCenteredProgressBar(); if (_usersInfo == null) return buildCenteredProgressBar();
return Scaffold( return Scaffold(
appBar: AppBar( appBar: widget.enableAppBar
title: Text(_routeName), ? AppBar(
), title: Text(_routeName),
)
: null,
body: ListView.builder( body: ListView.builder(
itemCount: _friendsList.length, itemCount: _friendsList.length,
itemBuilder: (c, i) => SimpleUserTile( itemBuilder: (c, i) => SimpleUserTile(

View File

@ -1,4 +1,6 @@
import 'package:comunic/models/advanced_user_info.dart'; import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/ui/screens/friends_list_screen.dart';
import 'package:comunic/ui/screens/other_friends_lists_screen.dart';
import 'package:comunic/ui/screens/user_page_sections/user_page_header.dart'; import 'package:comunic/ui/screens/user_page_sections/user_page_header.dart';
import 'package:comunic/ui/screens/user_page_sections/user_posts_section.dart'; import 'package:comunic/ui/screens/user_page_sections/user_posts_section.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
@ -36,7 +38,21 @@ class _UserMobilePageState extends State<UserMobilePage>
user: widget.userInfo, user: widget.userInfo,
), ),
), ),
];
// User friends
UserPageTab(
label: tr("Friends"),
onBuild: (c) => widget.userInfo.isCurrentUser
? FriendsListScreen(
showAppBar: false,
)
: OtherUserFriendsListScreen(
userID: widget.userInfo.id,
enableAppBar: false,
),
visible: widget.userInfo.isFriendsListPublic ||
widget.userInfo.isCurrentUser),
].where((element) => element.visible).toList();
@override @override
void initState() { void initState() {
@ -85,12 +101,15 @@ class _UserMobilePageState extends State<UserMobilePage>
class UserPageTab { class UserPageTab {
final String label; final String label;
final WidgetBuilder onBuild; final WidgetBuilder onBuild;
final bool visible;
UserPageTab({ UserPageTab({
@required this.label, @required this.label,
@required this.onBuild, @required this.onBuild,
this.visible = true,
}) : assert(label != null), }) : assert(label != null),
assert(onBuild != null); assert(onBuild != null),
assert(visible != null);
Tab get tab => Tab(text: label); Tab get tab => Tab(text: label);
} }