2019-06-15 14:01:58 +00:00
|
|
|
import 'package:comunic/helpers/friends_helper.dart';
|
|
|
|
import 'package:comunic/helpers/users_helper.dart';
|
|
|
|
import 'package:comunic/models/friend_status.dart';
|
|
|
|
import 'package:comunic/models/user.dart';
|
2020-05-05 11:21:37 +00:00
|
|
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
2019-06-15 14:01:58 +00:00
|
|
|
import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
2020-05-16 07:46:38 +00:00
|
|
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
2019-06-15 14:01:58 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2020-04-16 11:26:04 +00:00
|
|
|
/// User access denied screen
|
2019-06-15 14:01:58 +00:00
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2020-04-16 11:26:04 +00:00
|
|
|
class UserAccessDeniedScreen extends StatefulWidget {
|
2019-06-15 14:01:58 +00:00
|
|
|
final int userID;
|
|
|
|
|
2020-04-16 11:26:04 +00:00
|
|
|
const UserAccessDeniedScreen({Key key, @required this.userID})
|
2019-06-15 14:01:58 +00:00
|
|
|
: assert(userID != null),
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
@override
|
2020-04-16 11:26:04 +00:00
|
|
|
_UserAccessDeniedScreenState createState() => _UserAccessDeniedScreenState();
|
2019-06-15 14:01:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 07:46:38 +00:00
|
|
|
class _UserAccessDeniedScreenState extends SafeState<UserAccessDeniedScreen> {
|
2019-06-15 14:01:58 +00:00
|
|
|
final UsersHelper usersHelper = UsersHelper();
|
|
|
|
final FriendsHelper friendsHelper = FriendsHelper();
|
|
|
|
|
2020-05-16 07:46:38 +00:00
|
|
|
final _key = GlobalKey<AsyncScreenWidgetState>();
|
2019-06-15 14:01:58 +00:00
|
|
|
|
|
|
|
FriendStatus _status;
|
|
|
|
User _user;
|
|
|
|
|
|
|
|
Future<void> refresh() async {
|
2020-05-16 07:46:38 +00:00
|
|
|
final status = await friendsHelper.getFriendshipStatus(widget.userID);
|
|
|
|
final user = await usersHelper.getSingleWithThrow(widget.userID);
|
|
|
|
|
|
|
|
// Check if the two users are friend now
|
|
|
|
if (status.areFriend) {
|
|
|
|
final controller = MainController.of(context);
|
|
|
|
controller.popPage();
|
|
|
|
controller.openUserPage(widget.userID);
|
2019-06-15 14:01:58 +00:00
|
|
|
}
|
2020-05-16 07:46:38 +00:00
|
|
|
|
|
|
|
_status = status;
|
|
|
|
_user = user;
|
2019-06-15 14:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-16 07:46:38 +00:00
|
|
|
return AsyncScreenWidget(
|
|
|
|
key: _key,
|
|
|
|
onReload: refresh,
|
|
|
|
onBuild: _buildPage,
|
|
|
|
errorMessage: tr("Could not load friendship information!"));
|
2019-06-15 14:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildPage() {
|
2020-05-16 07:46:38 +00:00
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
return Container(
|
2021-03-13 14:38:43 +00:00
|
|
|
width: size.width,
|
2020-05-16 07:46:38 +00:00
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
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(),
|
|
|
|
)
|
|
|
|
],
|
2019-06-15 14:01:58 +00:00
|
|
|
),
|
2020-05-16 07:46:38 +00:00
|
|
|
),
|
2019-06-15 14:01:58 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|