Skip to content

Instantly share code, notes, and snippets.

@ltvu93
Last active December 3, 2021 02:10
Show Gist options
  • Save ltvu93/d2abc42436b13f6009a7f4d5f2b36119 to your computer and use it in GitHub Desktop.
Save ltvu93/d2abc42436b13f6009a7f4d5f2b36119 to your computer and use it in GitHub Desktop.
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"),
),
),
);
},
),
),
],
),
),
),
);
}
}
@ltvu93
Copy link
Author

ltvu93 commented Dec 3, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment