Feat: Lagert die Versionsnummer in eine eigene Klasse aus und macht Settings zu einem StatelessWidget
This commit is contained in:
@@ -1,75 +1,37 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
|
||||||
|
|
||||||
import 'account_list.dart';
|
import 'account_list.dart';
|
||||||
import 'recurring_transaction_list.dart';
|
import 'recurring_transaction_list.dart';
|
||||||
|
import 'version_number.dart';
|
||||||
|
|
||||||
/// Eine Widget-Klasse, die die Einstellungsseite der Anwendung darstellt.
|
/// Eine Widget-Klasse, die die Einstellungsseite der Anwendung darstellt.
|
||||||
class Settings extends StatefulWidget {
|
class Settings extends StatelessWidget {
|
||||||
/// Erstellt eine neue Instanz dieser Klasse.
|
/// Erstellt eine neue Instanz dieser Klasse.
|
||||||
const Settings({super.key});
|
const Settings({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<Settings> createState() => _SettingsState();
|
Widget build(final BuildContext context) => const Scaffold(
|
||||||
}
|
|
||||||
|
|
||||||
class _SettingsState extends State<Settings> {
|
|
||||||
@override
|
|
||||||
Widget build(final BuildContext context) {
|
|
||||||
final ThemeData theme = Theme.of(context);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const Text(
|
Text(
|
||||||
'Einstellungen',
|
'Einstellungen',
|
||||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
|
|
||||||
const AccountList(),
|
AccountList(),
|
||||||
const SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
|
|
||||||
const RecurringTransactionList(),
|
RecurringTransactionList(),
|
||||||
const SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
_versionNumber(theme),
|
VersionNumber(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
Widget _versionNumber(final ThemeData theme) {
|
|
||||||
final Future<PackageInfo> packageInfo = PackageInfo.fromPlatform();
|
|
||||||
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.bottomLeft,
|
|
||||||
child: FutureBuilder(
|
|
||||||
future: packageInfo,
|
|
||||||
builder:
|
|
||||||
(
|
|
||||||
final BuildContext context,
|
|
||||||
final AsyncSnapshot<PackageInfo> 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();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
41
lib/Pages/Settings/version_number.dart
Normal file
41
lib/Pages/Settings/version_number.dart
Normal file
@@ -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<StatefulWidget> createState() => _VersionNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _VersionNumber extends State<VersionNumber> {
|
||||||
|
@override
|
||||||
|
Widget build(final BuildContext context) => Align(
|
||||||
|
alignment: Alignment.bottomLeft,
|
||||||
|
child: FutureBuilder(
|
||||||
|
future: PackageInfo.fromPlatform(),
|
||||||
|
builder:
|
||||||
|
(
|
||||||
|
final BuildContext context,
|
||||||
|
final AsyncSnapshot<PackageInfo> 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();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user