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-09-18 22:11:26 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_volumes/server_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';
|
2022-09-16 11:28:17 +00:00
|
|
|
import 'package:selfprivacy/logic/models/disk_status.dart';
|
2022-09-18 16:31:22 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/root_route.dart';
|
|
|
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
2022-08-03 02:25:33 +00:00
|
|
|
|
|
|
|
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-09-06 10:27:18 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2022-09-18 22:11:26 +00:00
|
|
|
minSize = widget.diskVolumeToResize.sizeTotal + DiskSize.fromGibibyte(3);
|
2022-09-06 10:27:18 +00:00
|
|
|
_currentSliderGbValue = minSize.gibibyte;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:46:29 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_sizeController.dispose();
|
|
|
|
_priceController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2022-08-24 05:35:49 +00:00
|
|
|
bool _isError = false;
|
2022-08-03 02:25:33 +00:00
|
|
|
|
2022-09-06 10:27:18 +00:00
|
|
|
late double _currentSliderGbValue;
|
2022-08-03 02:25:33 +00:00
|
|
|
double _euroPerGb = 1.0;
|
|
|
|
|
2022-09-06 10:27:18 +00:00
|
|
|
final DiskSize maxSize = const DiskSize(byte: 500000000000);
|
|
|
|
late DiskSize minSize;
|
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-09-06 09:17:44 +00:00
|
|
|
_isError = minSize.gibibyte > _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,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'storage.extending_volume_title'.tr(),
|
|
|
|
heroSubtitle: 'storage.extending_volume_description'.tr(),
|
2022-08-24 05:35:49 +00:00
|
|
|
children: const [
|
|
|
|
SizedBox(height: 16),
|
2022-09-06 10:27:18 +00:00
|
|
|
Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
2022-08-24 05:35:49 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
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))
|
2022-08-29 18:43:42 +00:00
|
|
|
.toStringAsFixed(2);
|
2022-09-06 11:03:21 +00:00
|
|
|
minSize =
|
2022-09-18 22:11:26 +00:00
|
|
|
widget.diskVolumeToResize.sizeTotal + DiskSize.fromGibibyte(3);
|
2022-08-24 05:35:49 +00:00
|
|
|
if (_currentSliderGbValue < 0) {
|
2022-09-06 09:17:44 +00:00
|
|
|
_currentSliderGbValue = minSize.gibibyte;
|
2022-08-24 05:35:49 +00:00
|
|
|
}
|
2022-08-03 02:25:33 +00:00
|
|
|
|
2022-09-18 22:11:26 +00:00
|
|
|
final isAlreadyResizing =
|
|
|
|
context.watch<ApiProviderVolumeCubit>().state.isResizing;
|
|
|
|
|
2022-08-03 02:25:33 +00:00
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'storage.extending_volume_title'.tr(),
|
|
|
|
heroSubtitle: 'storage.extending_volume_description'.tr(),
|
2022-08-03 02:25:33 +00:00
|
|
|
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,
|
2022-10-03 23:32:35 +00:00
|
|
|
labelText: 'storage.size'.tr(),
|
2022-08-24 05:35:49 +00:00
|
|
|
),
|
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,
|
2022-10-03 23:32:35 +00:00
|
|
|
labelText: 'storage.euro'.tr(),
|
2022-08-24 05:35:49 +00:00
|
|
|
),
|
2022-08-03 02:25:33 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Slider(
|
2022-09-06 09:17:44 +00:00
|
|
|
min: minSize.gibibyte,
|
2022-08-24 05:35:49 +00:00
|
|
|
value: _currentSliderGbValue,
|
2022-09-06 09:17:44 +00:00
|
|
|
max: maxSize.gibibyte,
|
2022-08-03 02:25:33 +00:00
|
|
|
onChanged: (final double value) {
|
|
|
|
setState(() {
|
|
|
|
_currentSliderGbValue = value;
|
|
|
|
_updateErrorStatuses();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
FilledButton(
|
2022-10-03 23:32:35 +00:00
|
|
|
title: 'storage.extend_volume_button.title'.tr(),
|
2022-09-18 16:26:55 +00:00
|
|
|
onPressed: _isError
|
|
|
|
? null
|
2022-09-18 16:31:22 +00:00
|
|
|
: () {
|
|
|
|
context.read<ApiProviderVolumeCubit>().resizeVolume(
|
|
|
|
widget.diskVolumeToResize,
|
|
|
|
_currentSliderGbValue.round(),
|
2022-09-18 22:11:26 +00:00
|
|
|
context.read<ApiServerVolumeCubit>().reload,
|
2022-09-18 16:31:22 +00:00
|
|
|
);
|
|
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
|
|
materialRoute(const RootPage()),
|
|
|
|
(final predicate) => false,
|
|
|
|
);
|
|
|
|
},
|
2022-09-18 22:11:26 +00:00
|
|
|
disabled: _isError || isAlreadyResizing,
|
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),
|
2022-10-03 23:32:35 +00:00
|
|
|
Text('storage.extending_volume_price_info'.tr()),
|
2022-08-03 02:25:33 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|