Created
August 10, 2018 20:59
-
-
Save Rahiche/f57083652379e716d0a48ed707bb5e6a to your computer and use it in GitHub Desktop.
How to scroll to the beginning / end of the ListView
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: new MyApp())); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
var mylist = List.generate(500, (i) => "Flutter $i"); | |
var _controller = ScrollController(); | |
var _controller2 = ScrollController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
_controller.animateTo(0.0, | |
curve: Curves.easeInOut, duration: Duration(seconds: 1)); | |
_controller2.animateTo(_controller.position.maxScrollExtent, | |
curve: Curves.easeInOut, duration: Duration(seconds: 1)); | |
}, | |
), | |
body: Row( | |
children: <Widget>[ | |
Expanded( | |
child: ListView( | |
controller: _controller, | |
children: mylist.map((item) { | |
return ListTile( | |
leading: FlutterLogo(), | |
title: Text(item), | |
); | |
}).toList(), | |
), | |
), | |
Expanded( | |
child: ListView( | |
controller: _controller2, | |
children: mylist.map((item) { | |
return ListTile( | |
leading: FlutterLogo( | |
colors: Colors.red, | |
), | |
title: Text(item), | |
); | |
}).toList(), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment