forked from ibhavikmakwana/FlutterPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowWidgetExample.dart
More file actions
91 lines (77 loc) · 2.3 KB
/
FlowWidgetExample.dart
File metadata and controls
91 lines (77 loc) · 2.3 KB
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
82
83
84
85
86
87
88
89
90
91
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class FlowWidgetExample extends StatefulWidget {
final String title;
FlowWidgetExample(this.title);
@override
FlowWidgetExampleState createState() {
return FlowWidgetExampleState();
}
}
class FlowWidgetExampleState extends State<FlowWidgetExample>
with TickerProviderStateMixin {
AnimationController start;
@override
void initState() {
super.initState();
start = AnimationController.unbounded(vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Flow(
delegate: ExampleFlowDelegate(opacity: 0.2, startOffset: start),
children: [
buildBox(0, Colors.red),
buildBox(1, Colors.deepPurple),
buildBox(2, Colors.brown),
buildBox(3, Colors.orange),
buildBox(4, Colors.blueGrey),
buildBox(5, Colors.cyan),
buildBox(6, Colors.blue),
],
),
),
);
}
Widget buildBox(int i, MaterialColor red) {
return GestureDetector(
onTap: () {
print("TAPPED $i");
},
child: Container(
width: 100.0,
height: 50.0,
color: red,
child:
Center(child: Text('$i', textDirection: TextDirection.ltr))));
}
}
class ExampleFlowDelegate extends FlowDelegate {
ExampleFlowDelegate({this.opacity, this.startOffset})
: super(repaint: startOffset);
double opacity;
Animation<double> startOffset;
@override
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) {
return constraints.loosen();
}
@override
void paintChildren(FlowPaintingContext context) {
double dy = startOffset.value;
for (int i = 0; i < context.childCount; ++i) {
context.paintChild(i,
opacity: opacity, transform: Matrix4.translationValues(0.0, dy, 0.0));
dy += 0.65 * context.getChildSize(i).height;
}
}
@override
bool shouldRepaint(ExampleFlowDelegate oldDelegate) =>
startOffset == oldDelegate.startOffset;
}