selfprivacy.org.app/lib/ui/pages/backups/change_period_modal.dart

106 lines
3.1 KiB
Dart
Raw Normal View History

2023-07-02 15:24:07 +00:00
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:selfprivacy/logic/bloc/backups/backups_bloc.dart';
import 'package:selfprivacy/logic/bloc/server_jobs/server_jobs_bloc.dart';
2024-01-31 10:57:12 +00:00
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
2023-07-02 15:24:07 +00:00
import 'package:selfprivacy/utils/extensions/duration.dart';
class ChangeAutobackupsPeriodModal extends StatefulWidget {
const ChangeAutobackupsPeriodModal({
required this.scrollController,
super.key,
});
final ScrollController scrollController;
@override
State<ChangeAutobackupsPeriodModal> createState() =>
_ChangeAutobackupsPeriodModalState();
}
class _ChangeAutobackupsPeriodModalState
extends State<ChangeAutobackupsPeriodModal> {
Duration? selectedPeriod;
static const List<Duration> autobackupPeriods = [
Duration(hours: 12),
Duration(days: 1),
Duration(days: 2),
Duration(days: 3),
Duration(days: 7),
];
// Set initial period to the one currently set
@override
void initState() {
super.initState();
selectedPeriod = context.read<BackupsBloc>().state.autobackupPeriod;
2023-07-02 15:24:07 +00:00
}
@override
Widget build(final BuildContext context) {
final Duration? initialAutobackupPeriod =
context.watch<BackupsBloc>().state.autobackupPeriod;
2023-07-02 15:24:07 +00:00
return ListView(
controller: widget.scrollController,
padding: const EdgeInsets.all(16),
children: [
const SizedBox(height: 16),
Text(
'backup.autobackup_period_title'.tr(),
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
// Select all services tile
RadioListTile<Duration?>(
onChanged: (final Duration? value) {
setState(() {
selectedPeriod = value;
});
},
title: Text(
'backup.autobackup_period_disable'.tr(),
),
value: null,
groupValue: selectedPeriod,
),
const Divider(
height: 1.0,
),
...autobackupPeriods.map(
(final Duration period) => RadioListTile<Duration?>(
onChanged: (final Duration? value) {
setState(() {
selectedPeriod = value;
});
},
title: Text(
'backup.autobackup_period_every'.tr(
namedArgs: {'period': period.toPrettyString(context.locale)},
),
),
value: period,
groupValue: selectedPeriod,
),
),
const SizedBox(height: 16),
// Create backup button
FilledButton(
onPressed: selectedPeriod == initialAutobackupPeriod
? null
: () {
context
.read<BackupsBloc>()
.add(SetAutobackupPeriod(selectedPeriod));
2023-07-02 15:24:07 +00:00
Navigator.of(context).pop();
},
child: Text(
'backup.autobackup_set_period'.tr(),
),
),
],
);
}
}