Simplify theme management, integrate ToggleButtons for theme selection, and enhance settings view structure.

This commit is contained in:
2025-09-26 20:11:10 +02:00
parent 4a4f10d533
commit ece3c333eb
6 changed files with 204 additions and 141 deletions

View File

@@ -14,6 +14,8 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
B4938A305FA6CC3F11C2B360 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98DFFE772CFE93B4BC46C9AD /* Pods_Runner.framework */; };
F56F832F7C6FCA441762B03C /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7EF9C1B14BC3FAD925D13606 /* Pods_RunnerTests.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -45,9 +47,13 @@
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
6A9A17806BE49FD019B0DB41 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
6ACEEED8BD84FC00007A9E9B /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7081090C6E22D91B12A63D65 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7EF9C1B14BC3FAD925D13606 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -55,13 +61,26 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
98DFFE772CFE93B4BC46C9AD /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A4BF9D95DC3AEA839D03722B /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = "<group>"; };
F43503EB41EB8364AAA6165B /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
FA7CB1383A647C2D24B46844 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
0D70F078EEFD111D42BA3C5C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F56F832F7C6FCA441762B03C /* Pods_RunnerTests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
97C146EB1CF9000F007C117D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B4938A305FA6CC3F11C2B360 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -94,6 +113,8 @@
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
331C8082294A63A400263BE5 /* RunnerTests */,
DA4F95BDE713E57F5B145DB1 /* Pods */,
CA36834C8F3CDFB7D8CB9171 /* Frameworks */,
);
sourceTree = "<group>";
};
@@ -121,6 +142,29 @@
path = Runner;
sourceTree = "<group>";
};
CA36834C8F3CDFB7D8CB9171 /* Frameworks */ = {
isa = PBXGroup;
children = (
98DFFE772CFE93B4BC46C9AD /* Pods_Runner.framework */,
7EF9C1B14BC3FAD925D13606 /* Pods_RunnerTests.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
DA4F95BDE713E57F5B145DB1 /* Pods */ = {
isa = PBXGroup;
children = (
6ACEEED8BD84FC00007A9E9B /* Pods-Runner.debug.xcconfig */,
F43503EB41EB8364AAA6165B /* Pods-Runner.release.xcconfig */,
7081090C6E22D91B12A63D65 /* Pods-Runner.profile.xcconfig */,
6A9A17806BE49FD019B0DB41 /* Pods-RunnerTests.debug.xcconfig */,
FA7CB1383A647C2D24B46844 /* Pods-RunnerTests.release.xcconfig */,
A4BF9D95DC3AEA839D03722B /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -128,8 +172,10 @@
isa = PBXNativeTarget;
buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */;
buildPhases = (
522EC1B060427CA49FA9A954 /* [CP] Check Pods Manifest.lock */,
331C807D294A63A400263BE5 /* Sources */,
331C807F294A63A400263BE5 /* Resources */,
0D70F078EEFD111D42BA3C5C /* Frameworks */,
);
buildRules = (
);
@@ -145,12 +191,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
6E3C45D3F1E98809BC13B1B5 /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
8F7BBF6E33A45DC857BA490D /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@@ -238,6 +286,67 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
522EC1B060427CA49FA9A954 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
6E3C45D3F1E98809BC13B1B5 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
8F7BBF6E33A45DC857BA490D /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
@@ -378,6 +487,7 @@
};
331C8088294A63A400263BE5 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 6A9A17806BE49FD019B0DB41 /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
@@ -395,6 +505,7 @@
};
331C8089294A63A400263BE5 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = FA7CB1383A647C2D24B46844 /* Pods-RunnerTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
@@ -410,6 +521,7 @@
};
331C808A294A63A400263BE5 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A4BF9D95DC3AEA839D03722B /* Pods-RunnerTests.profile.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;

View File

@@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -25,10 +25,10 @@ class ThemeController extends ChangeNotifier {
}
/// Sets theme and persists it in Preferences.
Future<void> setTheme(ThemeMode mode) async {
void setTheme(ThemeMode mode) {
_themeMode = mode;
notifyListeners();
await _prefs.setString('theme', _toString(mode));
_prefs.setString('theme', mode.name);
}
ThemeMode _fromString(String value) {
@@ -43,16 +43,5 @@ class ThemeController extends ChangeNotifier {
}
}
String _toString(ThemeMode mode) {
switch (mode) {
case ThemeMode.light:
return 'light';
case ThemeMode.dark:
return 'dark';
case ThemeMode.system:
return 'system';
}
}
ThemeMode get themeMode => _themeMode;
}

View File

@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:fluttery/fluttery.dart';
import 'package:fluttery/logger.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
Future<void> main() async {
// Ensures that the Flutter engine and widget binding
@@ -25,10 +26,13 @@ Future<void> main() async {
await themeController.init();
runApp(
FinlogApp(
MultiProvider(
providers: [ChangeNotifierProvider(create: (context) => themeController)],
child: FinlogApp(
router: buildAppRouter(startRoute),
themeController: themeController,
),
),
);
}

View File

@@ -1,5 +1,5 @@
import 'package:app/core/app/theme.dart';
import 'package:app/modules/settings/modules/app/model/app_settings_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@@ -8,8 +8,9 @@ class AppSettingsView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final themeModel = context.watch<ThemeController>();
return ChangeNotifierProvider(
create: (_) => AppSettingsViewModel()..load(),
create: (_) => AppSettingsViewModel(themeModel: themeModel)..load(),
child: const _AppSettingsContent(),
);
}
@@ -38,8 +39,6 @@ class _AppSettingsContent extends StatelessWidget {
_TextSizeSection(),
const SizedBox(height: 16),
_LanguageSection(),
const SizedBox(height: 24),
_SaveButton(),
],
),
),
@@ -49,102 +48,74 @@ class _AppSettingsContent extends StatelessWidget {
}
class _SystemBackgroundSection extends StatelessWidget {
const _SystemBackgroundSection();
@override
Widget build(BuildContext context) {
final vm = context.watch<AppSettingsViewModel>();
final scheme = Theme.of(context).colorScheme;
// A few pleasant presets; extend as needed.
final presets = <Color>[
const Color(0xFFFFFFFF),
const Color(0xFFF5F5F5),
const Color(0xFF121212),
const Color(0xFF1E1E1E),
Colors.blueGrey.shade50,
Colors.blueGrey.shade900,
];
final isSystem = vm.backgroundColorSystem == null;
final selected = vm.backgroundColorSystem;
Widget chip({
required Widget child,
required bool selected,
required VoidCallback onTap,
}) {
return InkWell(
borderRadius: BorderRadius.circular(22),
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
border: Border.all(
color: selected ? scheme.primary : scheme.outlineVariant,
),
),
child: child,
),
);
}
final selected = vm.themeMode;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
const Text(
'System-Hintergrundfarbe',
style: Theme.of(context).textTheme.titleMedium,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
chip(
const SizedBox(height: 10),
ToggleButtons(
isSelected: [
selected == ThemeMode.system,
selected == ThemeMode.dark,
selected == ThemeMode.light,
],
onPressed: (i) {
switch (i) {
case 0:
vm.setBackgroundPref(ThemeMode.system);
break;
case 1:
vm.setBackgroundPref(ThemeMode.dark);
break;
case 2:
vm.setBackgroundPref(ThemeMode.light);
break;
}
},
borderRadius: BorderRadius.circular(24),
constraints: const BoxConstraints(minHeight: 44, minWidth: 140),
children: const [
_SegItem(icon: Icons.phone_iphone, label: 'Systemstandard'),
_SegItem(emoji: '🌙', label: 'Dark Mode'),
_SegItem(emoji: '☀️', label: 'White Mode'),
],
),
],
);
}
}
class _SegItem extends StatelessWidget {
final IconData? icon;
final String? emoji;
final String label;
const _SegItem({this.icon, this.emoji, required this.label});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.phone_android, size: 18),
const SizedBox(width: 6),
Text(
'Systemstandard',
style: Theme.of(context).textTheme.bodyMedium,
),
if (icon != null) Icon(icon, size: 18),
if (emoji != null) Text(emoji!, style: const TextStyle(fontSize: 18)),
const SizedBox(width: 8),
Text(label),
],
),
selected: isSystem,
onTap: () => vm.setSystemBackgroundColor(null),
),
...presets.map((c) {
final bool sel = selected == c;
return GestureDetector(
onTap: () => vm.setSystemBackgroundColor(c),
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: c,
shape: BoxShape.circle,
border: Border.all(
color: sel ? scheme.primary : scheme.outlineVariant,
width: sel ? 2 : 1,
),
),
),
);
}),
],
),
const SizedBox(height: 4),
Text(
isSystem
? 'Aktuell: Systemstandard'
: 'Aktuell: Benutzerdefinierte Farbe',
style: Theme.of(
context,
).textTheme.bodySmall?.copyWith(color: scheme.outline),
),
],
);
}
}
@@ -212,31 +183,3 @@ class _LanguageSection extends StatelessWidget {
);
}
}
class _SaveButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final vm = context.watch<AppSettingsViewModel>();
return FilledButton.icon(
onPressed: vm.isSaving
? null
: () async {
await vm.save();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Einstellungen gespeichert')),
);
}
},
icon: vm.isSaving
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.save_outlined),
label: const Text('Speichern'),
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:app/core/app/theme.dart';
import 'package:flutter/material.dart';
/// Domain-ish enums for clarity and easy (de)serialization.
@@ -14,15 +15,10 @@ class AppSettingsViewModel extends ChangeNotifier {
bool _isLoading = false;
bool _isSaving = false;
Color? get backgroundColorSystem => _backgroundColorSystem;
final ThemeController _theme;
AppTextSize get textSize => _textSize;
AppLanguage get language => _language;
bool get isLoading => _isLoading;
bool get isSaving => _isSaving;
AppSettingsViewModel({required ThemeController themeModel})
: _theme = themeModel;
/// Pretend to load from backend. Plug your repository here later.
Future<void> load() async {
@@ -41,6 +37,11 @@ class AppSettingsViewModel extends ChangeNotifier {
notifyListeners();
}
void setBackgroundPref(ThemeMode mode) {
_theme.setTheme(mode);
notifyListeners();
}
/// Save to backend (stub).
Future<void> save() async {
if (_isSaving) return;
@@ -71,7 +72,6 @@ class AppSettingsViewModel extends ChangeNotifier {
Map<String, dynamic> toJson() => {
'backgroundColorSystem': _backgroundColorSystem?.value,
// null => system
'textSize': _textSize.name,
'language': _language.name,
};
@@ -94,4 +94,16 @@ class AppSettingsViewModel extends ChangeNotifier {
notifyListeners();
}
ThemeMode get themeMode => _theme.themeMode;
Color? get backgroundColorSystem => _backgroundColorSystem;
AppTextSize get textSize => _textSize;
AppLanguage get language => _language;
bool get isLoading => _isLoading;
bool get isSaving => _isSaving;
}