1+ import 'package:flutter/material.dart' ;
2+
3+ class Index extends StatelessWidget {
4+ List <Map <String , dynamic >> containerValue = [
5+ {
6+ 'color' : Colors .yellow
7+ },
8+ {
9+ 'color' : Colors .green
10+ },
11+ {
12+ 'color' : Colors .red
13+ },
14+ {
15+ 'color' : Colors .black
16+ },
17+ {
18+ 'color' : Colors .blue
19+ },
20+ {
21+ 'color' : Colors .lightGreenAccent
22+ },
23+ ];
24+
25+ @override
26+ Widget build (BuildContext context) {
27+ return Scaffold (
28+ appBar: AppBar (title: Text ('Flow' ),),
29+ body: Flow (
30+ delegate: TestFlowDelegate (margin: EdgeInsets .fromLTRB (10.0 , 10.0 , 10.0 , 10.0 )),
31+ children: List .generate (6 , (index) {
32+ return Container (
33+ width: 40.0 ,
34+ height: 40.0 ,
35+ color: containerValue[index]['color' ],
36+ );
37+ }),
38+ ),
39+ );
40+ }
41+ }
42+
43+ class FlowDelegates extends FlowDelegate {
44+ @override
45+ void paintChildren (FlowPaintingContext context) {}
46+
47+ @override
48+ bool shouldRepaint (FlowDelegate oldDelegeate) {
49+ return oldDelegeate != this ;
50+ }
51+ }
52+
53+ class TestFlowDelegate extends FlowDelegate {
54+ EdgeInsets margin = EdgeInsets .zero;
55+
56+ TestFlowDelegate ({this .margin});
57+ @override
58+ void paintChildren (FlowPaintingContext context) {
59+ var x = margin.left;
60+ var y = margin.top;
61+ for (int i = 0 ; i < context.childCount; i++ ) {
62+ var w = context.getChildSize (i).width + x + margin.right;
63+ if (w < context.size.width) {
64+ context.paintChild (i,
65+ transform: new Matrix4 .translationValues (
66+ x, y, 0.0 ));
67+ x = w + margin.left;
68+ } else {
69+ x = margin.left;
70+ y += context.getChildSize (i).height + margin.top + margin.bottom;
71+ context.paintChild (i,
72+ transform: new Matrix4 .translationValues (
73+ x, y, 0.0 ));
74+ x += context.getChildSize (i).width + margin.left + margin.right;
75+ }
76+ }
77+ }
78+
79+ @override
80+ bool shouldRepaint (FlowDelegate oldDelegate) {
81+ return oldDelegate != this ;
82+ }
83+ }
0 commit comments