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

105 lines
3.5 KiB
Dart
Raw Normal View History

2021-09-29 18:28:47 +00:00
import 'package:auto_size_text/auto_size_text.dart';
2021-01-14 18:45:10 +00:00
import 'package:cubit_form/cubit_form.dart';
2020-12-03 16:52:53 +00:00
import 'package:flutter/material.dart';
2021-09-29 18:28:47 +00:00
import 'package:hive/hive.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/config/brand_colors.dart';
import 'package:selfprivacy/config/brand_theme.dart';
2021-09-29 18:28:47 +00:00
import 'package:selfprivacy/config/hive_config.dart';
import 'package:selfprivacy/config/text_themes.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
2021-01-14 18:45:10 +00:00
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
2021-06-20 21:08:52 +00:00
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
2021-08-29 15:02:51 +00:00
import 'package:selfprivacy/logic/models/job.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/logic/models/user.dart';
2021-06-20 21:08:52 +00:00
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
2020-12-03 16:52:53 +00:00
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';
2020-12-08 19:26:51 +00:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
2021-03-18 00:55:38 +00:00
import 'package:easy_localization/easy_localization.dart';
2021-06-20 21:08:52 +00:00
import 'package:selfprivacy/ui/helpers/modals.dart';
2021-03-26 13:38:39 +00:00
import 'package:selfprivacy/utils/ui_helpers.dart';
2021-07-29 05:24:42 +00:00
import 'package:share_plus/share_plus.dart';
2020-12-03 16:52:53 +00:00
2021-01-06 17:35:57 +00:00
part 'fab.dart';
part 'new_user.dart';
part 'user_details.dart';
part 'user.dart';
part 'empty.dart';
2020-12-03 16:52:53 +00:00
class UsersPage extends StatelessWidget {
2021-03-15 15:39:44 +00:00
const UsersPage({Key? key}) : super(key: key);
2020-12-03 16:52:53 +00:00
@override
Widget build(BuildContext context) {
2021-03-15 15:39:44 +00:00
final usersCubitState = context.watch<UsersCubit>().state;
var isReady = context.watch<AppConfigCubit>().state is AppConfigFinished;
2021-10-11 21:10:04 +00:00
final users = [...usersCubitState.users];
2021-09-29 18:28:47 +00:00
//Todo: listen box events
User? user = Hive.box(BNames.appConfig).get(BNames.rootUser);
if (user != null) {
users.insert(0, user);
}
2021-10-13 21:49:24 +00:00
final isEmpty = users.isEmpty;
2021-01-06 17:35:57 +00:00
Widget child;
if (!isReady) {
child = isNotReady();
} else {
child = isEmpty
? Container(
alignment: Alignment.center,
child: _NoUsers(
2021-03-18 00:55:38 +00:00
text: 'users.add_new_user'.tr(),
2021-01-06 17:35:57 +00:00
),
)
2021-09-29 18:28:47 +00:00
: ListView.builder(
itemCount: users.length,
itemBuilder: (BuildContext context, int index) {
return _User(
user: users[index],
2021-10-11 21:10:04 +00:00
isRootUser: index == 0,
2021-09-29 18:28:47 +00:00
);
},
2021-01-06 17:35:57 +00:00
);
}
2020-12-03 16:52:53 +00:00
return Scaffold(
appBar: PreferredSize(
2021-05-25 21:53:54 +00:00
child: BrandHeader(
title: 'basis.users'.tr(),
hasFlashButton: true,
),
2020-12-03 16:52:53 +00:00
preferredSize: Size.fromHeight(52),
),
2021-01-06 17:35:57 +00:00
floatingActionButton: isReady ? _Fab() : null,
body: child,
2020-12-03 16:52:53 +00:00
);
}
2021-01-06 17:35:57 +00:00
Widget isNotReady() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: NotReadyCard(),
2020-12-03 16:52:53 +00:00
),
2021-01-06 17:35:57 +00:00
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Center(
child: _NoUsers(
2021-03-18 00:55:38 +00:00
text: 'users.not_ready'.tr(),
2020-12-03 16:52:53 +00:00
),
),
),
2021-01-06 17:35:57 +00:00
)
],
2020-12-03 16:52:53 +00:00
);
}
}