From 095eff2c21329f93f78636c18e32767ebf5855f7 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Tue, 9 Jul 2024 22:02:21 +0200 Subject: [PATCH] feat: add loadingIndicatorBuilder to override CircularProgressIndicator.adaptive() --- .../lib/src/config/availability_options.dart | 12 ++++++++++++ .../lib/src/ui/screens/template_overview.dart | 4 +++- .../lib/src/ui/widgets/template_legend.dart | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/flutter_availability/lib/src/config/availability_options.dart b/packages/flutter_availability/lib/src/config/availability_options.dart index 0ba1dd5..d5ea120 100644 --- a/packages/flutter_availability/lib/src/config/availability_options.dart +++ b/packages/flutter_availability/lib/src/config/availability_options.dart @@ -19,6 +19,7 @@ class AvailabilityOptions { this.textStyles = const AvailabilityTextStyles(), this.colors = const AvailabilityColors(), this.timePickerBuilder, + this.loadingIndicatorBuilder = defaultLoader, AvailabilityDataInterface? dataInterface, }) : dataInterface = dataInterface ?? LocalAvailabilityDataInterface(); @@ -53,6 +54,11 @@ class AvailabilityOptions { /// A way to provide your own time picker implementation or customize /// the default time picker final TimePickerBuilder? timePickerBuilder; + + /// A builder to override the loading indicator + /// If not provided the [CircularProgressIndicator.adaptive()] will be used + /// which shows a platform adaptive loading indicator + final WidgetBuilder loadingIndicatorBuilder; } /// All configurable paddings and whitespaces withing the userstory @@ -154,3 +160,9 @@ typedef TimePickerBuilder = Future Function( BuildContext context, TimeOfDay? initialTime, ); + +/// Builder definition for providing a loading indicator implementation +Widget defaultLoader( + BuildContext context, +) => + const CircularProgressIndicator.adaptive(); diff --git a/packages/flutter_availability/lib/src/ui/screens/template_overview.dart b/packages/flutter_availability/lib/src/ui/screens/template_overview.dart index 0ec5f6f..9428c04 100644 --- a/packages/flutter_availability/lib/src/ui/screens/template_overview.dart +++ b/packages/flutter_availability/lib/src/ui/screens/template_overview.dart @@ -101,6 +101,8 @@ class _TemplateListSection extends StatelessWidget { Widget build(BuildContext context) { var theme = Theme.of(context); var textTheme = theme.textTheme; + var availabilityScope = AvailabilityScope.of(context); + var options = availabilityScope.options; var templateCreationButton = GestureDetector( onTap: onAddTemplate, @@ -160,7 +162,7 @@ class _TemplateListSection extends StatelessWidget { ), ], if (templatesSnapshot.connectionState == ConnectionState.waiting) ...[ - const Center(child: CircularProgressIndicator.adaptive()), + Center(child: options.loadingIndicatorBuilder(context)), ], const SizedBox(height: 8), templateCreationButton, diff --git a/packages/flutter_availability/lib/src/ui/widgets/template_legend.dart b/packages/flutter_availability/lib/src/ui/widgets/template_legend.dart index 6d02d6e..27b9ba3 100644 --- a/packages/flutter_availability/lib/src/ui/widgets/template_legend.dart +++ b/packages/flutter_availability/lib/src/ui/widgets/template_legend.dart @@ -179,7 +179,7 @@ class _TemplateLegendState extends State { (!_templateDrawerOpen || templatesLoading)) ...[ const SizedBox(height: 12), if (templatesLoading) ...[ - const CircularProgressIndicator.adaptive(), + options.loadingIndicatorBuilder(context), ] else ...[ createNewTemplateButton, ],