22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- // @dart = 2.8
6-
75import 'dart:async' ;
86
97import 'package:flutter/material.dart' ;
@@ -14,15 +12,15 @@ import '../rendering/mock_canvas.dart';
1412
1513Widget buildInputDecorator ({
1614 InputDecoration decoration = const InputDecoration (),
17- InputDecorationTheme inputDecorationTheme,
15+ InputDecorationTheme ? inputDecorationTheme,
1816 TextDirection textDirection = TextDirection .ltr,
1917 bool expands = false ,
2018 bool isEmpty = false ,
2119 bool isFocused = false ,
2220 bool isHovering = false ,
23- TextStyle baseStyle,
24- TextAlignVertical textAlignVertical,
25- VisualDensity visualDensity,
21+ TextStyle ? baseStyle,
22+ TextAlignVertical ? textAlignVertical,
23+ VisualDensity ? visualDensity,
2624 bool fixTextFieldOutlineLabel = false ,
2725 Widget child = const Text (
2826 'text' ,
@@ -34,7 +32,7 @@ Widget buildInputDecorator({
3432 child: Builder (
3533 builder: (BuildContext context) {
3634 return Theme (
37- data: Theme .of (context).copyWith (
35+ data: Theme .of (context)! .copyWith (
3836 inputDecorationTheme: inputDecorationTheme,
3937 visualDensity: visualDensity,
4038 fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
@@ -70,7 +68,7 @@ Finder findBorderPainter() {
7068}
7169
7270double getBorderBottom (WidgetTester tester) {
73- final RenderBox box = InputDecorator .containerOf (tester.element (findBorderPainter ()));
71+ final RenderBox box = InputDecorator .containerOf (tester.element (findBorderPainter ()))! ;
7472 return box.size.height;
7573}
7674
@@ -85,7 +83,7 @@ Rect getLabelRect(WidgetTester tester) {
8583 return tester.getRect (findLabel ());
8684}
8785
88- InputBorder getBorder (WidgetTester tester) {
86+ InputBorder ? getBorder (WidgetTester tester) {
8987 if (! tester.any (findBorderPainter ()))
9088 return null ;
9189 final CustomPaint customPaint = tester.widget (findBorderPainter ());
@@ -96,21 +94,21 @@ InputBorder getBorder(WidgetTester tester) {
9694 return border;
9795}
9896
99- BorderSide getBorderSide (WidgetTester tester) {
100- return getBorder (tester)? .borderSide;
97+ BorderSide ? getBorderSide (WidgetTester tester) {
98+ return getBorder (tester)! .borderSide;
10199}
102100
103- BorderRadius getBorderRadius (WidgetTester tester) {
104- final InputBorder border = getBorder (tester);
101+ BorderRadius ? getBorderRadius (WidgetTester tester) {
102+ final InputBorder border = getBorder (tester)! ;
105103 if (border is UnderlineInputBorder ) {
106104 return border.borderRadius;
107105 }
108106 return null ;
109107}
110108
111- double getBorderWeight (WidgetTester tester) => getBorderSide (tester)? .width;
109+ double getBorderWeight (WidgetTester tester) => getBorderSide (tester)! .width;
112110
113- Color getBorderColor (WidgetTester tester) => getBorderSide (tester)? .color;
111+ Color getBorderColor (WidgetTester tester) => getBorderSide (tester)! .color;
114112
115113Color getContainerColor (WidgetTester tester) {
116114 final CustomPaint customPaint = tester.widget (findBorderPainter ());
@@ -925,10 +923,10 @@ void main() {
925923
926924 testWidgets ('InputDecorator counter text, widget, and null' , (WidgetTester tester) async {
927925 Widget buildFrame ({
928- InputCounterWidgetBuilder buildCounter,
929- String counterText,
930- Widget counter,
931- int maxLength,
926+ InputCounterWidgetBuilder ? buildCounter,
927+ String ? counterText,
928+ Widget ? counter,
929+ int ? maxLength,
932930 }) {
933931 return MaterialApp (
934932 home: Scaffold (
@@ -953,7 +951,7 @@ void main() {
953951
954952 // When counter, counterText, and buildCounter are null, defaults to showing
955953 // the built-in counter.
956- int maxLength = 10 ;
954+ int ? maxLength = 10 ;
957955 await tester.pumpWidget (buildFrame (maxLength: maxLength));
958956 Finder counterFinder = find.byType (Text );
959957 expect (counterFinder, findsOneWidget);
@@ -966,13 +964,18 @@ void main() {
966964 final Key buildCounterKey = UniqueKey ();
967965 const String counterText = 'I show instead of count' ;
968966 final Widget counter = Text ('hello' , key: counterKey);
969- final InputCounterWidgetBuilder buildCounter =
970- (BuildContext context, { int currentLength, int maxLength, bool isFocused }) {
971- return Text (
972- '${currentLength .toString ()} of ${maxLength .toString ()}' ,
973- key: buildCounterKey,
974- );
975- };
967+ final InputCounterWidgetBuilder buildCounter = (
968+ BuildContext context, {
969+ required int currentLength,
970+ required int ? maxLength,
971+ required bool isFocused,
972+ }) {
973+ return Text (
974+ '${currentLength .toString ()} of ${maxLength .toString ()}' ,
975+ key: buildCounterKey,
976+ );
977+ };
978+
976979 await tester.pumpWidget (buildFrame (
977980 counterText: counterText,
978981 counter: counter,
@@ -3021,10 +3024,10 @@ void main() {
30213024 expect (tester.getTopRight (find.text ('counter' )), const Offset (800.0 , 64.0 ));
30223025
30233026 // Verify that the styles were passed along
3024- expect (tester.widget <Text >(find.text ('prefix' )).style.color, prefixStyle.color);
3025- expect (tester.widget <Text >(find.text ('suffix' )).style.color, suffixStyle.color);
3026- expect (tester.widget <Text >(find.text ('helper' )).style.color, helperStyle.color);
3027- expect (tester.widget <Text >(find.text ('counter' )).style.color, counterStyle.color);
3027+ expect (tester.widget <Text >(find.text ('prefix' )).style! .color, prefixStyle.color);
3028+ expect (tester.widget <Text >(find.text ('suffix' )).style! .color, suffixStyle.color);
3029+ expect (tester.widget <Text >(find.text ('helper' )).style! .color, helperStyle.color);
3030+ expect (tester.widget <Text >(find.text ('counter' )).style! .color, counterStyle.color);
30283031
30293032 TextStyle getLabelStyle () {
30303033 return tester.firstWidget <AnimatedDefaultTextStyle >(
@@ -3073,7 +3076,7 @@ void main() {
30733076
30743077 final RenderObject renderer = tester.renderObject (find.byType (InputDecorator ));
30753078 final Iterable <String > nodeNames = renderer.debugDescribeChildren ()
3076- .map ((DiagnosticsNode node) => node.name);
3079+ .map ((DiagnosticsNode node) => node.name! );
30773080 expect (nodeNames, unorderedEquals (< String > [
30783081 'container' ,
30793082 'counter' ,
@@ -3089,7 +3092,7 @@ void main() {
30893092 ]));
30903093
30913094 final Set <Object > nodeValues = Set <Object >.from (
3092- renderer.debugDescribeChildren ().map <Object >((DiagnosticsNode node) => node.value)
3095+ renderer.debugDescribeChildren ().map <Object >((DiagnosticsNode node) => node.value! )
30933096 );
30943097 expect (nodeValues.length, 11 );
30953098 });
@@ -3347,7 +3350,11 @@ void main() {
33473350 const Color disabledColor = Color (0x05000000 );
33483351 const Color enabledBorderColor = Color (0x61000000 );
33493352
3350- Future <void > pumpDecorator ({bool hovering, bool enabled = true , bool filled = true }) async {
3353+ Future <void > pumpDecorator ({
3354+ required bool hovering,
3355+ bool enabled = true ,
3356+ bool filled = true ,
3357+ }) async {
33513358 return await tester.pumpWidget (
33523359 buildInputDecorator (
33533360 isHovering: hovering,
@@ -3422,7 +3429,11 @@ void main() {
34223429 const Color disabledColor = Color (0x05000000 );
34233430 const Color enabledBorderColor = Color (0x61000000 );
34243431
3425- Future <void > pumpDecorator ({bool focused, bool enabled = true , bool filled = true }) async {
3432+ Future <void > pumpDecorator ({
3433+ required bool focused,
3434+ bool enabled = true ,
3435+ bool filled = true ,
3436+ }) async {
34263437 return await tester.pumpWidget (
34273438 buildInputDecorator (
34283439 isFocused: focused,
@@ -3467,7 +3478,13 @@ void main() {
34673478 });
34683479
34693480 testWidgets ('InputDecorator withdraws label when not empty or focused' , (WidgetTester tester) async {
3470- Future <void > pumpDecorator ({bool focused, bool enabled = true , bool filled = false , bool empty = true , bool directional = false }) async {
3481+ Future <void > pumpDecorator ({
3482+ required bool focused,
3483+ bool enabled = true ,
3484+ bool filled = false ,
3485+ bool empty = true ,
3486+ bool directional = false ,
3487+ }) async {
34713488 return await tester.pumpWidget (
34723489 buildInputDecorator (
34733490 isEmpty: empty,
@@ -4140,8 +4157,8 @@ void main() {
41404157 testWidgets ('textAlignVertical can be updated' , (WidgetTester tester) async {
41414158 // Regression test for https://github.com/flutter/flutter/issues/56933
41424159 const String hintText = 'hint' ;
4143- TextAlignVertical alignment = TextAlignVertical .top;
4144- StateSetter setState;
4160+ TextAlignVertical ? alignment = TextAlignVertical .top;
4161+ late StateSetter setState;
41454162 await tester.pumpWidget (
41464163 MaterialApp (
41474164 home: StatefulBuilder (
@@ -4187,7 +4204,7 @@ void main() {
41874204 child: Builder (
41884205 builder: (BuildContext context) {
41894206 return Theme (
4190- data: Theme .of (context),
4207+ data: Theme .of (context)! ,
41914208 child: Align (
41924209 alignment: Alignment .topLeft,
41934210 child: TextField (
@@ -4247,7 +4264,7 @@ void main() {
42474264 child: Builder (
42484265 builder: (BuildContext context) {
42494266 return Theme (
4250- data: Theme .of (context).copyWith (visualDensity: visualDensity),
4267+ data: Theme .of (context)! .copyWith (visualDensity: visualDensity),
42514268 child: Center (
42524269 child: Row (
42534270 children: < Widget > [
@@ -4320,7 +4337,7 @@ void main() {
43204337 child: Builder (
43214338 builder: (BuildContext context) {
43224339 return Theme (
4323- data: Theme .of (context).copyWith (visualDensity: VisualDensity .compact),
4340+ data: Theme .of (context)! .copyWith (visualDensity: VisualDensity .compact),
43244341 child: Center (
43254342 child: Row (
43264343 children: < Widget > [
0 commit comments