From f765ba6268ebb13b55fa35a968c0d57566951f8d Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Mon, 29 Dec 2025 00:09:15 +0100 Subject: [PATCH] Feat: Lagert die Versionsnummer in eine eigene Klasse aus und macht Settings zu einem StatelessWidget --- lib/Pages/Settings/settings.dart | 82 +++++++------------------- lib/Pages/Settings/version_number.dart | 41 +++++++++++++ 2 files changed, 63 insertions(+), 60 deletions(-) create mode 100644 lib/Pages/Settings/version_number.dart diff --git a/lib/Pages/Settings/settings.dart b/lib/Pages/Settings/settings.dart index 2961a38..edf535a 100644 --- a/lib/Pages/Settings/settings.dart +++ b/lib/Pages/Settings/settings.dart @@ -1,75 +1,37 @@ import 'package:flutter/material.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'account_list.dart'; import 'recurring_transaction_list.dart'; +import 'version_number.dart'; /// Eine Widget-Klasse, die die Einstellungsseite der Anwendung darstellt. -class Settings extends StatefulWidget { +class Settings extends StatelessWidget { /// Erstellt eine neue Instanz dieser Klasse. const Settings({super.key}); @override - State createState() => _SettingsState(); -} + Widget build(final BuildContext context) => const Scaffold( + body: SafeArea( + child: Padding( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Einstellungen', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + SizedBox(height: 24), -class _SettingsState extends State { - @override - Widget build(final BuildContext context) { - final ThemeData theme = Theme.of(context); + AccountList(), + SizedBox(height: 24), - return Scaffold( - body: SafeArea( - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Einstellungen', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const SizedBox(height: 24), - - const AccountList(), - const SizedBox(height: 24), - - const RecurringTransactionList(), - const SizedBox(height: 8), - _versionNumber(theme), - ], - ), + RecurringTransactionList(), + SizedBox(height: 8), + VersionNumber(), + ], ), ), - ); - } - - Widget _versionNumber(final ThemeData theme) { - final Future packageInfo = PackageInfo.fromPlatform(); - - return Align( - alignment: Alignment.bottomLeft, - child: FutureBuilder( - future: packageInfo, - builder: - ( - final BuildContext context, - final AsyncSnapshot snapshot, - ) { - if (snapshot.hasData) { - return Text( - '${snapshot.data?.version}+${snapshot.data?.buildNumber}', - style: theme.textTheme.bodySmall?.copyWith( - color: theme.colorScheme.onSurface.withAlpha( - (0.6 * 255).round(), - ), - ), - ); - } else { - return const CircularProgressIndicator(); - } - }, - ), - ); - } + ), + ); } diff --git a/lib/Pages/Settings/version_number.dart b/lib/Pages/Settings/version_number.dart new file mode 100644 index 0000000..96a7e0d --- /dev/null +++ b/lib/Pages/Settings/version_number.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +/// Ein Widget mit der aktuellen Versionsnummer +class VersionNumber extends StatefulWidget { + /// Erstellt eine neue Instanz dieser Klasse + const VersionNumber({super.key}); + + @override + State createState() => _VersionNumber(); +} + +class _VersionNumber extends State { + @override + Widget build(final BuildContext context) => Align( + alignment: Alignment.bottomLeft, + child: FutureBuilder( + future: PackageInfo.fromPlatform(), + builder: + ( + final BuildContext context, + final AsyncSnapshot snapshot, + ) { + final ThemeData theme = Theme.of(context); + + if (snapshot.hasData) { + return Text( + '${snapshot.data?.version}+${snapshot.data?.buildNumber}', + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurface.withAlpha( + (0.6 * 255).round(), + ), + ), + ); + } else { + return const CircularProgressIndicator(); + } + }, + ), + ); +}