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; 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 @immutable
abstract class NeonException implements Exception { abstract class NeonException implements Exception {
/// Creates a NeonException /// Creates a NeonException
const NeonException(); const NeonException();
/// Details that will be rendered by the UI /// Details that will be rendered by the UI.
NeonExceptionDetails get details; 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) ?? widget.errorBuilder?.call(context, error) ??
NeonError( NeonError(
error, error,

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

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

Loading…
Cancel
Save