I have now the size of the parent and I can compute the best size.
However I face a problem with my changes. Now I have only one Card displayed (in a Block with many Cards) instead of many (actually, the builder is called so the cards seem to be on each other). Here is a simple repro :
void main() {
runApp(new MaterialApp(home: new Scaffold(
appBar: new AppBar(title: new Text('test')),
body: new Block(
padding: new EdgeInsets.symmetric(horizontal: 8.0),
children: ['a', 'b', 'c'].map((m) => new MyWidget(m)).toList()))));
}
// with LayoutBuilder the Block container displays only the 'a' card
class MyWidget extends StatelessWidget {
MyWidget(this.text);
String text;
@override
Widget build(BuildContext context) {
return new LayoutBuilder(builder: (context, size) {
print('build $text');
final height = min(200, size.height).toInt();
final width = min(400, size.width).toInt();
return new Card(child: new Column(children: [
'?size=${width}x$height'
'¢er=Berkeley,CA&zoom=14'),
new Text(text)
]));
});
}
}
// without LayoutBuilder the Block container displays all the card
class MyWidget2 extends StatelessWidget {
MyWidget2(this.text);
String text;
@override
Widget build(BuildContext context) {
final height = 200;
final width = 400;
return new Card(child: new Column(children: [
'?size=${width}x$height'
'¢er=Berkeley,CA&zoom=14'),
new Text(text)
]));
}
}