import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:lightmeter/data/shared_prefs_service.dart'; import 'package:lightmeter/utils/inherited_generics.dart'; import 'package:provider/provider.dart'; typedef MeteringScreenLayout = InheritedModelBase; class MeteringScreenLayoutProvider extends StatefulWidget { final Widget child; const MeteringScreenLayoutProvider({required this.child, super.key}); static MeteringScreenLayoutProviderState of(BuildContext context) { return context.findAncestorStateOfType()!; } @override State createState() => MeteringScreenLayoutProviderState(); } class MeteringScreenLayoutProviderState extends State { late final MeteringScreenLayoutConfig _config = context.read().meteringScreenLayout; @override Widget build(BuildContext context) { return InheritedModelBase( data: MeteringScreenLayoutConfig.from(_config), child: widget.child, ); } void updateFeatures(MeteringScreenLayoutConfig config) { setState(() { config.forEach((key, value) { _config.update( key, (_) => value, ifAbsent: () => value, ); }); }); context.read().meteringScreenLayout = _config; } }