Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce updateCurrentPage method to update the currently visible page without pagination animation #207

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 pagination 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 pagination 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
Loading