Flutter Widget之Flow

Widget:https://flutter.io/docs/development/ui/widgets
Flow:https://docs.flutter.io/flutter/widgets/Flow-class.html

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
import 'package:flutter/material.dart';

class FlowDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _FlowDemoPagePageState();
}

class _FlowDemoPagePageState extends State<FlowDemoPage> {
final width = 80.0;
final height = 60.0;

@override
void initState() {
super.initState();
}

Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('Flow Demo'),
),
body: Flow(
delegate: TestFlowDelegate(margin: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 8.0)),
children: <Widget>[
new Container(width: width, height: height, color: Colors.yellow,),
new Container(width: width, height: height, color: Colors.green,),
new Container(width: width, height: height, color: Colors.red,),
new Container(width: width, height: height, color: Colors.purple,),
new Container(width: width, height: height, color: Colors.blue,),
new Container(width: width, height: height, color: Colors.teal,),
],
),
);
}
}

class TestFlowDelegate extends FlowDelegate {
EdgeInsets margin = EdgeInsets.zero;

TestFlowDelegate({this.margin});
@override
void paintChildren(FlowPaintingContext context) {
var x = margin.left;
var y = margin.top;
for (int i = 0; i < context.childCount; i++) {
var w = context.getChildSize(i).width + x + margin.right;
if (w < context.size.width) {
context.paintChild(i,
transform: new Matrix4.translationValues(x, y, 0.0));
x = w + margin.left;
} else {
x = margin.left;
y += context.getChildSize(i).height + margin.top + margin.bottom;
context.paintChild(i,
transform: new Matrix4.translationValues(x, y, 0.0));
x += context.getChildSize(i).width + margin.left + margin.right;
}
}
}

@override
bool shouldRepaint(FlowDelegate oldDelegate) {
return oldDelegate != this;
}
}

Flutter Widget Flow

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :