Closed
Description
Issue by HansMuller
Monday Sep 21, 2015 at 22:46 GMT
Originally opened as https://github.com/flutter/engine/issues/1263
A ScrollableList with scrollDirection: ScrollDirection.horizontal
ends up consuming all available vertical space. Having it occupy its "natural" vertical extent instead, i.e. the height of the highest element seen so far, would be more intuitive. As a result, centering a horizontal scrolling list can be frustrating. Centering it in terms of its natural height doesn't appear to be possible.
import 'dart:async';
import 'package:sky/widgets.dart';
import 'package:sky/rendering.dart';
// This app wants to put a horizontal ScrollableList in the center
// of the screen. What happens instead is that the occupies
// all available height.
//
// The code that's not commented out was my hopeful approach.
class TestApp extends App {
static const double itemExtent = 50.0;
Widget build() {
Widget list = new ScrollableList<int>(
scrollDirection: ScrollDirection.horizontal,
items: new List.generate(50, (n) => n),
itemExtent: itemExtent,
itemBuilder: (n) {
return new Container(
key: new ValueKey<int>(n),
width: itemExtent,
// Surprisingly, providing an item height doesn't affect the layout.
// Don't want to specify a height anyway.
// height: 100.0,
decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00)),
child: new Text("Item $n")
);
}
);
// This works but requires giving the list a fixed height. FTR: specifying
// shrinkWrap: ShrinkWrap.height for Center doesn't change anything.
// return new Center(child: new Container(child: list, height: 100.0));
// This fails, the list ends up at the top of the screen and extends to the bottom.
return new Center(child: list);
}
}
void main() {
runApp(new TestApp());
//new Timer(new Duration(seconds: 1), debugDumpRenderTree);
}