mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 14:29:22 +00:00
Create empty user page
This commit is contained in:
parent
c7d11aed1d
commit
ba93ffb01e
@ -1,6 +1,7 @@
|
|||||||
import 'package:comunic/enums/user_page_visibility.dart';
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
import 'package:comunic/helpers/database/users_database_helper.dart';
|
import 'package:comunic/helpers/database/users_database_helper.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
import 'package:comunic/models/api_request.dart';
|
import 'package:comunic/models/api_request.dart';
|
||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
|
|
||||||
@ -10,6 +11,15 @@ import 'package:comunic/models/user.dart';
|
|||||||
///
|
///
|
||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
/// Handle advanced information error
|
||||||
|
enum GetUserAdvancedInformationErrorCause { NOT_FOUND, NETWORK_ERROR }
|
||||||
|
|
||||||
|
class GetUserAdvancedUserError extends Error {
|
||||||
|
final GetUserAdvancedInformationErrorCause cause;
|
||||||
|
|
||||||
|
GetUserAdvancedUserError(this.cause) : assert(cause != null);
|
||||||
|
}
|
||||||
|
|
||||||
class UsersHelper {
|
class UsersHelper {
|
||||||
final UsersDatabaseHelper _usersDatabaseHelper = UsersDatabaseHelper();
|
final UsersDatabaseHelper _usersDatabaseHelper = UsersDatabaseHelper();
|
||||||
|
|
||||||
@ -87,4 +97,39 @@ class UsersHelper {
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Try to fetch advanced information about a user
|
||||||
|
Future<AdvancedUserInfo> getAdvancedInfo(int id) async {
|
||||||
|
final response = await APIRequest(
|
||||||
|
uri: "user/getAdvancedUserInfo",
|
||||||
|
needLogin: true,
|
||||||
|
args: {"userID": id.toString()}).exec();
|
||||||
|
|
||||||
|
// Handle exceptions
|
||||||
|
if (response.code != 200) {
|
||||||
|
var cause = GetUserAdvancedInformationErrorCause.NETWORK_ERROR;
|
||||||
|
|
||||||
|
if (response.code == 404)
|
||||||
|
cause = GetUserAdvancedInformationErrorCause.NOT_FOUND;
|
||||||
|
|
||||||
|
throw new GetUserAdvancedUserError(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
final data = response.getObject();
|
||||||
|
|
||||||
|
return AdvancedUserInfo(
|
||||||
|
id: data["userID"],
|
||||||
|
firstName: data["firstName"],
|
||||||
|
lastName: data["lastName"],
|
||||||
|
pageVisibility: data["publicPage"] == "false"
|
||||||
|
? UserPageVisibility.PRIVATE
|
||||||
|
: (data["openPage"] == "false"
|
||||||
|
? UserPageVisibility.PRIVATE
|
||||||
|
: UserPageVisibility.OPEN),
|
||||||
|
virtualDirectory:
|
||||||
|
data["virtualDirectory"] == "" ? null : data["virtualDirectory"],
|
||||||
|
accountImageURL: data["accountImage"],
|
||||||
|
publicNote: data["publicNote"],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
28
lib/models/advanced_user_info.dart
Normal file
28
lib/models/advanced_user_info.dart
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
|
import 'package:comunic/models/user.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
/// Advanced user information
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
class AdvancedUserInfo extends User {
|
||||||
|
final String publicNote;
|
||||||
|
|
||||||
|
const AdvancedUserInfo({
|
||||||
|
@required int id,
|
||||||
|
@required String firstName,
|
||||||
|
@required String lastName,
|
||||||
|
@required UserPageVisibility pageVisibility,
|
||||||
|
@required String virtualDirectory,
|
||||||
|
@required String accountImageURL,
|
||||||
|
@required this.publicNote,
|
||||||
|
}) : assert(publicNote != null),
|
||||||
|
super(
|
||||||
|
id: id,
|
||||||
|
firstName: firstName,
|
||||||
|
lastName: lastName,
|
||||||
|
pageVisibility: pageVisibility,
|
||||||
|
virtualDirectory: virtualDirectory,
|
||||||
|
accountImageURL: accountImageURL);
|
||||||
|
}
|
138
lib/ui/routes/user_page_route.dart
Normal file
138
lib/ui/routes/user_page_route.dart
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// User page route
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
enum _PageStatus { LOADING, ERROR, READY }
|
||||||
|
|
||||||
|
class UserPageRoute extends StatefulWidget {
|
||||||
|
final int userID;
|
||||||
|
|
||||||
|
const UserPageRoute({Key key, @required this.userID})
|
||||||
|
: assert(userID != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_UserPageRouteState createState() => _UserPageRouteState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UserPageRouteState extends State<UserPageRoute> {
|
||||||
|
// Helpers
|
||||||
|
final usersHelper = UsersHelper();
|
||||||
|
|
||||||
|
// Objects members
|
||||||
|
final double _appBarHeight = 256.0;
|
||||||
|
_PageStatus _status = _PageStatus.LOADING;
|
||||||
|
AdvancedUserInfo _userInfo;
|
||||||
|
|
||||||
|
_setStatus(_PageStatus s) => setState(() => _status = s);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
_getUserInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _getUserInfo() async {
|
||||||
|
_setStatus(_PageStatus.LOADING);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final user = await usersHelper.getAdvancedInfo(widget.userID);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_userInfo = user;
|
||||||
|
});
|
||||||
|
|
||||||
|
_setStatus(_PageStatus.READY);
|
||||||
|
} on GetUserAdvancedUserError catch (e) {
|
||||||
|
_setStatus(_PageStatus.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (_status == _PageStatus.LOADING) return buildLoadingPage();
|
||||||
|
|
||||||
|
if (_status == _PageStatus.ERROR) return _buildError();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
body: CustomScrollView(
|
||||||
|
slivers: <Widget>[_buildHeader(), _buildBody()],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Error card
|
||||||
|
Widget _buildError() {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(tr("Error")),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child:
|
||||||
|
buildErrorCard(tr("Could not get user information!"), actions: [
|
||||||
|
FlatButton(
|
||||||
|
onPressed: _getUserInfo,
|
||||||
|
child: Text(
|
||||||
|
tr("Retry").toUpperCase(),
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
])),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildHeader() {
|
||||||
|
return SliverAppBar(
|
||||||
|
expandedHeight: _appBarHeight,
|
||||||
|
floating: false,
|
||||||
|
pinned: true,
|
||||||
|
snap: false,
|
||||||
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
|
title: Text(_userInfo.displayName),
|
||||||
|
background: Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
children: <Widget>[
|
||||||
|
NetworkImageWidget(
|
||||||
|
url: _userInfo.accountImageURL,
|
||||||
|
height: _appBarHeight,
|
||||||
|
),
|
||||||
|
// This gradient ensures that the toolbar icons are distinct
|
||||||
|
// against the background image.
|
||||||
|
const DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: LinearGradient(
|
||||||
|
begin: Alignment(0.0, -1.0),
|
||||||
|
end: Alignment(0.0, -0.4),
|
||||||
|
colors: <Color>[Color(0x60000000), Color(0x00000000)],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: LinearGradient(
|
||||||
|
begin: Alignment(0.0, 0.4),
|
||||||
|
end: Alignment(0.0, 0.9),
|
||||||
|
colors: <Color>[Color(0x00000000), Color(0x60000000)],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildBody() {
|
||||||
|
return SliverList(
|
||||||
|
delegate: SliverChildListDelegate(<Widget>[]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ import 'package:comunic/models/user.dart';
|
|||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/utils/date_utils.dart';
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:comunic/utils/navigation_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Accepted friend tile
|
/// Accepted friend tile
|
||||||
@ -39,6 +40,7 @@ class AcceptedFriendTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
onTap: () => openUserPage(context: context, userID: user.id),
|
||||||
leading: AccountImageWidget(user: user),
|
leading: AccountImageWidget(user: user),
|
||||||
title: Text(user.displayName),
|
title: Text(user.displayName),
|
||||||
subtitle: friend.isConnected
|
subtitle: friend.isConnected
|
||||||
|
21
lib/utils/navigation_utils.dart
Normal file
21
lib/utils/navigation_utils.dart
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import 'package:comunic/ui/routes/user_page_route.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
/// Navigation utilities
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
/// Open the page of a user
|
||||||
|
void openUserPage({@required int userID, @required BuildContext context}) {
|
||||||
|
assert(userID != null);
|
||||||
|
assert(context != null);
|
||||||
|
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (c) => UserPageRoute(
|
||||||
|
userID: userID,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user