Merge branch 'development' into enhancement/18-navbar-alignment
This commit is contained in:
@@ -17,12 +17,7 @@ class CustomNavigationBar extends StatefulWidget {
|
||||
class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
with SingleTickerProviderStateMixin {
|
||||
int currentIndex = 0;
|
||||
final List<Widget> tabs = [
|
||||
const HomeView(),
|
||||
const GameHistoryView(),
|
||||
const GroupsView(),
|
||||
const StatisticsView(),
|
||||
];
|
||||
int tabKeyCount = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -31,6 +26,22 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Pretty ugly but works
|
||||
final List<Widget> tabs = [
|
||||
KeyedSubtree(key: ValueKey('home_$tabKeyCount'), child: const HomeView()),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('games_$tabKeyCount'),
|
||||
child: const GameHistoryView(),
|
||||
),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('groups_$tabKeyCount'),
|
||||
child: const GroupsView(),
|
||||
),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('stats_$tabKeyCount'),
|
||||
child: const StatisticsView(),
|
||||
),
|
||||
];
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
@@ -42,10 +53,15 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
scrolledUnderElevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const SettingsView()),
|
||||
),
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const SettingsView()),
|
||||
);
|
||||
setState(() {
|
||||
tabKeyCount++;
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.settings),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,13 +1,191 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:game_tracker/core/enums.dart';
|
||||
import 'package:game_tracker/presentation/widgets/tiles/settings_list_tile.dart';
|
||||
import 'package:game_tracker/services/data_transfer_service.dart';
|
||||
|
||||
class SettingsView extends StatelessWidget {
|
||||
class SettingsView extends StatefulWidget {
|
||||
const SettingsView({super.key});
|
||||
|
||||
@override
|
||||
State<SettingsView> createState() => _SettingsViewState();
|
||||
}
|
||||
|
||||
class _SettingsViewState extends State<SettingsView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Einstellungen')),
|
||||
body: const Center(child: Text('Settings View')),
|
||||
appBar: AppBar(backgroundColor: CustomTheme.backgroundColor),
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
body: LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) =>
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 0, 24, 10),
|
||||
child: Text(
|
||||
textAlign: TextAlign.start,
|
||||
'Menu',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
|
||||
child: Text(
|
||||
textAlign: TextAlign.start,
|
||||
'Settings',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SettingsListTile(
|
||||
title: 'Export data',
|
||||
icon: Icons.upload_outlined,
|
||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
onPressed: () async {
|
||||
final String json =
|
||||
await DataTransferService.getAppDataAsJson(context);
|
||||
final result = await DataTransferService.exportData(
|
||||
json,
|
||||
'game_tracker-data',
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showExportSnackBar(context: context, result: result);
|
||||
},
|
||||
),
|
||||
SettingsListTile(
|
||||
title: 'Import data',
|
||||
icon: Icons.download_outlined,
|
||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
onPressed: () async {
|
||||
final result = await DataTransferService.importData(
|
||||
context,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showImportSnackBar(context: context, result: result);
|
||||
},
|
||||
),
|
||||
SettingsListTile(
|
||||
title: 'Delete all data',
|
||||
icon: Icons.download_outlined,
|
||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
onPressed: () {
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete all data?'),
|
||||
content: const Text('This can\'t be undone'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Abbrechen'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Löschen'),
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) {
|
||||
if (confirmed == true && context.mounted) {
|
||||
DataTransferService.deleteAllData(context);
|
||||
showSnackbar(
|
||||
context: context,
|
||||
message: 'Daten erfolgreich gelöscht',
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Displays a snackbar based on the import result.
|
||||
///
|
||||
/// [context] The BuildContext to show the snackbar in.
|
||||
/// [result] The result of the import operation.
|
||||
void showImportSnackBar({
|
||||
required BuildContext context,
|
||||
required ImportResult result,
|
||||
}) {
|
||||
switch (result) {
|
||||
case ImportResult.success:
|
||||
showSnackbar(context: context, message: 'Data successfully imported');
|
||||
case ImportResult.invalidSchema:
|
||||
showSnackbar(context: context, message: 'Invalid Schema');
|
||||
case ImportResult.fileReadError:
|
||||
showSnackbar(context: context, message: 'Error reading file');
|
||||
case ImportResult.canceled:
|
||||
showSnackbar(context: context, message: 'Import canceled');
|
||||
case ImportResult.formatException:
|
||||
showSnackbar(
|
||||
context: context,
|
||||
message: 'Format Exception (see console)',
|
||||
);
|
||||
case ImportResult.unknownException:
|
||||
showSnackbar(
|
||||
context: context,
|
||||
message: 'Unknown Exception (see console)',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Displays a snackbar based on the export result.
|
||||
///
|
||||
/// [context] The BuildContext to show the snackbar in.
|
||||
/// [result] The result of the export operation.
|
||||
void showExportSnackBar({
|
||||
required BuildContext context,
|
||||
required ExportResult result,
|
||||
}) {
|
||||
switch (result) {
|
||||
case ExportResult.success:
|
||||
showSnackbar(context: context, message: 'Data successfully exported');
|
||||
case ExportResult.canceled:
|
||||
showSnackbar(context: context, message: 'Export canceled');
|
||||
case ExportResult.unknownException:
|
||||
showSnackbar(
|
||||
context: context,
|
||||
message: 'Unknown Exception (see console)',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Displays a snackbar with the given message and optional action.
|
||||
///
|
||||
/// [context] The BuildContext to show the snackbar in.
|
||||
/// [message] The message to display in the snackbar.
|
||||
/// [duration] The duration for which the snackbar is displayed.
|
||||
/// [action] An optional callback function to execute when the action button is pressed.
|
||||
void showSnackbar({
|
||||
required BuildContext context,
|
||||
required String message,
|
||||
Duration duration = const Duration(seconds: 3),
|
||||
VoidCallback? action,
|
||||
}) {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
messenger.hideCurrentSnackBar();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message, style: const TextStyle(color: Colors.white)),
|
||||
backgroundColor: CustomTheme.onBoxColor,
|
||||
duration: duration,
|
||||
action: action != null
|
||||
? SnackBarAction(label: 'Rückgängig', onPressed: action)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user