@@ -31,26 +31,6 @@ const double _kMinFlingVelocity = 700.0;
3131const double _kCloseProgressThreshold = 0.5 ;
3232const double _kDefaultScrollControlDisabledMaxHeightRatio = 9.0 / 16.0 ;
3333
34- /// Internal coordination between [Scaffold] and [BottomSheet] .
35- ///
36- /// Only persistent sheets receive an extension. Modal sheets and standalone
37- /// [BottomSheet] s retain their existing layout policy.
38- @internal
39- class BottomSheetKeyboardInset extends InheritedWidget {
40- /// Supplies the extra surface extent computed by [Scaffold] .
41- const BottomSheetKeyboardInset ({super .key, required this .bottom, required super .child});
42-
43- /// The distance below the usable sheet area, in logical pixels.
44- final double bottom;
45-
46- /// Returns zero outside a persistent sheet or below its content boundary.
47- static double of (BuildContext context) =>
48- context.dependOnInheritedWidgetOfExactType <BottomSheetKeyboardInset >()? .bottom ?? 0.0 ;
49-
50- @override
51- bool updateShouldNotify (BottomSheetKeyboardInset oldWidget) => bottom != oldWidget.bottom;
52- }
53-
5434/// A callback for when the user begins dragging the bottom sheet.
5535///
5636/// Used by [BottomSheet.onDragStart] .
@@ -113,9 +93,11 @@ class BottomSheet extends StatefulWidget {
11393 this .shape,
11494 this .clipBehavior,
11595 this .constraints,
96+ this .bottomInset = 0.0 ,
11697 required this .onClosing,
11798 required this .builder,
118- }) : assert (elevation == null || elevation >= 0.0 );
99+ }) : assert (elevation == null || elevation >= 0.0 ),
100+ assert (bottomInset >= 0.0 && bottomInset < double .infinity);
119101
120102 /// The animation controller that controls the bottom sheet's entrance and
121103 /// exit animations.
@@ -256,6 +238,21 @@ class BottomSheet extends StatefulWidget {
256238 /// the available space. Otherwise, no alignment is applied.
257239 final BoxConstraints ? constraints;
258240
241+ /// Additional space below the content and drag handle, painted by the sheet's
242+ /// [Material] background.
243+ ///
244+ /// This space is added to the height [constraints] , preserving the space
245+ /// available to the content, subject to the parent's constraints. It does not
246+ /// add any width or read the ambient [MediaQuery] .
247+ ///
248+ /// [Scaffold] sets this when a persistent sheet avoids the keyboard. Custom
249+ /// presentations can also use it to extend the surface while keeping content
250+ /// above an inset. The presentation is responsible for positioning the sheet
251+ /// and keeping the inset area out of hit testing and accessibility bounds.
252+ ///
253+ /// Defaults to zero. Must be finite and non-negative.
254+ final double bottomInset;
255+
259256 @override
260257 State <BottomSheet > createState () => _BottomSheetState ();
261258
@@ -375,7 +372,7 @@ class _BottomSheetState extends State<BottomSheet> {
375372 // Scaffold reserves this space for the persistent sheet's surface. Inflate
376373 // height constraints before adding padding so the builder retains its
377374 // original constraints, including explicit or themed min/max heights.
378- final double keyboardInset = BottomSheetKeyboardInset . of (context) ;
375+ final double keyboardInset = widget.bottomInset ;
379376 final BoxConstraints ? contentConstraints =
380377 widget.constraints ?? bottomSheetTheme.constraints ?? defaults.constraints;
381378 final BoxConstraints ? constraints = contentConstraints? .copyWith (
@@ -426,23 +423,20 @@ class _BottomSheetState extends State<BottomSheet> {
426423 clipBehavior: clipBehavior,
427424 child: Padding (
428425 padding: EdgeInsets .only (bottom: keyboardInset),
429- child: BottomSheetKeyboardInset (
430- bottom: 0.0 ,
431- child: NotificationListener <DraggableScrollableNotification >(
432- onNotification: extentChanged,
433- child: ! showDragHandle
434- ? widget.builder (context)
435- : Stack (
436- alignment: Alignment .topCenter,
437- children: < Widget > [
438- dragHandle! ,
439- Padding (
440- padding: const EdgeInsets .only (top: kMinInteractiveDimension),
441- child: widget.builder (context),
442- ),
443- ],
444- ),
445- ),
426+ child: NotificationListener <DraggableScrollableNotification >(
427+ onNotification: extentChanged,
428+ child: ! showDragHandle
429+ ? widget.builder (context)
430+ : Stack (
431+ alignment: Alignment .topCenter,
432+ children: < Widget > [
433+ dragHandle! ,
434+ Padding (
435+ padding: const EdgeInsets .only (top: kMinInteractiveDimension),
436+ child: widget.builder (context),
437+ ),
438+ ],
439+ ),
446440 ),
447441 ),
448442 );
0 commit comments