2022-08-03 02:25:33 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
2022-08-24 23:45:02 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_cubit.dart';
|
2022-08-24 05:35:49 +00:00
|
|
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
2022-08-03 02:25:33 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
|
|
|
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
|
|
|
|
|
|
|
class ExtendingVolumePage extends StatefulWidget {
|
2022-08-24 05:35:49 +00:00
|
|
|
const ExtendingVolumePage({
|
|
|
|
required this.diskVolumeToResize,
|
|
|
|
required this.diskStatus,
|
|
|
|
final super.key,
|
|
|
|
});
|
2022-08-03 02:25:33 +00:00
|
|
|
|
2022-08-24 05:35:49 +00:00
|
|
|
final DiskVolume diskVolumeToResize;
|
|
|
|
final DiskStatus diskStatus;
|
2022-08-03 02:25:33 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<ExtendingVolumePage> createState() => _ExtendingVolumePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
2022-08-24 05:35:49 +00:00
|
|
|
bool _isError = false;
|
2022-08-03 02:25:33 +00:00
|
|
|
|
2022-08-24 05:35:49 +00:00
|
|
|
double _currentSliderGbValue = -1;
|
2022-08-03 02:25:33 +00:00
|
|
|
double _euroPerGb = 1.0;
|
|
|
|
|
2022-08-24 05:35:49 +00:00
|
|
|
final DiskSize maxSize = DiskSize(byte: 500000000000);
|
|
|
|
DiskSize minSize = DiskSize();
|
2022-08-03 02:25:33 +00:00
|
|
|
|
|
|
|
final TextEditingController _sizeController = TextEditingController();
|
2022-08-24 05:35:49 +00:00
|
|
|
final TextEditingController _priceController = TextEditingController();
|
2022-08-03 02:25:33 +00:00
|
|
|
|
|
|
|
void _updateErrorStatuses() {
|
2022-08-24 05:35:49 +00:00
|
|
|
_isError = minSize.asGb() > _currentSliderGbValue;
|
2022-08-03 02:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => FutureBuilder(
|
2022-08-24 23:45:02 +00:00
|
|
|
future: context.read<ApiProviderVolumeCubit>().getPricePerGb(),
|
2022-08-03 02:25:33 +00:00
|
|
|
builder: (
|
|
|
|
final BuildContext context,
|
|
|
|
final AsyncSnapshot<void> snapshot,
|
|
|
|
) {
|
2022-08-24 05:35:49 +00:00
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
|
|
|
heroTitle: 'providers.storage.extending_volume_title'.tr(),
|
|
|
|
heroSubtitle:
|
|
|
|
'providers.storage.extending_volume_description'.tr(),
|
|
|
|
children: const [
|
|
|
|
SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2022-08-03 02:25:33 +00:00
|
|
|
_euroPerGb = snapshot.data as double;
|
2022-08-24 05:35:49 +00:00
|
|
|
_sizeController.text = _currentSliderGbValue.truncate().toString();
|
2022-08-03 02:25:33 +00:00
|
|
|
_priceController.text =
|
2022-08-24 05:35:49 +00:00
|
|
|
(_euroPerGb * double.parse(_sizeController.text))
|
|
|
|
.toStringAsPrecision(2);
|
|
|
|
minSize = widget.diskVolumeToResize.sizeTotal;
|
|
|
|
if (_currentSliderGbValue < 0) {
|
|
|
|
_currentSliderGbValue = minSize.asGb();
|
|
|
|
}
|
2022-08-03 02:25:33 +00:00
|
|
|
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
|
|
|
heroTitle: 'providers.storage.extending_volume_title'.tr(),
|
|
|
|
heroSubtitle: 'providers.storage.extending_volume_description'.tr(),
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Row(
|
2022-08-24 05:35:49 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2022-08-03 02:25:33 +00:00
|
|
|
children: [
|
2022-08-24 05:35:49 +00:00
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 130),
|
|
|
|
child: TextField(
|
|
|
|
readOnly: true,
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
enabled: true,
|
|
|
|
controller: _sizeController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
errorText: _isError ? ' ' : null,
|
|
|
|
labelText: 'providers.storage.size'.tr(),
|
|
|
|
),
|
2022-08-03 02:25:33 +00:00
|
|
|
),
|
|
|
|
),
|
2022-08-24 05:35:49 +00:00
|
|
|
const SizedBox(width: 16),
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 130),
|
|
|
|
child: TextField(
|
|
|
|
readOnly: true,
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
enabled: true,
|
|
|
|
controller: _priceController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
errorText: _isError ? ' ' : null,
|
|
|
|
labelText: 'providers.storage.euro'.tr(),
|
|
|
|
),
|
2022-08-03 02:25:33 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Slider(
|
2022-08-24 05:35:49 +00:00
|
|
|
min: minSize.asGb(),
|
|
|
|
value: _currentSliderGbValue,
|
|
|
|
max: maxSize.asGb(),
|
2022-08-03 02:25:33 +00:00
|
|
|
onChanged: (final double value) {
|
|
|
|
setState(() {
|
|
|
|
_currentSliderGbValue = value;
|
|
|
|
_updateErrorStatuses();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
FilledButton(
|
2022-08-24 05:35:49 +00:00
|
|
|
title: 'providers.storage.extend_volume_button.title'.tr(),
|
2022-08-03 02:25:33 +00:00
|
|
|
onPressed: null,
|
2022-08-24 05:35:49 +00:00
|
|
|
disabled: _isError,
|
2022-08-03 02:25:33 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
const Divider(
|
|
|
|
height: 1.0,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2022-08-24 05:35:49 +00:00
|
|
|
const Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Icon(
|
|
|
|
Icons.info_outlined,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
2022-08-03 02:25:33 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text('providers.storage.extending_volume_price_info'.tr()),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|