-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathwidget_page.dart
121 lines (108 loc) · 2.8 KB
/
widget_page.dart
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
class WidgetPage extends StatefulWidget {
final String title;
WidgetPage(this.title);
@override
State<StatefulWidget> createState() {
return new _WidgetPageState();
}
}
class _WidgetPageState extends State<WidgetPage> {
double testHeight = 50.0;
bool isOpen = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
centerTitle: true,
),
body: new Stack(
children: <Widget>[
new Container(
child: new Center(
child: new Padding(
padding: EdgeInsets.all(10.0),
child: new TestPage(testHeight),
),
),
),
new Container(
child: new TestPage2(),
margin: EdgeInsets.all(10.0),
)
],
),
floatingActionButton: new FloatingActionButton(
onPressed: () {
setState(() {
isOpen = !isOpen;
testHeight = isOpen ? 100.0 : 50.0;
});
},
tooltip: 'Increment',
child: new Icon(Icons.add),
));
}
}
class TestPage extends StatefulWidget {
final double _height;
TestPage(this._height);
@override
State<StatefulWidget> createState() {
return new _TestPageState();
}
}
class _TestPageState extends State<TestPage> {
WidgetUtil widgetUtil = new WidgetUtil();
String mCenterTxt = "";
@override
Widget build(BuildContext context) {
widgetUtil.asyncPrepare(context, true, (Rect rect) {
setState(() {
mCenterTxt = "width: " +
rect.width.toString() +
"\n" +
"height: " +
rect.height.toString();
});
});
return Container(
height: widget._height,
color: Colors.cyan[200],
child: new Center(child: new Text(mCenterTxt)),
);
}
}
class TestPage2 extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _TestPage2State();
}
}
class _TestPage2State extends State<TestPage2> {
String defText = "点击获取Widget在屏幕上的坐标";
String contentText = "";
@override
Widget build(BuildContext context) {
if (contentText == "") {
contentText = defText;
}
return new Container(
height: 100.0,
color: Colors.cyan[100],
child: new InkWell(
onTap: () {
setState(() {
Offset offset = WidgetUtil.getWidgetLocalToGlobal(context);
contentText = defText + "\n" + "Offset: " + offset.toString();
});
},
child: new Center(
child: new Text(contentText),
),
),
);
}
}