refactored landing page with initialization errors
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ErrorContainer extends StatelessWidget {
|
||||||
|
final Widget content;
|
||||||
|
|
||||||
|
const ErrorContainer({required this.content});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.errorContainer,
|
||||||
|
borderRadius: BorderRadius.circular(4.0),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.warning,
|
||||||
|
size: 36,
|
||||||
|
color: theme.colorScheme.onErrorContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: content,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import 'package:bang_navigator/core/routing/routes.dart';
|
|||||||
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
import 'package:bang_navigator/features/search_browser/domain/entities/modes.dart';
|
||||||
import 'package:bang_navigator/features/search_browser/domain/entities/sheet.dart';
|
import 'package:bang_navigator/features/search_browser/domain/entities/sheet.dart';
|
||||||
import 'package:bang_navigator/features/search_browser/domain/services/create_tab.dart';
|
import 'package:bang_navigator/features/search_browser/domain/services/create_tab.dart';
|
||||||
|
import 'package:bang_navigator/features/search_browser/presentation/widgets/error_container.dart';
|
||||||
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
import 'package:bang_navigator/features/settings/data/repositories/settings_repository.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
@@ -13,8 +14,6 @@ class LandingAction extends HookConsumerWidget {
|
|||||||
const LandingAction({super.key});
|
const LandingAction({super.key});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final theme = Theme.of(context);
|
|
||||||
|
|
||||||
final sessionTokenAvailable = ref.watch(
|
final sessionTokenAvailable = ref.watch(
|
||||||
settingsRepositoryProvider.select(
|
settingsRepositoryProvider.select(
|
||||||
(value) => value.valueOrNull?.kagiSession?.isNotEmpty ?? false,
|
(value) => value.valueOrNull?.kagiSession?.isNotEmpty ?? false,
|
||||||
@@ -29,24 +28,8 @@ class LandingAction extends HookConsumerWidget {
|
|||||||
|
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: sessionTokenAvailable,
|
visible: sessionTokenAvailable,
|
||||||
replacement: Container(
|
replacement: ErrorContainer(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
content: Markdown(
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: theme.colorScheme.errorContainer,
|
|
||||||
borderRadius: BorderRadius.circular(4.0),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Icon(
|
|
||||||
Icons.warning,
|
|
||||||
size: 36,
|
|
||||||
color: theme.colorScheme.onErrorContainer,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Markdown(
|
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
onTapLink: (text, href, title) async {
|
onTapLink: (text, href, title) async {
|
||||||
if (href == 'settings') {
|
if (href == 'settings') {
|
||||||
@@ -58,9 +41,6 @@ class LandingAction extends HookConsumerWidget {
|
|||||||
"You must provide a valid session in order to use Kagi's features.",
|
"You must provide a valid session in order to use Kagi's features.",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: 8.0,
|
spacing: 8.0,
|
||||||
alignment: WrapAlignment.spaceEvenly,
|
alignment: WrapAlignment.spaceEvenly,
|
||||||
|
|||||||
@@ -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/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/material.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
@@ -12,17 +14,12 @@ class LandingContent extends HookConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final textTheme = Theme.of(context).textTheme;
|
final textTheme = Theme.of(context).textTheme;
|
||||||
|
|
||||||
// ignore: discarded_futures
|
final descriptionAsset = useCachedFuture(
|
||||||
final descriptionAssetFuture = useMemoized(
|
|
||||||
() async => rootBundle.loadString('assets/landing/description.md'),
|
() async => rootBundle.loadString('assets/landing/description.md'),
|
||||||
);
|
);
|
||||||
final descriptionAsset = useFuture(descriptionAssetFuture);
|
final changelogAsset = useCachedFuture(
|
||||||
|
|
||||||
// ignore: discarded_futures
|
|
||||||
final changelogAssetFuture = useMemoized(
|
|
||||||
() async => rootBundle.loadString('assets/landing/changelog.md'),
|
() async => rootBundle.loadString('assets/landing/changelog.md'),
|
||||||
);
|
);
|
||||||
final changelogAsset = useFuture(changelogAssetFuture);
|
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -42,6 +39,71 @@ class LandingContent extends HookConsumerWidget {
|
|||||||
child: Image.asset('assets/icon/icon.png'),
|
child: Image.asset('assets/icon/icon.png'),
|
||||||
),
|
),
|
||||||
const LandingAction(),
|
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(
|
Markdown(
|
||||||
data: descriptionAsset.data ?? '',
|
data: descriptionAsset.data ?? '',
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
|
||||||
|
AsyncSnapshot<T> useCachedFuture<T>(
|
||||||
|
Future<T> Function() valueBuilder,
|
||||||
|
) {
|
||||||
|
// ignore: discarded_futures
|
||||||
|
final cachedFuture = useMemoized(
|
||||||
|
valueBuilder,
|
||||||
|
);
|
||||||
|
return useFuture(cachedFuture);
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ class FailureWidget extends StatelessWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final String? title;
|
final String? title;
|
||||||
final Object? exception;
|
final dynamic exception;
|
||||||
final VoidCallback? onRetry;
|
final VoidCallback? onRetry;
|
||||||
final bool compact;
|
final bool compact;
|
||||||
|
|
||||||
@@ -23,7 +23,10 @@ class FailureWidget extends StatelessWidget {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(title ?? 'Something went wrong'),
|
title: Text(title ?? 'Something went wrong'),
|
||||||
subtitle: exception != null
|
subtitle: exception != null
|
||||||
? Text(exception.runtimeType.toString())
|
? switch (exception) {
|
||||||
|
final String string => Text(string),
|
||||||
|
_ => Text(exception.runtimeType.toString())
|
||||||
|
}
|
||||||
: null,
|
: null,
|
||||||
trailing: compact && onRetry != null
|
trailing: compact && onRetry != null
|
||||||
? IconButton.outlined(
|
? IconButton.outlined(
|
||||||
|
|||||||
Reference in New Issue
Block a user