@@ -69,9 +69,145 @@ void main() {
6969 expect (builds[0 ], coveredBuilds);
7070 expect (seen.last, EdgeInsets .zero);
7171
72+ // Uncovered while the covering route's keyboard is still up: the page
73+ // stays where it was instead of jumping up, then takes live values once
74+ // the keyboard is gone.
7275 navigator.currentState! .pop ();
7376 await tester.pumpAndSettle ();
77+ expect (seen.last, EdgeInsets .zero);
78+ for (final bottom in [200.0 , 100.0 ]) {
79+ setOuter (() => insets = EdgeInsets .only (bottom: bottom));
80+ await tester.pump ();
81+ expect (seen.last, EdgeInsets .zero);
82+ }
83+ setOuter (() => insets = EdgeInsets .zero);
84+ await tester.pump ();
85+ expect (seen.last, EdgeInsets .zero);
86+ setOuter (() => insets = const EdgeInsets .only (bottom: 120 ));
87+ await tester.pump ();
88+ expect (seen.last, const EdgeInsets .only (bottom: 120 ));
89+ });
90+
91+ testWidgets ('an uncovered page never rises above the live keyboard and '
92+ 'follows it once it reaches the held value' , (tester) async {
93+ final builds = [0 ];
94+ final seen = < EdgeInsets > [];
95+ final navigator = GlobalKey <NavigatorState >();
96+ var insets = const EdgeInsets .only (bottom: 300 );
97+ late StateSetter setOuter;
98+ final app = MaterialApp (
99+ navigatorKey: navigator,
100+ home: CoveredRouteKeyboardInsets (child: _Probe (builds, seen)),
101+ );
102+
103+ await tester.pumpWidget (
104+ StatefulBuilder (
105+ builder: (context, setState) {
106+ setOuter = setState;
107+ return MediaQuery (
108+ data: MediaQueryData (
109+ size: const Size (400 , 800 ),
110+ viewInsets: insets,
111+ ),
112+ child: app,
113+ );
114+ },
115+ ),
116+ );
117+
118+ navigator.currentState! .push (
119+ PageRouteBuilder <void >(
120+ opaque: false ,
121+ transitionDuration: Duration .zero,
122+ pageBuilder: (_, _, _) => const SizedBox (),
123+ ),
124+ );
125+ await tester.pumpAndSettle ();
126+ // The page's keyboard closes to 100 behind the covering route, whose own
127+ // field then raises the keyboard back to 300.
128+ for (final bottom in [200.0 , 100.0 , 200.0 , 300.0 ]) {
129+ setOuter (() => insets = EdgeInsets .only (bottom: bottom));
130+ await tester.pump ();
131+ }
132+ expect (seen.last, const EdgeInsets .only (bottom: 100 ));
133+
134+ navigator.currentState! .pop ();
135+ await tester.pumpAndSettle ();
136+ expect (seen.last, const EdgeInsets .only (bottom: 100 ));
137+ for (final bottom in [250.0 , 150.0 , 100.0 ]) {
138+ setOuter (() => insets = EdgeInsets .only (bottom: bottom));
139+ await tester.pump ();
140+ expect (seen.last, const EdgeInsets .only (bottom: 100 ));
141+ }
142+ setOuter (() => insets = const EdgeInsets .only (bottom: 40 ));
143+ await tester.pump ();
144+ expect (seen.last, const EdgeInsets .only (bottom: 40 ));
145+ });
146+
147+ testWidgets ('an uncovered page follows the keyboard its own field raises' , (
148+ tester,
149+ ) async {
150+ final builds = [0 ];
151+ final seen = < EdgeInsets > [];
152+ final navigator = GlobalKey <NavigatorState >();
153+ final focusNode = FocusNode ();
154+ addTearDown (focusNode.dispose);
155+ var insets = EdgeInsets .zero;
156+ late StateSetter setOuter;
157+ final app = MaterialApp (
158+ navigatorKey: navigator,
159+ home: CoveredRouteKeyboardInsets (
160+ child: Scaffold (
161+ resizeToAvoidBottomInset: false ,
162+ body: Column (
163+ children: [
164+ Expanded (child: _Probe (builds, seen)),
165+ TextField (focusNode: focusNode),
166+ ],
167+ ),
168+ ),
169+ ),
170+ );
171+
172+ await tester.pumpWidget (
173+ StatefulBuilder (
174+ builder: (context, setState) {
175+ setOuter = setState;
176+ return MediaQuery (
177+ data: MediaQueryData (
178+ size: const Size (400 , 800 ),
179+ viewInsets: insets,
180+ ),
181+ child: app,
182+ );
183+ },
184+ ),
185+ );
186+
187+ navigator.currentState! .push (
188+ PageRouteBuilder <void >(
189+ opaque: false ,
190+ transitionDuration: Duration .zero,
191+ pageBuilder: (_, _, _) => const SizedBox (),
192+ ),
193+ );
194+ await tester.pumpAndSettle ();
195+ setOuter (() => insets = const EdgeInsets .only (bottom: 300 ));
196+ await tester.pump ();
197+ navigator.currentState! .pop ();
198+ await tester.pumpAndSettle ();
199+ expect (seen.last, EdgeInsets .zero);
200+
201+ // The page's own field takes focus while the keyboard is still up, so the
202+ // page has to follow the keyboard rather than hold below it.
203+ focusNode.requestFocus ();
204+ await tester.pump ();
205+ await tester.pump ();
206+ expect (focusNode.hasPrimaryFocus, isTrue);
74207 expect (seen.last, const EdgeInsets .only (bottom: 300 ));
208+ setOuter (() => insets = const EdgeInsets .only (bottom: 280 ));
209+ await tester.pump ();
210+ expect (seen.last, const EdgeInsets .only (bottom: 280 ));
75211 });
76212
77213 testWidgets ('a covered page follows its own keyboard closing' , (
0 commit comments