Skip to content

Commit

Permalink
Merge draggable and scrollable sheet APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed Dec 1, 2024
1 parent 3897f4e commit 21d7615
Show file tree
Hide file tree
Showing 50 changed files with 466 additions and 1,048 deletions.
18 changes: 12 additions & 6 deletions example/lib/showcase/ai_playlist_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,43 @@ final _sheetShellRoute = ShellRoute(
final _introRoute = GoRoute(
path: 'intro',
pageBuilder: (context, state) {
return const DraggableNavigationSheetPage(child: _IntroPage());
return const NavigationSheetPage(child: _IntroPage());
},
routes: [_genreRoute],
);

final _genreRoute = GoRoute(
path: 'genre',
pageBuilder: (context, state) {
return const DraggableNavigationSheetPage(child: _SelectGenrePage());
return const NavigationSheetPage(child: _SelectGenrePage());
},
routes: [_moodRoute],
);

final _moodRoute = GoRoute(
path: 'mood',
pageBuilder: (context, state) {
return const DraggableNavigationSheetPage(child: _SelectMoodPage());
return const NavigationSheetPage(child: _SelectMoodPage());
},
routes: [_seedTrackRoute],
);

final _seedTrackRoute = GoRoute(
path: 'seed-track',
pageBuilder: (context, state) {
return const ScrollableNavigationSheetPage(child: _SelectSeedTrackPage());
return const NavigationSheetPage(
scrollConfiguration: SheetScrollConfiguration(),
child: _SelectSeedTrackPage(),
);
},
routes: [_confirmRoute],
);

final _confirmRoute = GoRoute(
path: 'confirm',
pageBuilder: (context, state) {
return const ScrollableNavigationSheetPage(
return const NavigationSheetPage(
scrollConfiguration: SheetScrollConfiguration(),
initialPosition: SheetAnchor.proportional(0.7),
minPosition: SheetAnchor.proportional(0.7),
physics: BouncingSheetPhysics(
Expand All @@ -119,7 +123,7 @@ final _confirmRoute = GoRoute(
final _generateRoute = GoRoute(
path: 'generate',
pageBuilder: (context, state) {
return const DraggableNavigationSheetPage(child: _GeneratingPage());
return const NavigationSheetPage(child: _GeneratingPage());
},
);

Expand Down Expand Up @@ -718,6 +722,7 @@ const _moods = [
(label: 'Uplifting and Positive', emoji: '💪'),
];

/* cSpell: disable */
const _seedTracks = [
"Groove Odyssey",
"Funky Fusion Fiesta",
Expand All @@ -740,3 +745,4 @@ const _seedTracks = [
"Brass Bliss Bouquet",
"Funky Cosmic Carnival",
];
/* cSpell: enable */
37 changes: 18 additions & 19 deletions example/lib/showcase/airbnb_mobile_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class _ContentSheet extends StatelessWidget {
);

return SheetViewport(
child: ScrollableSheet(
child: Sheet(
scrollConfiguration: const SheetScrollConfiguration(),
physics: sheetPhysics,
minPosition: minSheetPosition,
child: SizedBox(
Expand Down Expand Up @@ -209,26 +210,24 @@ class _ContentSheetHandle extends StatelessWidget

@override
Widget build(BuildContext context) {
return SheetDraggable(
child: SizedBox(
height: preferredSize.height,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
buildIndicator(),
const SizedBox(height: 16),
Expanded(
child: Center(
child: Text(
'646 national park homes',
style: Theme.of(context).textTheme.labelLarge,
),
return SizedBox(
height: preferredSize.height,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
buildIndicator(),
const SizedBox(height: 16),
Expanded(
child: Center(
child: Text(
'646 national park homes',
style: Theme.of(context).textTheme.labelLarge,
),
),
],
),
),
],
),
),
);
Expand Down
3 changes: 2 additions & 1 deletion example/lib/showcase/safari/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class EditActionsSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ScrollableSheet(
return Sheet(
scrollConfiguration: const SheetScrollConfiguration(),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: SheetContentScaffold(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/showcase/safari/bookmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EditBookmarkSheet extends StatelessWidget {
Widget build(BuildContext context) {
return SheetKeyboardDismissible(
dismissBehavior: const SheetKeyboardDismissBehavior.onDragDown(),
child: DraggableSheet(
child: Sheet(
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: SheetContentScaffold(
Expand Down
41 changes: 20 additions & 21 deletions example/lib/showcase/safari/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MenuSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
const halfWayPosition = SheetAnchor.proportional(0.5);
return ScrollableSheet(
return Sheet(
scrollConfiguration: const SheetScrollConfiguration(),
initialPosition: halfWayPosition,
minPosition: halfWayPosition,
physics: const BouncingSheetPhysics(
Expand Down Expand Up @@ -190,27 +191,25 @@ class _TopBar extends StatelessWidget {
?.copyWith(color: CupertinoColors.secondaryLabel),
);

return SheetDraggable(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SiteIcon(url: faviconUrl),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [pageTitle, displayUrl],
),
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SiteIcon(url: faviconUrl),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [pageTitle, displayUrl],
),
const SizedBox(width: 16),
const _CloseButton(),
],
),
),
const SizedBox(width: 16),
const _CloseButton(),
],
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion example/lib/showcase/todo_list/todo_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class _TodoEditorState extends State<TodoEditor> {
dismissBehavior: const SheetKeyboardDismissBehavior.onDragDown(
isContentScrollAware: true,
),
child: ScrollableSheet(
child: Sheet(
scrollConfiguration: const SheetScrollConfiguration(),
child: Container(
clipBehavior: Clip.antiAlias,
decoration: sheetShape,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/bottom_bar_visibility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _ExampleSheet extends StatelessWidget {

return SafeArea(
bottom: false,
child: DraggableSheet(
child: Sheet(
minPosition: minSize,
initialPosition: halfSize,
physics: multiStopPhysics,
Expand Down
17 changes: 9 additions & 8 deletions example/lib/tutorial/bouncing_behaviors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class _Home extends StatelessWidget {
),
ListTile(
title: const Text('FixedBouncingBehavior'),
subtitle: const Text('with DraggableSheet'),
subtitle: const Text('with Sheet'),
onTap: () => showModalSheet(
const _DraggableSheet(
const _Sheet(
behavior: FixedBouncingBehavior(
// Allows the sheet position to exceed the content bounds by ±50 pixels.
SheetAnchor.pixels(50),
Expand All @@ -61,9 +61,9 @@ class _Home extends StatelessWidget {
),
ListTile(
title: const Text('DirectionAwareBouncingBehavior'),
subtitle: const Text('with DraggableSheet'),
subtitle: const Text('with Sheet'),
onTap: () => showModalSheet(
const _DraggableSheet(
const _Sheet(
behavior: DirectionAwareBouncingBehavior(
// Allows the sheet to bounce only when dragging it downwards.
upward: SheetAnchor.pixels(0),
Expand All @@ -86,7 +86,8 @@ class _ScrollableSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ScrollableSheet(
return Sheet(
scrollConfiguration: const SheetScrollConfiguration(),
physics: BouncingSheetPhysics(behavior: behavior),
child: Material(
color: Colors.white,
Expand All @@ -104,14 +105,14 @@ class _ScrollableSheet extends StatelessWidget {
}
}

class _DraggableSheet extends StatelessWidget {
const _DraggableSheet({required this.behavior});
class _Sheet extends StatelessWidget {
const _Sheet({required this.behavior});

final BouncingBehavior behavior;

@override
Widget build(BuildContext context) {
return DraggableSheet(
return Sheet(
physics: BouncingSheetPhysics(behavior: behavior),
child: Container(
height: 500,
Expand Down
4 changes: 2 additions & 2 deletions example/lib/tutorial/cupertino_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _HalfScreenSheet extends StatelessWidget {
Widget build(BuildContext context) {
// `CupertinoStackedTransition` won't start the transition animation until
// the visible height of a modal sheet (the position) exceeds 50% of the screen height.
return const DraggableSheet(
return const Sheet(
initialPosition: SheetAnchor.proportional(0.5),
minPosition: SheetAnchor.proportional(0.5),
physics: BouncingSheetPhysics(
Expand All @@ -91,7 +91,7 @@ class _FullScreenSheet extends StatelessWidget {
Widget build(BuildContext context) {
// Wrap the sheet with `SheetDismissible` to
// enable the pull-to-dismiss action.
return const DraggableSheet(
return const Sheet(
child: _SheetContent(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/declarative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class _ExampleSheet extends StatelessWidget {
}
}
},
child: DraggableSheet(
child: Sheet(
child: Card(
color: Theme.of(context).colorScheme.secondaryContainer,
margin: EdgeInsets.zero,
Expand Down
12 changes: 6 additions & 6 deletions example/lib/tutorial/declarative_navigation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ final router = GoRouter(
GoRoute(
path: '/a',
pageBuilder: (context, state) {
// Use DraggableNavigationSheetPage for a draggable page.
// Use ScrollableNavigationSheetPage for a draggable page.
// If the page contains scrollable widget(s), consider using
// ScrollableNavigationSheetPage instead.
return DraggableNavigationSheetPage(
return NavigationSheetPage(
key: state.pageKey,
child: const _ExampleSheetContent(
title: '/a',
Expand All @@ -50,7 +50,7 @@ final router = GoRouter(
GoRoute(
path: 'details',
pageBuilder: (context, state) {
return DraggableNavigationSheetPage(
return NavigationSheetPage(
key: state.pageKey,
child: const _ExampleSheetContent(
title: '/a/details',
Expand All @@ -63,7 +63,7 @@ final router = GoRouter(
GoRoute(
path: 'info',
pageBuilder: (context, state) {
return DraggableNavigationSheetPage(
return NavigationSheetPage(
key: state.pageKey,
child: const _ExampleSheetContent(
title: '/a/details/info',
Expand All @@ -80,7 +80,7 @@ final router = GoRouter(
GoRoute(
path: '/b',
pageBuilder: (context, state) {
return DraggableNavigationSheetPage(
return NavigationSheetPage(
key: state.pageKey,
child: const _ExampleSheetContent(
title: 'B',
Expand All @@ -93,7 +93,7 @@ final router = GoRouter(
GoRoute(
path: 'details',
pageBuilder: (context, state) {
return DraggableNavigationSheetPage(
return NavigationSheetPage(
key: state.pageKey,
child: const _ExampleSheetContent(
title: 'B Details',
Expand Down
12 changes: 6 additions & 6 deletions example/lib/tutorial/draggable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';

void main() {
runApp(const _BasicDraggableSheetExample());
runApp(const _BasicSheetExample());
}

class _BasicDraggableSheetExample extends StatelessWidget {
const _BasicDraggableSheetExample();
class _BasicSheetExample extends StatelessWidget {
const _BasicSheetExample();

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -42,11 +42,11 @@ class _MySheet extends StatelessWidget {
),
);

// Then, wrap the content in DraggableSheet.
// Note that DraggableSheet does not work with scrollable widgets.
// Then, wrap the content in Sheet.
// Note that Sheet does not work with scrollable widgets.
// If you want to use a scrollable widget as its content,
// use ScrollableSheet instead.
return DraggableSheet(
return Sheet(
child: buildSheetBackground(context, content),
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/extent_driven_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _ExampleSheet extends StatelessWidget {
),
);

return DraggableSheet(
return Sheet(
minPosition: minPosition,
physics: physics,
child: Card(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/tutorial/imperative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _ExampleSheet extends StatelessWidget {
}
}
},
child: DraggableSheet(
child: Sheet(
minPosition: const SheetAnchor.proportional(0.5),
child: Card(
color: Theme.of(context).colorScheme.secondaryContainer,
Expand Down
Loading

0 comments on commit 21d7615

Please sign in to comment.