Add (for now) simple settings page to reset the exercise cache

This should be expanded later to allow to re-fetch all available exercises, etc.
This commit is contained in:
Roland Geider
2024-01-11 22:13:11 +01:00
parent 95eed706fb
commit e67d992385
32 changed files with 261 additions and 122 deletions

View File

@@ -57,16 +57,11 @@ class AboutEntry extends StatelessWidget {
}
}
class AboutPage extends StatefulWidget {
class AboutPage extends StatelessWidget {
static String routeName = '/AboutPage';
const AboutPage({super.key});
@override
State<AboutPage> createState() => _AboutPageState();
}
class _AboutPageState extends State<AboutPage> {
@override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;

View File

@@ -27,6 +27,7 @@ import 'package:wger/providers/user.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/form_screen.dart';
import 'package:wger/widgets/core/about.dart';
import 'package:wger/widgets/core/settings.dart';
import 'package:wger/widgets/user/forms.dart';
class MainAppBar extends StatelessWidget implements PreferredSizeWidget {
@@ -50,9 +51,7 @@ class MainAppBar extends StatelessWidget implements PreferredSizeWidget {
actions: [
TextButton(
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
onPressed: () {
Navigator.of(context).pop();
},
onPressed: () => Navigator.of(context).pop(),
),
],
contentPadding: EdgeInsets.zero,
@@ -63,22 +62,23 @@ class MainAppBar extends StatelessWidget implements PreferredSizeWidget {
//dense: true,
leading: const Icon(Icons.person),
title: Text(AppLocalizations.of(context).userProfile),
onTap: () {
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).userProfile,
UserProfileForm(context.read<UserProvider>().profile!),
),
);
},
onTap: () => Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).userProfile,
UserProfileForm(context.read<UserProvider>().profile!),
),
),
),
ListTile(
leading: const Icon(Icons.settings),
onTap: () => Navigator.of(context).pushNamed(SettingsPage.routeName),
title: Text(AppLocalizations.of(context).settingsTitle),
),
ListTile(
leading: const Icon(Icons.info),
onTap: () {
Navigator.of(context).pushNamed(AboutPage.routeName);
},
onTap: () => Navigator.of(context).pushNamed(AboutPage.routeName),
title: Text(AppLocalizations.of(context).aboutPageTitle),
),
const Divider(),

View File

@@ -0,0 +1,106 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wger Workout Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//import 'package:drift/drift.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:wger/helpers/misc.dart';
import 'package:wger/providers/exercises.dart';
class AboutEntry extends StatelessWidget {
final String url;
final String title;
final String content;
final Icon icon;
const AboutEntry({
required this.title,
required this.content,
required this.url,
required this.icon,
});
@override
Widget build(BuildContext context) {
return ListTile(
leading: icon,
title: Text(title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(content),
Text(
url,
style: const TextStyle(color: Colors.blue),
),
],
),
contentPadding: EdgeInsets.zero,
onTap: () async => launchURL(url, context),
);
}
}
class SettingsPage extends StatefulWidget {
static String routeName = '/SettingsPage';
const SettingsPage({super.key});
@override
State<SettingsPage> createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
@override
Widget build(BuildContext context) {
final exerciseProvider = Provider.of<ExercisesProvider>(context, listen: false);
final today = DateTime.now();
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context).settingsTitle),
),
body: ListView(
children: [
ListTile(
// leading: const Icon(Icons.cached),
title: Text(AppLocalizations.of(context).settingsCacheTitle),
subtitle: Text(AppLocalizations.of(context).settingsCacheDescription),
trailing: IconButton(
key: const ValueKey('cacheIcon'),
icon: const Icon(Icons.cached),
onPressed: () async {
await exerciseProvider.clearAllCachesAndPrefs();
if (context.mounted) {
final snackBar = SnackBar(
content: Text(AppLocalizations.of(context).settingsCacheDeletedSnackbar),
);
// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
},
),
)
],
));
}
}