Skip to content

Instantly share code, notes, and snippets.

@yyoon
Created February 14, 2017 21:19
Show Gist options
  • Select an option

  • Save yyoon/8c0ef358de2d1b148ff1b2d0ffacc4db to your computer and use it in GitHub Desktop.

Select an option

Save yyoon/8c0ef358de2d1b148ff1b2d0ffacc4db to your computer and use it in GitHub Desktop.
ListView Scroll
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(primarySwatch: Colors.blue),
home: new MyHomePage(
title: 'Flutter Demo Home Page',
initialHeight: 800.0,
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title, this.initialHeight}) : super(key: key);
final String title;
final double initialHeight;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double height;
@override
void initState() {
super.initState();
height = config.initialHeight;
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text(config.title)),
body: new Center(child: new MyBody(height: height)),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.remove),
onPressed: () => setState(() => height -= 200.0),
),
);
}
}
class MyBody extends StatelessWidget {
MyBody({Key key, this.height}) : super(key: key);
final double height;
@override
Widget build(BuildContext context) {
return new ListView(
children: <Widget>[
new Container(
decoration: new BoxDecoration(backgroundColor: Colors.red[500]),
height: height,
),
new Container(
decoration: new BoxDecoration(backgroundColor: Colors.green[500]),
height: 500.0,
),
new Container(
decoration: new BoxDecoration(backgroundColor: Colors.blue[500]),
height: 500.0,
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment