Skip to content

Commit

Permalink
Introduce update current page method
Browse files Browse the repository at this point in the history
  • Loading branch information
ulusoyca committed May 20, 2024
1 parent 79871b3 commit 98ae539
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
55 changes: 55 additions & 0 deletions lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,34 @@ class WoltModalSheet<T> extends StatefulWidget {
static bool showPageWithId(BuildContext context, Object id) {
return WoltModalSheet.of(context).showPageWithId(id);
}

/// Updates the currently visible page in the modal sheet without animation.
///
/// This method directly modifies the properties of the current page, effectively
/// replacing it with the provided page instance. It's particularly useful for updating the
/// current page's non-widget content such as [SliverWoltModalSheetPage.enableDrag] or
/// [SliverWoltModalSheetPage.hasSabGradient].
///
/// Usage Example:
/// ```dart
/// WoltModalSheet.of(context).updateCurrentPage(
/// SliverWoltModalSheetPage(
/// enableDrag: true,
/// hasSabGradient: true,
/// // additional properties
/// )
/// );
/// ```
///
/// Parameters:
/// - `newPage`: The new configuration of the [SliverWoltModalSheetPage] to apply to the
/// currently visible page.
static void updateCurrentPage(
BuildContext context,
SliverWoltModalSheetPage page,
) {
WoltModalSheet.of(context).updateCurrentPage(page);
}
}

class WoltModalSheetState extends State<WoltModalSheet> {
Expand Down Expand Up @@ -1239,4 +1267,31 @@ class WoltModalSheetState extends State<WoltModalSheet> {
}
return false;
}

/// Updates the currently visible page in the modal sheet without animation.
///
/// This method directly modifies the properties of the current page, effectively
/// replacing it with the provided page instance. It's particularly useful for updating the
/// current page's non-widget content such as [SliverWoltModalSheetPage.enableDrag] or
/// [SliverWoltModalSheetPage.hasSabGradient].
///
/// Usage Example:
/// ```dart
/// WoltModalSheet.of(context).updateCurrentPage(
/// SliverWoltModalSheetPage(
/// enableDrag: true,
/// hasSabGradient: true,
/// // additional properties
/// )
/// );
/// ```
///
/// Parameters:
/// - `newPage`: The new configuration of the [SliverWoltModalSheetPage] to apply to the
/// currently visible page.
void updateCurrentPage(SliverWoltModalSheetPage newPage) {
setState(() {
_pages[_currentPageIndex] = newPage;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class SheetPageWithDynamicPageProperties {

static const ModalPageName pageId = ModalPageName.dynamicPageProperties;

static WoltModalSheetPage build(BuildContext context,
{bool isLastPage = true}) {
static WoltModalSheetPage build(
BuildContext context, {
bool isLastPage = true,
}) {
bool useOriginalPageValues = true;
return WoltModalSheetPage(
id: pageId,
Expand Down Expand Up @@ -54,6 +56,10 @@ class SheetPageWithDynamicPageProperties {
dynamicPageModel.value.copyWith(
enableDrag: newValue,
);
// Update the current page to reflect the changes.
WoltModalSheet.of(context).updateCurrentPage(
SheetPageWithDynamicPageProperties.build(context),
);
setState(() =>
useOriginalPageValues = !useOriginalPageValues);
},
Expand Down

0 comments on commit 98ae539

Please sign in to comment.