refactored landing page with initialization errors
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'package:bang_navigator/domain/services/app_initialization.dart';
|
||||
import 'package:bang_navigator/features/search_browser/presentation/widgets/error_container.dart';
|
||||
import 'package:bang_navigator/features/search_browser/presentation/widgets/landing/action.dart';
|
||||
import 'package:bang_navigator/presentation/hooks/cached_future.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
@@ -12,17 +14,12 @@ class LandingContent extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
// ignore: discarded_futures
|
||||
final descriptionAssetFuture = useMemoized(
|
||||
final descriptionAsset = useCachedFuture(
|
||||
() async => rootBundle.loadString('assets/landing/description.md'),
|
||||
);
|
||||
final descriptionAsset = useFuture(descriptionAssetFuture);
|
||||
|
||||
// ignore: discarded_futures
|
||||
final changelogAssetFuture = useMemoized(
|
||||
final changelogAsset = useCachedFuture(
|
||||
() async => rootBundle.loadString('assets/landing/changelog.md'),
|
||||
);
|
||||
final changelogAsset = useFuture(changelogAssetFuture);
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -42,6 +39,71 @@ class LandingContent extends HookConsumerWidget {
|
||||
child: Image.asset('assets/icon/icon.png'),
|
||||
),
|
||||
const LandingAction(),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final errors = ref.watch(
|
||||
appInitializationServiceProvider
|
||||
.select((result) => result.valueOrNull?.errors),
|
||||
);
|
||||
|
||||
if (errors == null || errors.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...errors.map(
|
||||
(error) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: ErrorContainer(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Error during App Initialization!',
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
Text(
|
||||
error.message,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
if (error.details != null)
|
||||
Text(error.details.toString()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(appInitializationServiceProvider.notifier)
|
||||
.reinitialize();
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
label: const Text('Restart App'),
|
||||
icon: const Icon(Icons.refresh_outlined),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
Markdown(
|
||||
data: descriptionAsset.data ?? '',
|
||||
selectable: true,
|
||||
|
||||
Reference in New Issue
Block a user