selfprivacy.org.app/lib/ui/pages/users/users.dart

327 lines
11 KiB
Dart
Raw Normal View History

2020-12-03 16:52:53 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_colors.dart';
import 'package:selfprivacy/config/brand_theme.dart';
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
import 'package:selfprivacy/logic/models/user.dart';
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
import 'package:selfprivacy/ui/components/brand_modal_sheet/brand_modal_sheet.dart';
2020-12-08 19:26:51 +00:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/utils/password_generator.dart';
class UsersPage extends StatelessWidget {
const UsersPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final usersCubit = context.watch<UsersCubit>();
final users = usersCubit.state.users;
return Scaffold(
appBar: PreferredSize(
child: BrandHeader(title: 'Пользователи'),
preferredSize: Size.fromHeight(52),
),
floatingActionButton: Container(
width: 48.0,
height: 48.0,
child: RawMaterialButton(
fillColor: BrandColors.blue,
shape: CircleBorder(),
elevation: 0.0,
highlightElevation: 2,
child: Icon(
Icons.add,
color: Colors.white,
size: 34,
),
onPressed: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return _NewUser();
},
);
},
),
),
body: ListView(
children: [
...users.map((user) => _User(user: user)),
],
),
);
}
}
class _User extends StatelessWidget {
const _User({Key key, this.user}) : super(key: key);
final User user;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return _UserDetails(user: user);
},
);
},
child: Container(
padding: brandPagePadding2,
height: 48,
child: Row(
children: [
Container(
width: 17,
height: 17,
decoration: BoxDecoration(
color: user.color,
shape: BoxShape.circle,
),
),
SizedBox(width: 20),
2020-12-08 19:26:51 +00:00
BrandText.h4(user.login),
2020-12-03 16:52:53 +00:00
],
),
),
);
}
}
class _NewUser extends StatefulWidget {
const _NewUser({Key key}) : super(key: key);
@override
__NewUserState createState() => __NewUserState();
}
class __NewUserState extends State<_NewUser> {
var passController = TextEditingController(text: genPass());
@override
Widget build(BuildContext context) {
return BrandModalSheet(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BrandHeader(title: 'Новый пользователь'),
SizedBox(width: 14),
Padding(
padding: brandPagePadding2,
child: Column(
children: [
TextField(
decoration: InputDecoration(
labelText: 'Логин',
suffixText: '@example',
),
),
SizedBox(height: 20),
TextField(
controller: passController,
decoration: InputDecoration(
alignLabelWithHint: false,
labelText: 'Пароль',
suffixIcon: Padding(
padding: const EdgeInsets.only(right: 8),
child: IconButton(
icon: Icon(
BrandIcons.refresh,
color: BrandColors.blue,
),
onPressed: () {
passController.value =
TextEditingValue(text: genPass());
},
),
),
),
),
SizedBox(height: 30),
BrandButton.rised(
onPressed: () {
Navigator.pop(context);
},
title: 'Создать',
),
SizedBox(height: 40),
Text(
'Новый пользователь автоматически получит доступ ко всем сервисам. Ещё какое-то описание.'),
SizedBox(height: 30),
],
),
),
],
),
),
);
}
}
class _UserDetails extends StatelessWidget {
const _UserDetails({
Key key,
this.user,
}) : super(key: key);
final User user;
@override
Widget build(BuildContext context) {
return BrandModalSheet(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 200,
decoration: BoxDecoration(
color: user.color,
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 4,
horizontal: 2,
),
2020-12-06 07:28:31 +00:00
child: PopupMenuButton<PopupMenuItemType>(
2020-12-03 16:52:53 +00:00
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
2020-12-06 07:28:31 +00:00
onSelected: (PopupMenuItemType result) {
switch (result) {
case PopupMenuItemType.reset:
break;
case PopupMenuItemType.delete:
showDialog(
context: context,
child: AlertDialog(
title: Text('Подтверждение '),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('удалить учетную запись?'),
],
),
),
actions: <Widget>[
TextButton(
child: Text('Отменить'),
onPressed: () {
Navigator.of(context)..pop();
},
),
TextButton(
child: Text(
'Удалить',
style: TextStyle(
color: BrandColors.red,
),
),
onPressed: () {
Navigator.of(context)..pop()..pop();
},
),
],
));
break;
}
},
2020-12-03 16:52:53 +00:00
icon: Icon(Icons.more_vert),
itemBuilder: (BuildContext context) => [
2020-12-06 07:28:31 +00:00
PopupMenuItem<PopupMenuItemType>(
value: PopupMenuItemType.reset,
2020-12-03 16:52:53 +00:00
child: Container(
padding: EdgeInsets.only(left: 5),
child: Text('Сбросить пароль'),
),
),
2020-12-06 07:28:31 +00:00
PopupMenuItem<PopupMenuItemType>(
value: PopupMenuItemType.delete,
2020-12-03 16:52:53 +00:00
child: Container(
padding: EdgeInsets.only(left: 5),
child: Text(
'Удалить',
style: TextStyle(color: BrandColors.red),
),
),
),
],
),
),
),
Spacer(),
Padding(
2020-12-08 19:26:51 +00:00
padding: EdgeInsets.symmetric(
vertical: 20,
horizontal: 15,
),
child: BrandText.h1(
user.login,
softWrap: true,
overflow: TextOverflow.ellipsis,
)),
2020-12-03 16:52:53 +00:00
],
),
),
SizedBox(height: 20),
Padding(
padding: brandPagePadding2.copyWith(bottom: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2020-12-08 19:26:51 +00:00
BrandText.small('Учетная запись'),
2020-12-03 16:52:53 +00:00
Container(
height: 40,
alignment: Alignment.centerLeft,
2020-12-08 19:26:51 +00:00
child: BrandText.h4('${user.login}@example.com'),
2020-12-03 16:52:53 +00:00
),
SizedBox(height: 14),
2020-12-08 19:26:51 +00:00
BrandText.small('Пароль'),
2020-12-03 16:52:53 +00:00
Container(
height: 40,
alignment: Alignment.centerLeft,
2020-12-08 19:26:51 +00:00
child: BrandText.h4(user.password),
2020-12-03 16:52:53 +00:00
),
SizedBox(height: 24),
BrandDivider(),
SizedBox(height: 20),
BrandButton.iconText(
title: 'Отправить реквизиты для входа',
icon: Icon(BrandIcons.share),
onPressed: () {},
),
SizedBox(height: 20),
BrandDivider(),
SizedBox(height: 20),
Text(
2020-12-06 07:28:31 +00:00
'Вам был создан доступ к сервисам с логином <login> и паролем <password> к сервисам:- E-mail с адресом <username@domain.com>- Менеджер паролей: <pass.domain.com>- Файловое облако: <cloud.mydomain.com>- Видеоконференция <meet.domain.com>- Git сервер <git.mydomain.com>'),
2020-12-03 16:52:53 +00:00
],
),
)
],
),
);
}
}
2020-12-06 07:28:31 +00:00
enum PopupMenuItemType {
reset,
delete,
}