Created
August 17, 2020 22:13
-
-
Save Piinks/35699be6e7c7c12fb4cd65e7f4273dbb to your computer and use it in GitHub Desktop.
Inverted scrollables
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 'package:flutter/material.dart'; | |
void main() { | |
runApp(MaterialApp(home: Home())); | |
} | |
class Home extends StatefulWidget { | |
@override | |
State createState() => HomeState(); | |
} | |
class HomeState extends State<Home> { | |
ScrollController _scrollController = new ScrollController(); | |
double height; | |
@override | |
void initState() { | |
height = 200.0; | |
_scrollController.addListener(_maybeUpdateSize); | |
super.initState(); | |
} | |
void _maybeUpdateSize() { | |
final ScrollPosition position = _scrollController.position; | |
if (position.pixels >= 0.0 && position.pixels <= 150.0) { | |
setState((){ | |
height = 200.0 - position.pixels; | |
}); | |
} | |
} | |
@override | |
void dispose() { | |
_scrollController.dispose(); | |
super.dispose(); | |
} | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
toolbarHeight: height, | |
title: Text('demo'), | |
), | |
body: ListView.builder( | |
controller: _scrollController, | |
reverse: true, | |
padding: const EdgeInsets.all(8), | |
itemCount: 50, | |
itemBuilder: (BuildContext context, int index) { | |
return Container( | |
height: 50, | |
child: Center(child: Text('Entry $index')), | |
); | |
} | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment