Skip to content

Instantly share code, notes, and snippets.

@Piinks
Created August 17, 2020 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Piinks/35699be6e7c7c12fb4cd65e7f4273dbb to your computer and use it in GitHub Desktop.
Save Piinks/35699be6e7c7c12fb4cd65e7f4273dbb to your computer and use it in GitHub Desktop.
Inverted scrollables
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