Skip to content

Commit

Permalink
Add listtile for backup setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
braniii committed Mar 29, 2024
1 parent e0fe9c3 commit 6d71ad4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/lib/core/traleNotifier.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:intl/date_time_patterns.dart';
import 'package:intl/intl.dart';
import 'package:trale/core/backupInterval.dart';
import 'package:trale/core/interpolation.dart';
import 'package:trale/core/language.dart';
import 'package:trale/core/measurementDatabase.dart';
Expand Down Expand Up @@ -59,7 +60,17 @@ class TraleNotifier with ChangeNotifier {
prefs.zoomLevel = newLevel;
notifyListeners();
}
}
}

/// get backup frequency
BackupInterval get backupInterval => prefs.backupInterval;
/// setter backup frequency
set backupInterval(BackupInterval newInterval) {
if (backupInterval != newInterval) {
prefs.backupInterval = newInterval;
notifyListeners();
}
}

/// getter
Language get language => prefs.language;
Expand Down
4 changes: 4 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"@monthly": {
"description": "Frequency of backup interval"
},
"backupInterval": "Backups",
"@backupInterval": {
"description": "Frequency of backup interval"
},
"stats": "Statistics",
"@stats": {
"description": "Header for statistics section"
Expand Down
46 changes: 46 additions & 0 deletions app/lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:intl/intl.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:share_plus/share_plus.dart';
import 'package:trale/core/backupInterval.dart';

import 'package:trale/core/icons.dart';
import 'package:trale/core/interpolation.dart';
Expand Down Expand Up @@ -484,6 +485,50 @@ class UnitsListTile extends StatelessWidget {
}
}

/// ListTile for changing units settings
class BackupIntervalListTile extends StatelessWidget {
/// constructor
const BackupIntervalListTile({super.key});

@override
Widget build(BuildContext context) {
return ListTile(
contentPadding: EdgeInsets.symmetric(
horizontal: 2 * TraleTheme.of(context)!.padding,
vertical: 0.5 * TraleTheme.of(context)!.padding,
),
title: AutoSizeText(
AppLocalizations.of(context)!.backupInterval,
style: Theme.of(context).textTheme.bodyLarge,
maxLines: 1,
),
trailing: DropdownMenu<BackupInterval>(
initialSelection: Provider.of<TraleNotifier>(context).backupInterval,
label: AutoSizeText(
AppLocalizations.of(context)!.backupInterval,
style: Theme.of(context).textTheme.bodyLarge,
maxLines: 1,
),
dropdownMenuEntries: <DropdownMenuEntry<BackupInterval>>[
for (final BackupInterval interval in BackupInterval.values)
DropdownMenuEntry<BackupInterval>(
value: interval,
label: interval.name,
)
],
onSelected: (BackupInterval? newInterval) async {
if (newInterval != null) {
Provider.of<TraleNotifier>(
context, listen: false
).backupInterval = newInterval;
}
},
),
);
}
}



/// ListTile for changing dark mode settings
class DarkModeListTile extends StatelessWidget {
Expand Down Expand Up @@ -751,6 +796,7 @@ class _Settings extends State<Settings> {
const LanguageListTile(),
const UnitsListTile(),
const InterpolationListTile(),
const BackupIntervalListTile(),
Divider(
height: 2 * TraleTheme.of(context)!.padding,
),
Expand Down

0 comments on commit 6d71ad4

Please sign in to comment.