mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Create empty user page
This commit is contained in:
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>[]),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user