add load error in featurecontext

This commit is contained in:
lukas-heiligenbrunner 2022-10-20 09:28:14 +02:00
parent 6f6fbb3897
commit eff1ea0812

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:openmediacentermobile/login/login_context.dart';
import '../api/settings_api.dart';
// todo maybe instead of feature context a context for all settings?
@ -35,30 +36,53 @@ class FeatureContainer extends StatefulWidget {
class _FeatureContainerState extends State<FeatureContainer> {
bool? tvShowEnabled;
bool? fullDeleteEnabled;
bool fetcherror = false;
@override
void initState() {
loadInitialData().then((value) => setState(
loadInitialData()
.then((value) => setState(
() {
fullDeleteEnabled = value.fullDeleteEnabled;
tvShowEnabled = value.tvShowEnabled;
},
));
))
.catchError((err) => setState(() => fetcherror = true));
super.initState();
}
@override
Widget build(BuildContext context) {
if (tvShowEnabled == null || fullDeleteEnabled == null) {
if (fetcherror) {
final loginctx = LoginContext.of(context);
return MaterialApp(
home: Container(
home: Scaffold(
body: Center(
child:
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text("Fetch error"),
MaterialButton(
onPressed: () => loginctx.onLoggin(false),
child: Text("Logout"),
)
]),
),
),
);
} else if (tvShowEnabled == null || fullDeleteEnabled == null) {
return MaterialApp(
home: Scaffold(
body: Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [CircularProgressIndicator(), Text("loading features")],
)),
),
),
);
} else {
return FeatureContext(tvShowEnabled!, fullDeleteEnabled!,