Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Flutter scrollable horizontal list widget which animates into place on load.
import 'package:flutter/material.dart';
import './animation_mixins.dart'; // See my other gist for this
/// A scrollable horizontal list which animates into place on load.
class ListPicker extends StatefulWidget {
final List<Widget> children;
final double paddingX, paddingY;
const ListPicker({
this.paddingX = 12.0,
this.paddingY = 12.0,
_ListPickerState createState() => _ListPickerState();
class _ListPickerState extends State<ListPicker> with StateDelay {
ScrollController _controller;
_getController() {
if (_controller != null) return _controller;
var cont = ScrollController(initialScrollOffset: 100);
// This delay is required to allow the controller to bind the scroll view
delay(0, () => cont.animateTo(0,
duration: Duration(milliseconds: 500), curve: Curves.easeOut));
setState(() => _controller = cont);
return cont;
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(10),
child: SingleChildScrollView(
controller: _getController(),
scrollDirection: Axis.horizontal,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: widget.paddingX, vertical: widget.paddingY),
child: Row(children: widget.children),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment