Last active
December 3, 2021 02:10
-
-
Save ltvu93/d2abc42436b13f6009a7f4d5f2b36119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'dart:ui'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
static const ITEM_COUNT = 10; | |
static const ITEM_HEIGHT = 150.0; | |
static const ITEM_PADDING = 16.0; | |
ScrollController controller = ScrollController(); | |
Random random = Random(); | |
double scrollPercent = 0; | |
@override | |
void initState() { | |
super.initState(); | |
controller.addListener(() { | |
setState(() { | |
scrollPercent = (controller.offset / controller.position.maxScrollExtent).clamp(0.0, 1.0); | |
print('scrollPercent $scrollPercent'); | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: SafeArea( | |
child: SingleChildScrollView( | |
padding: const EdgeInsets.all(16), | |
controller: controller, | |
child: Column( | |
children: <Widget>[ | |
SizedBox( | |
height: 200, | |
child: ListView.builder( | |
scrollDirection: Axis.horizontal, | |
itemCount: 10, | |
itemBuilder: (_, __) { | |
return Container( | |
width: 200, | |
color: Color.fromARGB( | |
255, | |
random.nextInt(255), | |
random.nextInt(255), | |
random.nextInt(255), | |
), | |
); | |
}, | |
), | |
), | |
SizedBox(height: 16), | |
SizedBox( | |
height: | |
ITEM_COUNT * ITEM_HEIGHT + (ITEM_COUNT - 1) * ITEM_PADDING, | |
child: ListView.separated( | |
primary: false, | |
shrinkWrap: true, | |
itemCount: ITEM_COUNT, | |
separatorBuilder: (_, __) => SizedBox(height: ITEM_PADDING), | |
itemBuilder: (context, index) { | |
return Align( | |
alignment: Alignment.topCenter, | |
heightFactor: lerpDouble(0.2, 1.0, scrollPercent), | |
child: Container( | |
width: double.infinity, | |
height: ITEM_HEIGHT, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.all( | |
Radius.circular(10.0), | |
), | |
color: Colors.white, | |
boxShadow: [ | |
BoxShadow( | |
color: Colors.black.withAlpha(100), | |
blurRadius: 10.0, | |
), | |
], | |
), | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Text("Item $index"), | |
), | |
), | |
); | |
}, | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/passsy/9f1805606433300e5863ef969dadabcb