1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| class FlowPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flow'), ), body: Flow( delegate: MyFlowDelegate(), children: <Widget>[ Ball(80, Colors.cyan), Ball(70, Colors.purple), Ball(90, Colors.grey), Ball(50, Colors.red), Ball(10, Colors.green), Ball(20, Colors.black), Ball(40, Colors.blue), Ball(50, Colors.pink), Ball(100, Colors.orange), ], ), ); } }
class MyFlowDelegate extends FlowDelegate { @override void paintChildren(FlowPaintingContext context) { var x = 0.0; var y = 0.0; var maxHeight = 0.0; for (int i = 0; i < context.childCount; i++) { var w = context.getChildSize(i).width + x; var h = context.getChildSize(i).height; if (w < context.size.width) { context.paintChild(i, transform: new Matrix4.translationValues(x, y, 0.0)); x = w; maxHeight = max(maxHeight, h); } else { x = 0.0; y += maxHeight; context.paintChild(i, transform: new Matrix4.translationValues(x, y, 0.0)); x += context.getChildSize(i).width; } } }
@override Size getSize(BoxConstraints constraints) { return super.getSize(constraints); }
@override bool shouldRepaint(FlowDelegate oldDelegate) { return oldDelegate != this; } }
class Ball extends StatelessWidget { double _size; Color _color;
Ball(double size, Color color) { this._size = size; this._color = color; }
@override Widget build(BuildContext context) { return Container( width: _size, height: _size, decoration: BoxDecoration( borderRadius: BorderRadius.circular(_size / 2), color: _color), ); } }
|