Load server configuration
This commit is contained in:
49
moneymgr_mobile/lib/widgets/full_screen_error.dart
Normal file
49
moneymgr_mobile/lib/widgets/full_screen_error.dart
Normal file
@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FullScreenError extends StatelessWidget {
|
||||
final String message;
|
||||
final String error;
|
||||
final List<Widget>? actions;
|
||||
|
||||
const FullScreenError({
|
||||
super.key,
|
||||
required this.message,
|
||||
required this.error,
|
||||
this.actions,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("Error")),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 2,
|
||||
color: Colors.red,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(color: Colors.white, fontSize: 20),
|
||||
),
|
||||
Text(error, style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: actions ?? [],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
35
moneymgr_mobile/lib/widgets/loaders/load_server_config.dart
Normal file
35
moneymgr_mobile/lib/widgets/loaders/load_server_config.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:moneymgr_mobile/providers/auth_state.dart';
|
||||
import 'package:moneymgr_mobile/services/api/server_api.dart';
|
||||
import 'package:moneymgr_mobile/widgets/full_screen_error.dart';
|
||||
|
||||
class LoadServerConfig extends HookConsumerWidget {
|
||||
final Widget child;
|
||||
|
||||
const LoadServerConfig({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final serverConfig = ref.watch(serverConfigOrCacheProvider);
|
||||
|
||||
handleSignOut() {
|
||||
ref.watch(currentAuthStateProvider.notifier).logout();
|
||||
}
|
||||
|
||||
return switch (serverConfig) {
|
||||
AsyncData() => child,
|
||||
AsyncError(:final error) => FullScreenError(
|
||||
message: "Failed to load server configuration!",
|
||||
error: error.toString(),
|
||||
actions: [
|
||||
MaterialButton(
|
||||
onPressed: handleSignOut,
|
||||
child: Text("Sign out".toUpperCase()),
|
||||
),
|
||||
],
|
||||
),
|
||||
_ => const Scaffold(body: Center(child: CircularProgressIndicator())),
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user