Skip to content

Commit

Permalink
ScrollPhysics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkko committed Oct 10, 2022
1 parent ca823ce commit ed8b9f2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 29 deletions.
81 changes: 57 additions & 24 deletions example/lib/demo/pages/dismissible_page_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,16 @@ class LargeImages extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Title('Scrollable'),
...images.map((imagePath) =>
LargeImageItem(imagePath: imagePath, pageModel: pageModel)),
...images.asMap().entries.map((entry) {
return LargeImageItem(
imagePath: entry.value,
pageModel: pageModel,
scrollPhysics: entry.key.isOdd
? ClampingScrollPhysics()
: BouncingScrollPhysics(),
);
}),
SizedBox(height: 100),
],
),
);
Expand Down Expand Up @@ -371,44 +379,67 @@ const home2ImagePath = 'assets/images/home_2.png';
const images = [home1ImagePath, home2ImagePath];

class LargeImageItem extends StatelessWidget {
final DismissiblePageModel pageModel;
final String imagePath;

LargeImageItem({
required this.imagePath,
required this.pageModel,
required this.scrollPhysics,
});

final DismissiblePageModel pageModel;
final String imagePath;
final ScrollPhysics scrollPhysics;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
// Use extension method to use [TransparentRoute]
// This will push page without route background
context.pushTransparentRoute(
LargeImageDetailsPage(imagePath: imagePath, pageModel: pageModel));
LargeImageDetailsPage(
imagePath: imagePath,
pageModel: pageModel,
scrollPhysics: scrollPhysics,
),
);
},
behavior: HitTestBehavior.translucent,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Stack(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Hero(
tag: imagePath,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.asset(
imagePath,
fit: BoxFit.cover,
Stack(
children: [
Hero(
tag: imagePath,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.asset(
imagePath,
fit: BoxFit.cover,
),
),
),
),
Positioned(
top: 10,
right: 10,
child: Icon(
Icons.favorite_border,
color: Colors.white,
),
),
],
),
Positioned(
top: 10,
right: 10,
child: Icon(
Icons.favorite_border,
color: Colors.white,
SizedBox(height: 5),
Text(
scrollPhysics is BouncingScrollPhysics
? 'iOS (BouncingScrollPhysics)'
: 'Android (ClampingScrollPhysics)',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
],
Expand All @@ -419,13 +450,14 @@ class LargeImageItem extends StatelessWidget {
}

class LargeImageDetailsPage extends StatelessWidget {
final DismissiblePageModel pageModel;

const LargeImageDetailsPage({
required this.imagePath,
required this.pageModel,
required this.scrollPhysics,
});

final DismissiblePageModel pageModel;
final ScrollPhysics scrollPhysics;
final String imagePath;

@override
Expand All @@ -435,13 +467,14 @@ class LargeImageDetailsPage extends StatelessWidget {
// direction: DismissiblePageDismissDirection.multi,
child: Scaffold(
body: SingleChildScrollView(
physics: scrollPhysics,
child: Column(
children: [
Hero(
tag: imagePath,
child: Image.asset(imagePath, fit: BoxFit.cover),
),
...List.generate(13, (index) => index + 1).map((index) {
...List.generate(25, (index) => index + 1).map((index) {
return ListTile(
title: Text(
'Item $index',
Expand Down
7 changes: 2 additions & 5 deletions lib/src/dismissible_page_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ class _DismissiblePageScrollBehavior extends ScrollBehavior {
@override
Widget buildOverscrollIndicator(_, Widget child, __) => child;

// @override
// TargetPlatform getPlatform(BuildContext context) => TargetPlatform.android;
//
// @override
// ScrollPhysics getScrollPhysics(_) =>
// const ClampingScrollPhysics(parent: RangeMaintainingScrollPhysics());
// const BouncingScrollPhysics(parent: RangeMaintainingScrollPhysics());
// // const ClampingScrollPhysics(parent: RangeMaintainingScrollPhysics());
// const BouncingScrollPhysics(parent: RangeMaintainingScrollPhysics());
}

mixin _DismissiblePageMixin {
Expand Down

0 comments on commit ed8b9f2

Please sign in to comment.