add page for tv shows
only showing up if enabled in backend
This commit is contained in:
68
lib/utils/feature_context.dart
Normal file
68
lib/utils/feature_context.dart
Normal file
@ -0,0 +1,68 @@
|
||||
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<FeatureContext>();
|
||||
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<FeatureContainer> createState() => _FeatureContainerState();
|
||||
}
|
||||
|
||||
class _FeatureContainerState extends State<FeatureContainer> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user