80 lines
2.1 KiB
Dart
80 lines
2.1 KiB
Dart
![]() |
// ignore_for_file: public_member_api_docs
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||
|
import 'package:habitrack_app/function_widgets/widget_settings_menu/setting_entry.dart';
|
||
|
|
||
|
class WidgetSettingsData {
|
||
|
WidgetSettingsData({required this.entries});
|
||
|
|
||
|
final Map<State, void Function(void Function())> listeners = {};
|
||
|
final Map<String, SettingEntry> entries;
|
||
|
|
||
|
void addListener(State toAdd, void Function(void Function()) updateCall) {
|
||
|
listeners[toAdd] = updateCall;
|
||
|
}
|
||
|
|
||
|
void removeListener(State toRemove) {
|
||
|
listeners.remove(toRemove);
|
||
|
}
|
||
|
|
||
|
void notify() {
|
||
|
for (final listener in listeners.keys) {
|
||
|
listeners[listener]!(() => ());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
dynamic getValue(String key) {
|
||
|
return entries[key]?.getValue();
|
||
|
}
|
||
|
|
||
|
void setValue(String key, dynamic value) {
|
||
|
entries[key]?.setValue(value);
|
||
|
notify();
|
||
|
}
|
||
|
|
||
|
List<SettingEntry> asList() {
|
||
|
return entries.values.toList();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class WidgetSettings extends StatefulWidget {
|
||
|
const WidgetSettings({
|
||
|
required this.entries,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final WidgetSettingsData entries;
|
||
|
|
||
|
@override
|
||
|
State<WidgetSettings> createState() => _WidgetSettingsState();
|
||
|
}
|
||
|
|
||
|
class _WidgetSettingsState extends State<WidgetSettings> {
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
iconTheme: IconThemeData(
|
||
|
color: Theme.of(context).colorScheme.onPrimaryContainer,),
|
||
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||
|
title: Text(
|
||
|
AppLocalizations.of(context)!.settingsHeader,
|
||
|
textScaler: const TextScaler.linear(1.5),
|
||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||
|
fontWeight: FontWeight.bold,
|
||
|
fontSize: 15,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
body: ColoredBox(
|
||
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||
|
child: ListView(
|
||
|
children: widget.entries.asList(),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|