selfprivacy.org.app/lib/ui/pages/server_details/text_details.dart

164 lines
4.8 KiB
Dart
Raw Normal View History

part of 'server_details_screen.dart';
2021-04-10 03:04:23 +00:00
class _TextDetails extends StatelessWidget {
@override
Widget build(final BuildContext context) {
final details = context.watch<ServerDetailsCubit>().state;
2021-04-10 03:04:23 +00:00
if (details is ServerDetailsLoading || details is ServerDetailsInitial) {
return _TempMessage(message: 'basis.loading'.tr());
} else if (details is ServerDetailsNotReady) {
return _TempMessage(message: 'basis.no_data'.tr());
} else if (details is Loaded) {
final data = details.serverInfo;
final checkTime = details.checkTime;
2021-04-10 03:04:23 +00:00
return Column(
children: [
Center(child: BrandText.h3('providers.server.bottom_sheet.2'.tr())),
2022-05-24 18:55:39 +00:00
const SizedBox(height: 10),
2021-04-10 03:04:23 +00:00
Table(
2022-05-24 18:55:39 +00:00
columnWidths: const {
2021-04-10 03:04:23 +00:00
0: FractionColumnWidth(.5),
1: FractionColumnWidth(.5),
},
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Last check:'),
2022-02-16 07:28:29 +00:00
getRowValue(formatter.format(checkTime)),
2021-04-10 03:04:23 +00:00
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Server Id:'),
2021-04-10 03:04:23 +00:00
getRowValue(data.id.toString()),
],
),
TableRow(
children: [
getRowTitle('Status:'),
getRowValue(
2022-05-24 18:55:39 +00:00
data.status.toString().split('.')[1].toUpperCase(),
2021-04-10 03:04:23 +00:00
isBold: true,
),
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('CPU:'),
2021-04-10 03:04:23 +00:00
getRowValue(
data.serverType.cores.toString(),
),
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Memory:'),
2021-04-10 03:04:23 +00:00
getRowValue(
'${data.serverType.memory.toString()} GB',
),
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Disk Local:'),
2021-04-10 03:04:23 +00:00
getRowValue(
'${data.serverType.disk.toString()} GB',
),
],
),
TableRow(
children: [
getRowTitle('Price monthly:'),
getRowValue(
2022-05-24 18:55:39 +00:00
data.serverType.prices[1].monthly.toString(),
2021-04-10 03:04:23 +00:00
),
],
),
TableRow(
children: [
getRowTitle('Price hourly:'),
getRowValue(
2022-05-24 18:55:39 +00:00
data.serverType.prices[1].hourly.toString(),
2021-04-10 03:04:23 +00:00
),
],
),
],
),
2022-05-24 18:55:39 +00:00
const SizedBox(height: 30),
2021-04-10 03:04:23 +00:00
Center(child: BrandText.h3('providers.server.bottom_sheet.3'.tr())),
2022-05-24 18:55:39 +00:00
const SizedBox(height: 10),
2021-04-10 03:04:23 +00:00
Table(
2022-05-24 18:55:39 +00:00
columnWidths: const {
2021-04-10 03:04:23 +00:00
0: FractionColumnWidth(.5),
1: FractionColumnWidth(.5),
},
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Country:'),
2021-04-10 03:04:23 +00:00
getRowValue(
2022-05-24 18:55:39 +00:00
data.location.country,
2021-04-10 03:04:23 +00:00
),
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('City:'),
2021-04-10 03:04:23 +00:00
getRowValue(data.location.city),
],
),
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Description:'),
2021-04-10 03:04:23 +00:00
getRowValue(data.location.description),
],
),
],
),
2022-05-24 18:55:39 +00:00
const SizedBox(height: 20),
2021-04-10 03:04:23 +00:00
],
);
} else {
throw Exception('wrong state');
}
}
Widget getRowTitle(final String title) => Padding(
padding: const EdgeInsets.only(right: 10),
child: BrandText.h5(
title,
textAlign: TextAlign.right,
),
);
2021-04-10 03:04:23 +00:00
Widget getRowValue(final String title, {final bool isBold = false}) =>
BrandText.body1(
title,
style: isBold
? const TextStyle(
fontWeight: NamedFontWeight.demiBold,
)
: null,
);
2021-04-10 03:04:23 +00:00
}
class _TempMessage extends StatelessWidget {
const _TempMessage({
required this.message,
});
2021-04-10 03:04:23 +00:00
final String message;
@override
Widget build(final BuildContext context) => SizedBox(
height: MediaQuery.of(context).size.height - 100,
child: Center(
child: BrandText.body2(message),
),
);
2021-04-10 03:04:23 +00:00
}
2022-02-16 07:28:29 +00:00
final DateFormat formatter = DateFormat('HH:mm:ss');