@@ -59,9 +59,32 @@ class ShowBottomModalAction extends EnsembleAction {
59
59
Color ? getBackgroundColor (scopeManager) =>
60
60
Utils .getColor (eval (payload["styles" ]? ['backgroundColor' ], scopeManager));
61
61
62
+ bool showDragHandle (scopeManager) =>
63
+ Utils .getBool (eval (payload["styles" ]? ["showDragHandle" ], scopeManager),
64
+ fallback: true );
65
+
66
+ Color ? dragHandleColor (scopeManager) =>
67
+ Utils .getColor (eval (payload["styles" ]? ["dragHandleColor" ], scopeManager));
68
+
62
69
bool ? isScrollable (scopeManager) =>
63
70
Utils .optionalBool (eval (payload["scrollable" ], scopeManager));
64
71
72
+ // scroll options
73
+ double ? _initialViewport (scopeManager) => Utils .optionalDouble (
74
+ eval (payload["scrollOptions" ]? ["initialViewport" ], scopeManager),
75
+ min: 0 ,
76
+ max: 1 );
77
+
78
+ double ? _minViewport (scopeManager) => Utils .optionalDouble (
79
+ eval (payload["scrollOptions" ]? ["minViewport" ], scopeManager),
80
+ min: 0 ,
81
+ max: 1 );
82
+
83
+ double ? _maxViewport (scopeManager) => Utils .optionalDouble (
84
+ eval (payload["scrollOptions" ]? ["maxViewport" ], scopeManager),
85
+ min: 0 ,
86
+ max: 1 );
87
+
65
88
@override
66
89
Future <dynamic > execute (BuildContext context, ScopeManager scopeManager) {
67
90
if (body != null ) {
@@ -70,10 +93,10 @@ class ShowBottomModalAction extends EnsembleAction {
70
93
// disable the default bottom sheet styling since we use our own
71
94
backgroundColor: Colors .transparent,
72
95
elevation: 0 ,
96
+ showDragHandle: false ,
73
97
74
98
barrierColor: getBarrierColor (scopeManager),
75
99
isScrollControlled: true ,
76
- showDragHandle: true ,
77
100
enableDrag: true ,
78
101
// padding to account for the keyboard when we have input widgets inside the modal
79
102
builder: (modalContext) => Padding (
@@ -102,8 +125,25 @@ class ShowBottomModalAction extends EnsembleAction {
102
125
Widget getBodyWidget (ScopeManager scopeManager, BuildContext context) {
103
126
var widget = scopeManager.buildWidgetFromDefinition (body);
104
127
if (isScrollable (scopeManager) == true ) {
128
+ // fix the viewport numbers if used incorrectly
129
+ double minViewport = _minViewport (scopeManager) ?? 0.25 ;
130
+ double maxViewport = _maxViewport (scopeManager) ?? 1 ;
131
+ if (minViewport > maxViewport) {
132
+ // reset
133
+ minViewport = 0.25 ;
134
+ maxViewport = 1 ;
135
+ }
136
+ double initialViewport = _initialViewport (scopeManager) ?? 0.5 ;
137
+ if (initialViewport < minViewport || initialViewport > maxViewport) {
138
+ // to middle
139
+ initialViewport = (minViewport + maxViewport) / 2.0 ;
140
+ }
141
+
105
142
return DraggableScrollableSheet (
106
143
expand: false ,
144
+ minChildSize: minViewport,
145
+ maxChildSize: maxViewport,
146
+ initialChildSize: initialViewport,
107
147
builder: (context, scrollController) =>
108
148
buildRootContainer (scopeManager, context,
109
149
child: SingleChildScrollView (
@@ -117,7 +157,7 @@ class ShowBottomModalAction extends EnsembleAction {
117
157
// This is the root container where all the root styling happen
118
158
Widget buildRootContainer (ScopeManager scopeManager, BuildContext context,
119
159
{required Widget child}) {
120
- return Container (
160
+ Widget rootWidget = Container (
121
161
margin: margin (scopeManager),
122
162
padding: padding (scopeManager),
123
163
decoration: BoxDecoration (
@@ -128,8 +168,28 @@ class ShowBottomModalAction extends EnsembleAction {
128
168
topLeft: defaultTopBorderRadius,
129
169
topRight: defaultTopBorderRadius)),
130
170
clipBehavior: Clip .antiAlias,
131
- width: double .infinity, // stretch width 100%
171
+ width: double .infinity,
172
+ // stretch width 100%
132
173
child: useSafeArea (scopeManager) ? SafeArea (child: child) : child);
174
+ if (showDragHandle (scopeManager)) {
175
+ rootWidget = Stack (
176
+ alignment: Alignment .topCenter,
177
+ children: [rootWidget, _buildDragHandle (scopeManager)],
178
+ );
179
+ }
180
+ return rootWidget;
181
+ }
182
+
183
+ Widget _buildDragHandle (ScopeManager scopeManager) {
184
+ return Container (
185
+ margin: const EdgeInsets .only (top: 10 ),
186
+ width: 32 ,
187
+ height: 3 ,
188
+ decoration: BoxDecoration (
189
+ color: dragHandleColor (scopeManager) ?? Colors .grey[500 ],
190
+ borderRadius: BorderRadius .circular (12 ),
191
+ ),
192
+ );
133
193
}
134
194
}
135
195
0 commit comments