diff --git a/lib/utils/feature_context.dart b/lib/utils/feature_context.dart index bc469f1..fd7dd8b 100644 --- a/lib/utils/feature_context.dart +++ b/lib/utils/feature_context.dart @@ -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,29 +36,52 @@ class FeatureContainer extends StatefulWidget { class _FeatureContainerState extends State { bool? tvShowEnabled; bool? fullDeleteEnabled; + bool fetcherror = false; @override void initState() { - loadInitialData().then((value) => setState( - () { - fullDeleteEnabled = value.fullDeleteEnabled; - tvShowEnabled = value.tvShowEnabled; - }, - )); + 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( - color: Colors.white, - child: Center( - child: Column( - children: [CircularProgressIndicator(), Text("loading features")], - )), + 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 {