From 1e9e890db796b2d2ba8b83d98692fbc05c53b44e Mon Sep 17 00:00:00 2001 From: Mangirdas Kazlauskas Date: Thu, 31 Oct 2024 23:30:10 +0200 Subject: [PATCH] feat: apply default configuration to widget slides --- .../lib/src/flutter_deck_app.dart | 19 +++++++++++++------ .../lib/src/flutter_deck_slide.dart | 13 +++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/flutter_deck/lib/src/flutter_deck_app.dart b/packages/flutter_deck/lib/src/flutter_deck_app.dart index 80f2c4a..eddadef 100644 --- a/packages/flutter_deck/lib/src/flutter_deck_app.dart +++ b/packages/flutter_deck/lib/src/flutter_deck_app.dart @@ -210,18 +210,25 @@ class _FlutterDeckAppState extends State { FlutterDeckRouterSlide? _buildRouterSlide((int, Widget) indexedSlide) { final (index, slide) = indexedSlide; - final slideConfiguration = - slide is FlutterDeckSlideWidget ? slide.configuration : null; - if (slideConfiguration?.hidden ?? false) return null; + var slideWidget = slide; - final configuration = slideConfiguration ?? - FlutterDeckSlideConfiguration(route: '/slide-${index + 1}'); + if (slideWidget is! FlutterDeckSlideWidget) { + final defaultConfiguration = FlutterDeckSlideConfiguration( + route: '/slide-${index + 1}', + ); + + slideWidget = slide.withSlideConfiguration(defaultConfiguration); + } + + final configuration = slideWidget.configuration!; + + if (configuration.hidden) return null; return FlutterDeckRouterSlide( configuration: configuration.mergeWithGlobal(widget.configuration), route: configuration.route, - widget: slide, + widget: slideWidget, ); } diff --git a/packages/flutter_deck/lib/src/flutter_deck_slide.dart b/packages/flutter_deck/lib/src/flutter_deck_slide.dart index 402003f..bed76e9 100644 --- a/packages/flutter_deck/lib/src/flutter_deck_slide.dart +++ b/packages/flutter_deck/lib/src/flutter_deck_slide.dart @@ -391,3 +391,16 @@ class _SlideBody extends StatelessWidget { ); } } + +/// +extension FlutterDeckSlideWidgetX on Widget { + /// + FlutterDeckSlideWidget withSlideConfiguration( + FlutterDeckSlideConfiguration configuration, + ) { + return FlutterDeckSlide.custom( + configuration: configuration, + builder: (context) => this, + ); + } +}