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