mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 14:59:22 +00:00
Improve user access denied screen
This commit is contained in:
parent
736accaca4
commit
288cd492a2
@ -5,8 +5,9 @@ import 'package:comunic/models/user.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/FrienshipStatusWidget.dart';
|
import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// User access denied screen
|
/// User access denied screen
|
||||||
@ -24,94 +25,67 @@ class UserAccessDeniedScreen extends StatefulWidget {
|
|||||||
_UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState();
|
_UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UserAccessDeniedScreenState extends State<UserAccessDeniedScreen> {
|
class _UserAccessDeniedScreenState extends SafeState<UserAccessDeniedScreen> {
|
||||||
final UsersHelper usersHelper = UsersHelper();
|
final UsersHelper usersHelper = UsersHelper();
|
||||||
final FriendsHelper friendsHelper = FriendsHelper();
|
final FriendsHelper friendsHelper = FriendsHelper();
|
||||||
|
|
||||||
GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
final _key = GlobalKey<AsyncScreenWidgetState>();
|
||||||
GlobalKey<RefreshIndicatorState>();
|
|
||||||
|
|
||||||
FriendStatus _status;
|
FriendStatus _status;
|
||||||
User _user;
|
User _user;
|
||||||
bool _error = false;
|
|
||||||
|
|
||||||
void setError(bool e) => setState(() => _error = e);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
try {
|
final status = await friendsHelper.getFriendshipStatus(widget.userID);
|
||||||
final status = await friendsHelper.getFriendshipStatus(widget.userID);
|
final user = await usersHelper.getSingleWithThrow(widget.userID);
|
||||||
final user = await usersHelper.getSingleWithThrow(widget.userID);
|
|
||||||
|
|
||||||
// Check if the two users are friend now
|
// Check if the two users are friend now
|
||||||
if (status.areFriend) {
|
if (status.areFriend) {
|
||||||
final controller = MainController.of(context);
|
final controller = MainController.of(context);
|
||||||
controller.popPage();
|
controller.popPage();
|
||||||
controller.openUserPage(widget.userID);
|
controller.openUserPage(widget.userID);
|
||||||
}
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_status = status;
|
|
||||||
_user = user;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
setError(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_status = status;
|
||||||
|
_user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (!_error && _status == null) return buildLoadingPage(showAppBar: true);
|
return AsyncScreenWidget(
|
||||||
|
key: _key,
|
||||||
|
onReload: refresh,
|
||||||
|
onBuild: _buildPage,
|
||||||
|
errorMessage: tr("Could not load friendship information!"));
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
Widget _buildPage() {
|
||||||
appBar: AppBar(
|
final size = MediaQuery.of(context).size;
|
||||||
title: Text(_error ? "Error" : _user.displayName),
|
return Container(
|
||||||
),
|
constraints: BoxConstraints.loose(size),
|
||||||
body: RefreshIndicator(
|
child: SingleChildScrollView(
|
||||||
key: _refreshIndicatorKey,
|
child: Padding(
|
||||||
onRefresh: refresh,
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ListView.builder(
|
child: Column(
|
||||||
itemBuilder: (c, i) => _scrollBuild(),
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
itemCount: 1,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
AccountImageWidget(
|
||||||
|
user: _user,
|
||||||
|
width: 75,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
_user.displayName,
|
||||||
|
style: TextStyle(fontSize: 25.0),
|
||||||
|
),
|
||||||
|
Text(tr("This account is private.")),
|
||||||
|
FriendshipStatusWidget(
|
||||||
|
status: _status,
|
||||||
|
onFriendshipUpdated: () => _key.currentState.refresh(),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _scrollBuild() {
|
|
||||||
if (_error) return _buildError();
|
|
||||||
|
|
||||||
return _buildPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildError() {
|
|
||||||
return buildErrorCard("Could get information about your friendship!");
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildPage() {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
AccountImageWidget(
|
|
||||||
user: _user,
|
|
||||||
width: 75,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
_user.displayName,
|
|
||||||
style: TextStyle(fontSize: 25.0),
|
|
||||||
),
|
|
||||||
Text(tr("This account is private.")),
|
|
||||||
FriendshipStatusWidget(
|
|
||||||
status: _status,
|
|
||||||
onFriendshipUpdated: () => _refreshIndicatorKey.currentState.show(),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user