Skip to content

Commit d4549ab

Browse files
committed
Properly handle margin/padding
1 parent 5247c96 commit d4549ab

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/action/bottom_sheet_actions.dart

+24-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ShowBottomSheetAction extends EnsembleAction {
2222
});
2323

2424
static const defaultTopBorderRadius = Radius.circular(16);
25+
static const dragHandleHeight = 3.0;
26+
static const dragHandleVerticalMargin = 10.0;
2527

2628
final Map payload;
2729
final dynamic body;
@@ -132,7 +134,21 @@ class ShowBottomSheetAction extends EnsembleAction {
132134
}
133135

134136
Widget getBodyWidget(ScopeManager scopeManager, BuildContext context) {
135-
var widget = scopeManager.buildWidgetFromDefinition(body);
137+
// We have to handle the BottomSheet's padding directly around the widget,
138+
// such that it is inside the Scrollable area to be able to move up and down.
139+
var sheetPadding = padding(scopeManager) ?? EdgeInsets.zero;
140+
141+
// account for the drag handle
142+
if (showDragHandle(scopeManager)) {
143+
var additionalPaddingTop =
144+
dragHandleVerticalMargin * 2 + dragHandleHeight;
145+
sheetPadding =
146+
sheetPadding.copyWith(top: sheetPadding.top + additionalPaddingTop);
147+
}
148+
149+
var widget = Padding(
150+
padding: sheetPadding,
151+
child: scopeManager.buildWidgetFromDefinition(body));
136152

137153
if (isScrollable(scopeManager) == true) {
138154
// fix the viewport numbers if used incorrectly
@@ -159,7 +175,7 @@ class ShowBottomSheetAction extends EnsembleAction {
159175
// so the height will be fixed to initialViewport, and content will just scroll within it.
160176
// https://docs.flutter.dev/release/breaking-changes/default-scroll-behavior-drag
161177
return DraggableScrollableSheet(
162-
expand: false,
178+
expand: true,
163179
minChildSize: minViewport,
164180
maxChildSize: maxViewport,
165181
initialChildSize: initialViewport,
@@ -181,8 +197,6 @@ class ShowBottomSheetAction extends EnsembleAction {
181197
Widget buildRootContainer(ScopeManager scopeManager, BuildContext context,
182198
{required Widget child, required bool isScrollable}) {
183199
Widget rootWidget = Container(
184-
margin: margin(scopeManager),
185-
padding: padding(scopeManager),
186200
decoration: BoxDecoration(
187201
color: getBackgroundColor(scopeManager) ??
188202
Theme.of(context).dialogBackgroundColor,
@@ -202,14 +216,17 @@ class ShowBottomSheetAction extends EnsembleAction {
202216
children: [rootWidget, _buildDragHandle(scopeManager)],
203217
);
204218
}
205-
return rootWidget;
219+
// This is the Margin of the bottom sheet.
220+
// Padding will be handled separately inside the scrollable area
221+
return Padding(
222+
padding: margin(scopeManager) ?? EdgeInsets.zero, child: rootWidget);
206223
}
207224

208225
Widget _buildDragHandle(ScopeManager scopeManager) {
209226
return Container(
210-
margin: const EdgeInsets.only(top: 10),
227+
margin: const EdgeInsets.only(top: dragHandleVerticalMargin),
211228
width: 32,
212-
height: 3,
229+
height: dragHandleHeight,
213230
decoration: BoxDecoration(
214231
color: dragHandleColor(scopeManager) ?? Colors.grey[500],
215232
borderRadius: BorderRadius.circular(12),

lib/util/utils.dart

+2
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ class Utils {
695695
} else if (values.length == 2) {
696696
left = right = (parseIntFromString(values[1]) ?? 0).toDouble();
697697
bottom = top;
698+
} else {
699+
left = right = bottom = top;
698700
}
699701
return EdgeInsets.only(
700702
top: top, right: right, bottom: bottom, left: left);

0 commit comments

Comments
 (0)