Browse Source

refactor(neon): Use Object? instead of dynamic for errors

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/852/head
jld3103 1 year ago
parent
commit
7c1647fec5
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/neon/neon/lib/src/utils/exceptions.dart
  2. 2
      packages/neon/neon/lib/src/widgets/cached_image.dart
  3. 6
      packages/neon/neon/lib/src/widgets/error.dart
  4. 2
      packages/neon/neon/lib/src/widgets/list_view.dart

4
packages/neon/neon/lib/src/utils/exceptions.dart

@ -22,13 +22,13 @@ class NeonExceptionDetails {
final bool isUnauthorized;
}
/// Extensible [Exception] to be used for displaying custom errors in the UI
/// Extensible [Exception] to be used for displaying custom errors in the UI.
@immutable
abstract class NeonException implements Exception {
/// Creates a NeonException
const NeonException();
/// Details that will be rendered by the UI
/// Details that will be rendered by the UI.
NeonExceptionDetails get details;
}

2
packages/neon/neon/lib/src/widgets/cached_image.dart

@ -180,7 +180,7 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
),
);
Widget _buildError(final dynamic error) =>
Widget _buildError(final Object? error) =>
widget.errorBuilder?.call(context, error) ??
NeonError(
error,

6
packages/neon/neon/lib/src/widgets/error.dart

@ -28,7 +28,7 @@ class NeonError extends StatelessWidget {
/// The error object.
///
/// Can be of type [String] or [Exception], various subtypes of `Exception` are also handled separately.
final dynamic error;
final Object? error;
/// A function that's called when the user decides to retry the action that lead to the error.
final VoidCallback onRetry;
@ -47,7 +47,7 @@ class NeonError extends StatelessWidget {
final Color? color;
/// Shows a [SnackBar] popup for the [error].
static void showSnackbar(final BuildContext context, final dynamic error) {
static void showSnackbar(final BuildContext context, final Object? error) {
final details = getDetails(error);
ScaffoldMessenger.of(context).showSnackBar(
@ -132,7 +132,7 @@ class NeonError extends StatelessWidget {
/// Gets the details for a given [error].
@internal
static NeonExceptionDetails getDetails(final dynamic error) {
static NeonExceptionDetails getDetails(final Object? error) {
switch (error) {
case String():
return NeonExceptionDetails(

2
packages/neon/neon/lib/src/widgets/list_view.dart

@ -18,7 +18,7 @@ class NeonListView<T> extends StatelessWidget {
final Iterable<T>? items;
final bool isLoading;
final dynamic error;
final Object? error;
final RefreshCallback onRefresh;
final Widget Function(BuildContext, T data) builder;
final String? scrollKey;

Loading…
Cancel
Save