// 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 listeners = {}; final Map 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 asList() { return entries.values.toList(); } } class WidgetSettings extends StatefulWidget { const WidgetSettings({ required this.entries, super.key, }); final WidgetSettingsData entries; @override State createState() => _WidgetSettingsState(); } class _WidgetSettingsState extends State { @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(), ), ), ); } }