Skip to content

Commit

Permalink
Many changes (#5804)
Browse files Browse the repository at this point in the history
(cherry picked from commit eb6b774dd0e9170aa9271f2cea33b2c5738b0a9d)
  • Loading branch information
g123k authored Nov 7, 2024
1 parent b1005ce commit a25d09a
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ Future<T?> showSmoothDraggableModalSheet<T>({
/// You must return a Sliver Widget
required WidgetBuilder bodyBuilder,
double? initHeight,
double? minHeight,
double? maxHeight,
DraggableScrollableController? draggableScrollableController,
}) {
return showDraggableModalSheet<T>(
context: context,
draggableScrollableController: draggableScrollableController,
borderRadius: const BorderRadius.vertical(top: ROUNDED_RADIUS),
headerBuilder: (_) => header,
headerHeight: header.computeHeight(context),
bodyBuilder: bodyBuilder,
initHeight: initHeight,
minHeight: minHeight,
maxHeight: maxHeight,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class SmoothDraggableBottomSheet extends StatefulWidget {
required this.bodyBuilder,
required this.borderRadius,
this.initHeightFraction = 0.5,
this.minHeightFraction,
this.maxHeightFraction = 1.0,
this.animationController,
this.bottomSheetColor,
this.draggableScrollableController,
}) : assert(maxHeightFraction > 0.0 && maxHeightFraction <= 1.0);

final double initHeightFraction;
final double? minHeightFraction;
final double maxHeightFraction;
final WidgetBuilder headerBuilder;
final double headerHeight;
Expand Down Expand Up @@ -52,55 +54,63 @@ class SmoothDraggableBottomSheetState
Theme.of(context).scaffoldBackgroundColor;
final double bottomPaddingHeight = MediaQuery.paddingOf(context).bottom;

return NotificationListener<DraggableScrollableNotification>(
onNotification: _scrolling,
child: Column(
children: <Widget>[
Expanded(
child: SafeArea(
bottom: false,
child: DraggableScrollableSheet(
minChildSize: 0.0,
maxChildSize: widget.maxHeightFraction,
initialChildSize: widget.initHeightFraction,
snap: true,
controller: _controller,
builder: (BuildContext context, ScrollController controller) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: widget.borderRadius,
color: backgroundColor,
),
child: Material(
type: MaterialType.transparency,
child: ClipRRect(
// Fix keyboard glitch
final double keyboardFraction = MediaQuery.viewInsetsOf(context).bottom /
MediaQuery.sizeOf(context).height;

return ChangeNotifierProvider<DraggableScrollableController>(
create: (_) => _controller,
child: NotificationListener<DraggableScrollableNotification>(
onNotification: _scrolling,
child: Column(
children: <Widget>[
Expanded(
child: SafeArea(
bottom: false,
child: DraggableScrollableSheet(
minChildSize: widget.minHeightFraction ?? 0.0,
maxChildSize: widget.maxHeightFraction,
initialChildSize:
widget.initHeightFraction + keyboardFraction,
snap: true,
controller: _controller,
builder: (BuildContext context, ScrollController controller) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: widget.borderRadius,
child: _SmoothDraggableContent(
bodyBuilder: widget.bodyBuilder,
headerBuilder: widget.headerBuilder,
headerHeight: widget.headerHeight,
currentExtent: _controller.isAttached
? _controller.size
: widget.initHeightFraction,
scrollController: controller,
cacheExtent: _calculateCacheExtent(
MediaQuery.viewInsetsOf(context).bottom,
color: backgroundColor,
),
child: Material(
type: MaterialType.transparency,
child: ClipRRect(
borderRadius: widget.borderRadius,
child: _SmoothDraggableContent(
bodyBuilder: widget.bodyBuilder,
headerBuilder: widget.headerBuilder,
headerHeight: widget.headerHeight,
currentExtent: _controller.isAttached
? _controller.size
: widget.initHeightFraction,
scrollController: controller,
cacheExtent: _calculateCacheExtent(
MediaQuery.viewInsetsOf(context).bottom,
),
),
),
),
),
);
},
);
},
),
),
),
),
if (bottomPaddingHeight > 0)
SizedBox(
width: double.infinity,
height: bottomPaddingHeight,
child: ColoredBox(color: backgroundColor),
),
],
if (bottomPaddingHeight > 0)
SizedBox(
width: double.infinity,
height: bottomPaddingHeight,
child: ColoredBox(color: backgroundColor),
),
],
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Future<T?> showDraggableModalSheet<T>({
required double headerHeight,
required WidgetBuilder bodyBuilder,
required BorderRadiusGeometry borderRadius,
DraggableScrollableController? draggableScrollableController,
double? initHeight,
double? minHeight,
double? maxHeight,
Color? bottomSheetColor,
Color? barrierColor,
Expand All @@ -19,6 +21,7 @@ Future<T?> showDraggableModalSheet<T>({

return Navigator.of(context, rootNavigator: true).push(
_FlexibleBottomSheetRoute<T>(
draggableScrollableController: draggableScrollableController,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
initHeight: initHeight ?? 0.5,
bodyBuilder: bodyBuilder,
Expand All @@ -38,6 +41,8 @@ class _FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
required this.headerHeight,
required this.bodyBuilder,
required this.borderRadius,
this.minHeight,
this.draggableScrollableController,
this.barrierLabel,
this.bottomSheetBackgroundColor,
super.settings,
Expand All @@ -46,9 +51,11 @@ class _FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
final WidgetBuilder headerBuilder;
final double headerHeight;
final WidgetBuilder bodyBuilder;
final double? minHeight;
final double initHeight;
final BorderRadiusGeometry borderRadius;
final Color? bottomSheetBackgroundColor;
final DraggableScrollableController? draggableScrollableController;

@override
final String? barrierLabel;
Expand Down Expand Up @@ -85,6 +92,7 @@ class _FlexibleBottomSheetRoute<T> extends PopupRoute<T> {
context: context,
child: SmoothDraggableBottomSheet(
initHeightFraction: initHeight,
draggableScrollableController: draggableScrollableController,
headerBuilder: headerBuilder,
bodyBuilder: bodyBuilder,
animationController: _animationController,
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@
"@user_list_button_new": {
"description": "Short label of a 'create a new list' button"
},
"user_list_empty_label": "No list available yet, please start by creating one",
"user_list_empty_label": "No list available yet!\nPlease start by creating one.",
"@user_list_empty_label": {
"description": "Content displayed when there is no list"
},
Expand Down
Loading

0 comments on commit a25d09a

Please sign in to comment.