import 'package:flutter/material.dart'; import '../api/settings_api.dart'; // todo maybe instead of feature context a context for all settings? class FeatureContext extends InheritedWidget { const FeatureContext(this.tvShowEnabled, this.fullDeleteEnabled, {Key? key, required Widget child}) : super(key: key, child: child); final bool tvShowEnabled; final bool fullDeleteEnabled; static FeatureContext of(BuildContext context) { final FeatureContext? result = context.dependOnInheritedWidgetOfExactType(); assert(result != null, 'No LoginContext found in context'); return result!; } @override bool updateShouldNotify(FeatureContext old) { return tvShowEnabled != old.tvShowEnabled || fullDeleteEnabled != old.fullDeleteEnabled; } } class FeatureContainer extends StatefulWidget { const FeatureContainer({Key? key, required this.child}) : super(key: key); final Widget child; @override State createState() => _FeatureContainerState(); } class _FeatureContainerState extends State { bool? tvShowEnabled; bool? fullDeleteEnabled; @override void initState() { loadInitialData().then((value) => setState( () { fullDeleteEnabled = value.fullDeleteEnabled; tvShowEnabled = value.tvShowEnabled; }, )); super.initState(); } @override Widget build(BuildContext context) { if (tvShowEnabled == null || fullDeleteEnabled == null) { return MaterialApp( home: Container( color: Colors.white, child: Center( child: Column( children: [CircularProgressIndicator(), Text("loading features")], )), ), ); } else { return FeatureContext(tvShowEnabled!, fullDeleteEnabled!, child: widget.child); } } }