Skip to content

Commit 9aa6653

Browse files
committed
Shrink Top List was added
1 parent 9474784 commit 9aa6653

File tree

3 files changed

+128
-2
lines changed

3 files changed

+128
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ You can follow me on twitter [@diegoveloper](https://www.twitter.com/diegovelope
6565
|--|--|
6666
| <center> <img src="https://media.giphy.com/media/QuIvsrhjCr4oPS49qa/giphy.gif" width="250"/> </center> | <center> <img src="https://media.giphy.com/media/gF30YeWCn0Ncf0qxCS/giphy.gif" width="250"/>
6767

68+
| [Animations / Shrink Top List](https://www.youtube.com/watch?v=becUP_s-KfU) | |
69+
|--|--|
70+
| <center> <img src="https://media.giphy.com/media/XFproCCYQ9eDR416g1/giphy.gif" width="250"/> </center> | <center> </center>

lib/animations/main_animations.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:flutter_samples/main.dart';
1010

1111
import 'custom_sliverheader/custom_sliver_header.dart';
1212
import 'hide_my_widgets/main_hide_my_widgets.dart';
13+
import 'shrink_top_list/shrink_top_list_page.dart';
1314

1415
class MainAnimations extends StatefulWidget {
1516
@override
@@ -20,8 +21,7 @@ class MainAnimations extends StatefulWidget {
2021

2122
class MainAnimationsState extends State<MainAnimations> {
2223
onButtonTap(Widget page) {
23-
Navigator.push(
24-
context, MaterialPageRoute(builder: (BuildContext context) => page));
24+
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => page));
2525
}
2626

2727
@override
@@ -88,6 +88,12 @@ class MainAnimationsState extends State<MainAnimations> {
8888
onButtonTap(MainMenuExploration());
8989
},
9090
),
91+
MyMenuButton(
92+
title: "Shrink Top List",
93+
actionTap: () {
94+
onButtonTap(ShrinkTopListPage());
95+
},
96+
),
9197
],
9298
),
9399
),
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_samples/animations/list_details/character.dart';
3+
4+
const itemSize = 150.0;
5+
6+
class ShrinkTopListPage extends StatefulWidget {
7+
@override
8+
_ShrinkTopListPageState createState() => _ShrinkTopListPageState();
9+
}
10+
11+
class _ShrinkTopListPageState extends State<ShrinkTopListPage> {
12+
final scrollController = ScrollController();
13+
14+
void onListen() {
15+
setState(() {});
16+
}
17+
18+
@override
19+
void initState() {
20+
characters.addAll(List.from(characters));
21+
scrollController.addListener(onListen);
22+
super.initState();
23+
}
24+
25+
@override
26+
void dispose() {
27+
scrollController.removeListener(onListen);
28+
super.dispose();
29+
}
30+
31+
@override
32+
Widget build(BuildContext context) {
33+
return Scaffold(
34+
appBar: AppBar(
35+
title: Text('Shrink top List'),
36+
),
37+
body: Padding(
38+
padding: const EdgeInsets.only(left: 15.0, right: 15.0, top: 15.0),
39+
child: CustomScrollView(
40+
controller: scrollController,
41+
slivers: <Widget>[
42+
SliverToBoxAdapter(
43+
child: Placeholder(
44+
fallbackHeight: 100.0,
45+
),
46+
),
47+
SliverAppBar(
48+
automaticallyImplyLeading: false,
49+
title: Text(
50+
'My Characters',
51+
style: TextStyle(color: Colors.black),
52+
),
53+
pinned: true,
54+
backgroundColor: Colors.transparent,
55+
elevation: 0,
56+
),
57+
SliverToBoxAdapter(
58+
child: const SizedBox(
59+
height: 50,
60+
),
61+
),
62+
SliverList(
63+
delegate: SliverChildBuilderDelegate(
64+
(context, index) {
65+
final heightFactor = 0.6;
66+
final character = characters[index];
67+
final itemPositionOffset = index * itemSize * heightFactor;
68+
final difference = scrollController.offset - itemPositionOffset;
69+
final percent = 1.0 - (difference / (itemSize * heightFactor));
70+
double opacity = percent;
71+
double scale = percent;
72+
if (opacity > 1.0) opacity = 1.0;
73+
if (opacity < 0.0) opacity = 0.0;
74+
if (percent > 1.0) scale = 1.0;
75+
76+
return Align(
77+
heightFactor: heightFactor,
78+
child: Opacity(
79+
opacity: opacity,
80+
child: Transform(
81+
alignment: Alignment.center,
82+
transform: Matrix4.identity()..scale(scale, 1.0),
83+
child: Card(
84+
shape: RoundedRectangleBorder(
85+
borderRadius: BorderRadius.only(
86+
topLeft: Radius.circular(20.0),
87+
topRight: Radius.circular(20.0),
88+
),
89+
),
90+
color: Color(character.color),
91+
child: SizedBox(
92+
height: itemSize,
93+
child: Row(
94+
children: <Widget>[
95+
Expanded(
96+
child: Padding(
97+
padding: const EdgeInsets.all(15.0),
98+
),
99+
),
100+
Image.asset(character.avatar),
101+
],
102+
),
103+
),
104+
),
105+
),
106+
),
107+
);
108+
},
109+
childCount: characters.length,
110+
),
111+
),
112+
],
113+
),
114+
),
115+
);
116+
}
117+
}

0 commit comments

Comments
 (0)