@@ -9,15 +9,34 @@ class ShowDialogDemo extends StatefulWidget {
99class _ShowDialogDemoState extends State <ShowDialogDemo > {
1010 @override
1111 final GlobalKey _scaffoldKey = GlobalKey ();
12+ final GlobalKey _containerKey = GlobalKey ();
1213 double _containerHeight = 0 ;
1314
15+ @override
16+ void initState () {
17+ super .initState ();
18+
19+ WidgetsBinding .instance.addPostFrameCallback ((_) {
20+ final RenderBox renderBox = _scaffoldKey.currentContext? .findRenderObject () as RenderBox ;
21+ double newHeight = renderBox.size.height;
22+ if (newHeight != _containerHeight) {
23+ _containerHeight = newHeight;
24+ print ("_containerHeight Height: ${_containerHeight }" );
25+ }
26+ });
27+ }
28+
1429 double _getContainerHeight () {
15- final RenderBox renderBox = _scaffoldKey.currentContext? .findRenderObject () as RenderBox ;
30+ RenderBox renderBox = _scaffoldKey.currentContext? .findRenderObject () as RenderBox ;
1631 double newHeight = renderBox.size.height;
17- if (newHeight != _containerHeight) {
18- _containerHeight = newHeight;
19- print ("_containerHeight Height: ${_containerHeight }" );
20- }
32+ // if (newHeight != _containerHeight) {
33+ // _containerHeight = newHeight;
34+ print ("_scaffoldHeight Height: ${_containerHeight }" );
35+ // }
36+
37+ renderBox = _containerKey.currentContext? .findRenderObject () as RenderBox ;
38+ newHeight = renderBox.size.height;
39+ print ("_containerHeight Height: ${newHeight }" );
2140
2241 return _containerHeight;
2342 }
@@ -26,15 +45,26 @@ class _ShowDialogDemoState extends State<ShowDialogDemo> {
2645 print ('flutter build' );
2746
2847 return Scaffold (
48+ key: _scaffoldKey,
2949 backgroundColor: Colors .red,
3050 // appBar: AppBar(
3151 // title: Text('TextField Example'),
3252 // ),
3353 body: Column (
54+ mainAxisAlignment: MainAxisAlignment .end,
3455 children: [
3556 Container (
36- key: _scaffoldKey,
37- child: TextField (
57+ color: Colors .blue,
58+ key: _containerKey,
59+ child: Column (
60+ mainAxisAlignment: MainAxisAlignment .end,
61+ children: [
62+ Text ('Widget 1' ),
63+ SizedBox (height: 10 ),
64+ Text ('Widget 2' ),
65+ SizedBox (height: 10 ),
66+ Text ('Widget 3' ),
67+ TextField (
3868 // key: _scaffoldKey,
3969 // expands: true,
4070 maxLines: 150 ,
@@ -59,6 +89,8 @@ class _ShowDialogDemoState extends State<ShowDialogDemo> {
5989 ),
6090 ),
6191 ),
92+ ],
93+ ),
6294 ),
6395 ],
6496 ),
0 commit comments