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

116 lines
4.3 KiB
Dart
Raw Normal View History

2020-12-01 19:08:19 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_theme.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
2020-12-01 19:08:19 +00:00
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
import 'package:selfprivacy/logic/models/service.dart';
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
import 'package:selfprivacy/ui/components/brand_card/brand_card.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
2020-12-01 19:08:19 +00:00
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';
2020-12-01 19:08:19 +00:00
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
2020-12-01 19:08:19 +00:00
class ServicesPage extends StatefulWidget {
ServicesPage({Key key}) : super(key: key);
@override
_ServicesPageState createState() => _ServicesPageState();
}
class _ServicesPageState extends State<ServicesPage> {
@override
Widget build(BuildContext context) {
final serviceCubit = context.watch<ServicesCubit>();
final connected = serviceCubit.state.connected;
final uninitialized = serviceCubit.state.uninitialized;
2021-01-06 17:35:57 +00:00
var isReady = context.watch<AppConfigCubit>().state.isFullyInitilized;
2020-12-01 19:08:19 +00:00
return Scaffold(
2020-12-03 16:52:53 +00:00
appBar: PreferredSize(
child: BrandHeader(title: 'Сервисы'),
preferredSize: Size.fromHeight(52),
),
2020-12-01 19:08:19 +00:00
body: ListView(
2020-12-03 16:52:53 +00:00
padding: brandPagePadding2,
2020-12-01 19:08:19 +00:00
children: [
2021-01-06 17:35:57 +00:00
if (!isReady) NotReadyCard(),
2020-12-01 19:08:19 +00:00
SizedBox(height: 24),
...connected.map((service) => _Card(service: service)).toList(),
if (uninitialized.isNotEmpty) ...[
2020-12-08 19:26:51 +00:00
BrandText.body1('не подключены'),
2020-12-01 19:08:19 +00:00
SizedBox(height: 30),
],
...uninitialized.map((service) => _Card(service: service)).toList()
],
),
);
}
}
class _Card extends StatelessWidget {
const _Card({Key key, @required this.service}) : super(key: key);
final Service service;
@override
Widget build(BuildContext context) {
String title;
IconData iconData;
String description;
switch (service.type) {
case ServiceTypes.messanger:
iconData = BrandIcons.messanger;
title = 'Мессенджер';
description =
2021-01-27 18:33:00 +00:00
'Delta Chat. Если бы мне надо было обсудить что-то от чего зависит жизнь. Я бы выбрал Delta.Chat + свой почтовый сервер.';
2020-12-01 19:08:19 +00:00
break;
case ServiceTypes.mail:
iconData = BrandIcons.envelope;
title = 'Почта';
description = 'Электронная почта для семьи или компании ';
break;
case ServiceTypes.passwordManager:
iconData = BrandIcons.key;
title = 'Менеджер паролей';
description = 'Надёжное хранилище для ваших паролей и ключей доступа';
break;
case ServiceTypes.github:
iconData = BrandIcons.github;
title = 'Git сервер';
description = 'Сервис для приватного хранения своих разработок';
break;
2020-12-06 07:28:31 +00:00
2020-12-01 19:08:19 +00:00
case ServiceTypes.cloud:
iconData = BrandIcons.upload;
title = 'Файловое Облако';
description = 'Сервис для доступа к вашим файлам в любой точке мира';
break;
}
return BrandCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2021-01-06 17:35:57 +00:00
IconStatusMask(
2020-12-01 19:08:19 +00:00
status: service.state,
child: Icon(iconData, size: 30, color: Colors.white),
),
SizedBox(height: 10),
2020-12-08 19:26:51 +00:00
BrandText.h2(title),
2020-12-01 19:08:19 +00:00
SizedBox(height: 10),
2020-12-10 20:33:19 +00:00
if (service.state == StateType.uninitialized) ...[
2020-12-08 19:26:51 +00:00
BrandText.body1(description),
2020-12-01 19:08:19 +00:00
SizedBox(height: 10),
BrandButton.text(
title: 'Подключить',
onPressed: () {
context.read<ServicesCubit>().connect(service);
})
],
2020-12-30 14:13:25 +00:00
if (service.state == StateType.stable) BrandText.body2('Подключен'),
2020-12-01 19:08:19 +00:00
],
),
);
}
}