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

172 lines
4.8 KiB
Dart
Raw Normal View History

2021-04-10 03:04:23 +00:00
part of 'server_details.dart';
class _TextDetails extends StatelessWidget {
const _TextDetails({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var details = context.watch<ServerDetailsCubit>().state;
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) {
var data = details.serverInfo;
var checkTime = details.checkTime;
return Column(
children: [
Center(child: BrandText.h3('providers.server.bottom_sheet.2'.tr())),
SizedBox(height: 10),
Table(
columnWidths: {
0: FractionColumnWidth(.5),
1: FractionColumnWidth(.5),
},
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
children: [
2021-09-22 22:25:47 +00:00
getRowTitle('Last check:'),
2021-04-10 03:04:23 +00:00
getRowValue(formater.format(checkTime)),
],
),
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(
'${data.status.toString().split('.')[1].toUpperCase()}',
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(
'${data.serverType.prices[1].monthly.toString()}',
),
],
),
TableRow(
children: [
getRowTitle('Price hourly:'),
getRowValue(
'${data.serverType.prices[1].hourly.toString()}',
),
],
),
],
),
SizedBox(height: 30),
Center(child: BrandText.h3('providers.server.bottom_sheet.3'.tr())),
SizedBox(height: 10),
Table(
columnWidths: {
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(
'${data.location.country}',
),
],
),
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),
],
),
],
),
SizedBox(height: 20),
],
);
} else {
throw Exception('wrong state');
}
}
Widget getRowTitle(String title) {
return Padding(
padding: const EdgeInsets.only(right: 10),
child: BrandText.h5(
title,
textAlign: TextAlign.right,
),
);
}
Widget getRowValue(String title, {bool isBold = false}) {
return BrandText.body1(
title,
style: isBold
? TextStyle(
fontWeight: NamedFontWeight.demiBold,
)
: null,
);
}
}
class _TempMessage extends StatelessWidget {
const _TempMessage({
Key? key,
required this.message,
}) : super(key: key);
final String message;
@override
Widget build(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height - 100,
child: Center(
child: BrandText.body2(message),
),
);
}
}
final DateFormat formater = DateFormat('HH:mm:ss');