mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 13:13:44 +02:00
feat: add error builder to options
This is done to allow for the user of this package to define custom error handling
This commit is contained in:
parent
2b931db798
commit
c8348be746
4 changed files with 66 additions and 0 deletions
|
@ -5,5 +5,6 @@ export "package:flutter_availability_data_interface/flutter_availability_data_in
|
||||||
|
|
||||||
export "src/config/availability_options.dart";
|
export "src/config/availability_options.dart";
|
||||||
export "src/config/availability_translations.dart";
|
export "src/config/availability_translations.dart";
|
||||||
|
export "src/service/errors.dart";
|
||||||
export "src/ui/screens/availability_overview.dart";
|
export "src/ui/screens/availability_overview.dart";
|
||||||
export "src/userstories.dart";
|
export "src/userstories.dart";
|
||||||
|
|
|
@ -2,10 +2,12 @@ import "dart:async";
|
||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_availability/src/config/availability_translations.dart";
|
import "package:flutter_availability/src/config/availability_translations.dart";
|
||||||
|
import "package:flutter_availability/src/service/errors.dart";
|
||||||
import "package:flutter_availability/src/service/local_data_interface.dart";
|
import "package:flutter_availability/src/service/local_data_interface.dart";
|
||||||
import "package:flutter_availability/src/ui/widgets/default_base_screen.dart";
|
import "package:flutter_availability/src/ui/widgets/default_base_screen.dart";
|
||||||
import "package:flutter_availability/src/ui/widgets/default_buttons.dart";
|
import "package:flutter_availability/src/ui/widgets/default_buttons.dart";
|
||||||
import "package:flutter_availability/src/ui/widgets/default_confirmation_dialog.dart";
|
import "package:flutter_availability/src/ui/widgets/default_confirmation_dialog.dart";
|
||||||
|
import "package:flutter_availability/src/ui/widgets/default_error_display.dart";
|
||||||
import "package:flutter_availability_data_interface/flutter_availability_data_interface.dart";
|
import "package:flutter_availability_data_interface/flutter_availability_data_interface.dart";
|
||||||
|
|
||||||
/// Class that holds all options for the availability userstory
|
/// Class that holds all options for the availability userstory
|
||||||
|
@ -25,6 +27,7 @@ class AvailabilityOptions {
|
||||||
this.confirmationDialogBuilder = DefaultConfirmationDialog.builder,
|
this.confirmationDialogBuilder = DefaultConfirmationDialog.builder,
|
||||||
this.timePickerBuilder,
|
this.timePickerBuilder,
|
||||||
this.loadingIndicatorBuilder = DefaultLoader.builder,
|
this.loadingIndicatorBuilder = DefaultLoader.builder,
|
||||||
|
this.errorDisplayBuilder = DefaultErrorDisplayDialog.defaultErrorDisplay,
|
||||||
AvailabilityDataInterface? dataInterface,
|
AvailabilityDataInterface? dataInterface,
|
||||||
}) : dataInterface = dataInterface ?? LocalAvailabilityDataInterface();
|
}) : dataInterface = dataInterface ?? LocalAvailabilityDataInterface();
|
||||||
|
|
||||||
|
@ -82,6 +85,16 @@ class AvailabilityOptions {
|
||||||
/// which shows a platform adaptive loading indicator
|
/// which shows a platform adaptive loading indicator
|
||||||
final WidgetBuilder loadingIndicatorBuilder;
|
final WidgetBuilder loadingIndicatorBuilder;
|
||||||
|
|
||||||
|
/// Builder for handling errors.
|
||||||
|
///
|
||||||
|
/// The user should determine how to display the error, through a dialog,
|
||||||
|
/// popup or other method of user interaction.
|
||||||
|
///
|
||||||
|
/// There is no guarantee that there is a scaffold in the tree for each of
|
||||||
|
/// the calls of the method. To ensure this, you can add a scaffold in the
|
||||||
|
/// base widget through [baseScreenBuilder].
|
||||||
|
final ErrorDisplayBuilder errorDisplayBuilder;
|
||||||
|
|
||||||
final _borderRadius = BorderRadius.circular(5);
|
final _borderRadius = BorderRadius.circular(5);
|
||||||
|
|
||||||
/// The border radius used on the individual elements
|
/// The border radius used on the individual elements
|
||||||
|
@ -204,6 +217,13 @@ typedef ConfirmationDialogBuilder = Future<bool> Function(
|
||||||
required String description,
|
required String description,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// Typedef for the handler of any errors that occur during the usage of this
|
||||||
|
/// userstory.
|
||||||
|
typedef ErrorDisplayBuilder = Future<void> Function(
|
||||||
|
BuildContext context,
|
||||||
|
AvailabilityError error,
|
||||||
|
);
|
||||||
|
|
||||||
///
|
///
|
||||||
class DefaultLoader extends StatelessWidget {
|
class DefaultLoader extends StatelessWidget {
|
||||||
///
|
///
|
||||||
|
|
12
packages/flutter_availability/lib/src/service/errors.dart
Normal file
12
packages/flutter_availability/lib/src/service/errors.dart
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/// A set of errors
|
||||||
|
enum AvailabilityError {
|
||||||
|
/// Error identifier when checking break mismatch
|
||||||
|
breakMismatchWithAvailability(
|
||||||
|
"The break needs to be within the timeframe of the availability",
|
||||||
|
);
|
||||||
|
|
||||||
|
const AvailabilityError(this.description);
|
||||||
|
|
||||||
|
/// A more verbose description of the error.
|
||||||
|
final String description;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
import "package:flutter/material.dart";
|
||||||
|
import "package:flutter_availability/src/service/errors.dart";
|
||||||
|
|
||||||
|
///
|
||||||
|
class DefaultErrorDisplayDialog extends StatelessWidget {
|
||||||
|
///
|
||||||
|
const DefaultErrorDisplayDialog({
|
||||||
|
required AvailabilityError error,
|
||||||
|
super.key,
|
||||||
|
}) : _error = error;
|
||||||
|
|
||||||
|
final AvailabilityError _error;
|
||||||
|
|
||||||
|
///
|
||||||
|
static Future<void> defaultErrorDisplay(
|
||||||
|
BuildContext context,
|
||||||
|
AvailabilityError error,
|
||||||
|
) async {
|
||||||
|
await showAdaptiveDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => DefaultErrorDisplayDialog(error: error),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Column(
|
||||||
|
children: [
|
||||||
|
Text(_error.name),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(_error.description),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue