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

216 lines
6.9 KiB
Dart
Raw Normal View History

2020-12-03 16:52:53 +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-10 20:33:19 +00:00
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
2020-12-06 07:28:31 +00:00
import 'package:selfprivacy/logic/models/provider.dart';
2020-12-10 20:33:19 +00:00
import 'package:selfprivacy/logic/models/state_types.dart';
2020-12-03 16:52:53 +00:00
import 'package:selfprivacy/ui/components/brand_card/brand_card.dart';
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
2020-12-06 07:28:31 +00:00
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/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-30 14:13:25 +00:00
import 'package:selfprivacy/ui/pages/providers/settings/settings.dart';
2020-12-06 07:28:31 +00:00
import 'package:selfprivacy/utils/route_transitions/basic.dart';
2020-12-03 16:52:53 +00:00
class ProvidersPage extends StatefulWidget {
ProvidersPage({Key key}) : super(key: key);
@override
_ProvidersPageState createState() => _ProvidersPageState();
}
class _ProvidersPageState extends State<ProvidersPage> {
@override
Widget build(BuildContext context) {
2021-01-06 17:35:57 +00:00
var isReady = context.watch<AppConfigCubit>().state.isFullyInitilized;
2020-12-10 20:33:19 +00:00
final cards = ProviderType.values
2021-01-06 17:35:57 +00:00
.map((type) => _Card(
provider:
ProviderModel(state: StateType.uninitialized, type: type)))
2020-12-06 07:28:31 +00:00
.toList();
2020-12-03 16:52:53 +00:00
return Scaffold(
appBar: PreferredSize(
child: BrandHeader(title: 'Провайдеры'),
preferredSize: Size.fromHeight(52),
),
body: ListView(
padding: brandPagePadding2,
2021-01-06 17:35:57 +00:00
children: [
if (!isReady) ...[
NotReadyCard(),
SizedBox(height: 24),
],
...cards,
],
2020-12-03 16:52:53 +00:00
),
);
}
}
class _Card extends StatelessWidget {
2020-12-06 07:28:31 +00:00
const _Card({Key key, @required this.provider}) : super(key: key);
2020-12-03 16:52:53 +00:00
2020-12-06 07:28:31 +00:00
final ProviderModel provider;
2020-12-03 16:52:53 +00:00
@override
Widget build(BuildContext context) {
String title;
2020-12-06 07:28:31 +00:00
String message;
String stableText;
2021-01-27 18:33:00 +00:00
var appConfig = context.watch<AppConfigCubit>().state;
var domainName =
appConfig.isDomainFilled ? appConfig.cloudFlareDomain.domainName : '';
2020-12-03 16:52:53 +00:00
2020-12-06 07:28:31 +00:00
switch (provider.type) {
2020-12-10 20:33:19 +00:00
case ProviderType.server:
2020-12-06 07:28:31 +00:00
title = 'Сервер';
stableText = 'В норме';
2020-12-03 16:52:53 +00:00
break;
2020-12-10 20:33:19 +00:00
case ProviderType.domain:
2020-12-06 07:28:31 +00:00
title = 'Домен';
2021-01-27 18:33:00 +00:00
message = domainName;
2020-12-06 07:28:31 +00:00
stableText = 'Домен настроен';
2020-12-03 16:52:53 +00:00
break;
2020-12-10 20:33:19 +00:00
case ProviderType.backup:
2021-01-27 18:33:00 +00:00
// message = '22 янв 2021 14:30';
2020-12-06 07:28:31 +00:00
title = 'Резервное копирование';
stableText = 'В норме';
break;
}
return GestureDetector(
onTap: () => showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return _ProviderDetails(
provider: provider,
statusText: stableText,
);
},
),
child: BrandCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2021-01-06 17:35:57 +00:00
IconStatusMask(
2020-12-06 07:28:31 +00:00
status: provider.state,
child: Icon(provider.icon, size: 30, color: Colors.white),
),
SizedBox(height: 10),
2020-12-08 19:26:51 +00:00
BrandText.h2(title),
2020-12-06 07:28:31 +00:00
SizedBox(height: 10),
if (message != null) ...[
2020-12-08 19:26:51 +00:00
BrandText.body2(message),
2020-12-06 07:28:31 +00:00
SizedBox(height: 10),
],
2020-12-10 20:33:19 +00:00
if (provider.state == StateType.stable) BrandText.body2(stableText),
2020-12-06 07:28:31 +00:00
],
),
),
);
}
}
class _ProviderDetails extends StatelessWidget {
const _ProviderDetails({
Key key,
@required this.provider,
@required this.statusText,
}) : super(key: key);
final ProviderModel provider;
final String statusText;
@override
Widget build(BuildContext context) {
String title;
switch (provider.type) {
2020-12-10 20:33:19 +00:00
case ProviderType.server:
2020-12-06 07:28:31 +00:00
title = 'Сервер';
2020-12-03 16:52:53 +00:00
break;
2020-12-10 20:33:19 +00:00
case ProviderType.domain:
2020-12-06 07:28:31 +00:00
title = 'Домен';
2020-12-03 16:52:53 +00:00
break;
2020-12-10 20:33:19 +00:00
case ProviderType.backup:
2020-12-03 16:52:53 +00:00
title = 'Резервное копирование';
break;
}
2020-12-06 07:28:31 +00:00
return BrandModalSheet(
2020-12-10 20:33:19 +00:00
child: Navigator(
key: navigatorKey,
initialRoute: '/',
onGenerateRoute: (_) {
return materialRoute(
Column(
2020-12-06 07:28:31 +00:00
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2020-12-10 20:33:19 +00:00
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 4,
horizontal: 2,
),
child: PopupMenuButton<_PopupMenuItemType>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
onSelected: (_PopupMenuItemType result) {
switch (result) {
case _PopupMenuItemType.setting:
navigatorKey.currentState
.push(materialRoute(SettingsPage()));
break;
}
},
icon: Icon(Icons.more_vert),
itemBuilder: (BuildContext context) => [
PopupMenuItem<_PopupMenuItemType>(
value: _PopupMenuItemType.setting,
child: Container(
padding: EdgeInsets.only(left: 5),
child: Text('Настройки'),
),
),
],
),
),
2020-12-06 07:28:31 +00:00
),
2020-12-10 20:33:19 +00:00
Padding(
padding: brandPagePadding1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 13),
2021-01-06 17:35:57 +00:00
IconStatusMask(
2020-12-10 20:33:19 +00:00
status: provider.state,
child:
Icon(provider.icon, size: 40, color: Colors.white),
),
SizedBox(height: 10),
BrandText.h1(title),
SizedBox(height: 10),
BrandText.body1(statusText),
SizedBox(
height: 20,
),
Text('Статусы сервера и сервис провайдера и т.д.')
],
),
)
2020-12-06 07:28:31 +00:00
],
),
2020-12-10 20:33:19 +00:00
);
},
2020-12-03 16:52:53 +00:00
),
);
}
}
2020-12-06 07:28:31 +00:00
enum _PopupMenuItemType { setting }