-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FlexibleWoltModalSheetPage for non-scrolling page content
- Loading branch information
Showing
7 changed files
with
163 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; | ||
|
||
/// A [FlexibleWoltModalSheetPage] is a specialized page for the [WoltModalSheet] | ||
/// that is designed to display content which is flexible in height but unlikely | ||
/// to require scrolling. | ||
/// | ||
/// This class is designed for content that needs to adapt to the available | ||
/// vertical space within the modal sheet's maximum height, but is unlikely | ||
/// to exceed that height and require scrolling. It is ideal for content that | ||
/// is flexible in height but has fixed (or intrinsic) dimensions and is laid | ||
/// out using the [Flex] layout model of a [Column]. | ||
/// | ||
/// Warning: | ||
/// - If there is a risk that the content's height might exceed the modal | ||
/// sheet's maximum height, leading to overflow, it is recommended to use | ||
/// [SliverWoltModalSheetPage] or [WoltModalSheetPage] instead. These classes | ||
/// provide scrolling capabilities to handle larger content effectively using slivers. | ||
class FlexibleWoltModalSheetPage extends SliverWoltModalSheetPage { | ||
/// A [Widget] that represents the main content displayed in the page. | ||
/// This is a shortcut for providing a list of Sliver widgets with only one Sliver widget. | ||
final Widget child; | ||
|
||
/// Creates a page to be built within [WoltScrollableModalSheet]. | ||
FlexibleWoltModalSheetPage({ | ||
required this.child, | ||
super.backgroundColor, | ||
super.enableDrag, | ||
super.leadingNavBarWidget, | ||
super.trailingNavBarWidget, | ||
super.hasTopBarLayer = false, | ||
super.topBar, | ||
super.topBarTitle, | ||
super.navBarHeight, | ||
}) : super( | ||
isTopBarLayerAlwaysVisible: hasTopBarLayer, | ||
mainContentSlivers: [ | ||
SliverFillViewport( | ||
delegate: SliverChildListDelegate([child]), | ||
), | ||
], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
playground/lib/home/pages/sheet_page_with_flexible_sheet_layout.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:demo_ui_components/demo_ui_components.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; | ||
|
||
class SheetPageWithFlexibleSheetLayout { | ||
SheetPageWithFlexibleSheetLayout._(); | ||
|
||
static FlexibleWoltModalSheetPage build({ | ||
required VoidCallback nextPagePressed, | ||
required VoidCallback onBackPressed, | ||
required VoidCallback onClosed, | ||
bool isLastPage = true, | ||
}) { | ||
const textStyle = TextStyle(fontSize: 24, fontWeight: FontWeight.bold); | ||
return FlexibleWoltModalSheetPage( | ||
leadingNavBarWidget: | ||
WoltModalSheetBackButton(onBackPressed: onBackPressed), | ||
trailingNavBarWidget: WoltModalSheetCloseButton(onClosed: onClosed), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
const Flexible( | ||
flex: 2, | ||
child: ColoredBox( | ||
color: Colors.blue, | ||
child: Center( | ||
child: Text('Flex: 2', style: textStyle), | ||
), | ||
), | ||
), | ||
const Flexible( | ||
flex: 3, | ||
child: ColoredBox( | ||
color: Colors.amber, | ||
child: Center(child: Text('Flex: 3', style: textStyle)), | ||
), | ||
), | ||
Flexible( | ||
flex: 1, | ||
child: GestureDetector( | ||
onTap: isLastPage ? onClosed : nextPagePressed, | ||
child: ColoredBox( | ||
color: Colors.green, | ||
child: Center( | ||
child: Text( | ||
"Flex: 1\n Tap here to ${isLastPage ? 'close' : 'go to the next page'}", | ||
style: textStyle, | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |