Skip to content

Commit 56d5389

Browse files
Migrate to null aware elements - Part 5 (flutter#172418)
## Description Continuing the work from @jamilsaadeh97 to replace verbose null checks with modern [null_aware_elements](https://dart.dev/tools/linter-rules/use_null_aware_elements) syntax. This PR cleans up the remaining files not covered in the previous parts, making the code more concise. ## Related PRs - flutter#172198 - flutter#172306 - flutter#172307 - flutter#172322 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 71b8458 commit 56d5389

33 files changed

Lines changed: 51 additions & 95 deletions

File tree

dev/bots/run_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Future<CommandResult> runCommand(
212212
}
213213
final String allOutput = '${result.flattenedStdout}\n${result.flattenedStderr}';
214214
foundError(<String>[
215-
if (failureMessage != null) failureMessage,
215+
?failureMessage,
216216
'${bold}Command: $green$commandDescription$reset',
217217
if (failureMessage == null)
218218
'$bold${red}Command exited with exit code ${result.exitCode} but expected ${expectNonZeroExit ? (expectedExitCode ?? 'non-zero') : 'zero'} exit code.$reset',

dev/bots/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ Future<void> runDartTest(
458458
if (coverage != null) '--coverage=$coverage',
459459
if (perTestTimeout != null) '--timeout=${perTestTimeout.inMilliseconds}ms',
460460
if (runSkipped) '--run-skipped',
461-
if (tags != null) ...tags.map((String t) => '--tags=$t'),
461+
...?tags?.map((String t) => '--tags=$t'),
462462
if (testPaths != null)
463463
for (final String testPath in testPaths) testPath,
464464
];

dev/devicelab/lib/tasks/hot_mode_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TaskFunction createHotModeTest({
5858
'--no-publish-port',
5959
'--verbose',
6060
'--uninstall-first',
61-
if (additionalOptions != null) ...additionalOptions,
61+
...?additionalOptions,
6262
];
6363
int hotReloadCount = 0;
6464
late Map<String, dynamic> smallReloadData;

dev/integration_tests/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ class Tab2ConversationRow extends StatelessWidget {
687687
mainAxisSize: MainAxisSize.min,
688688
crossAxisAlignment: isSelf ? CrossAxisAlignment.center : CrossAxisAlignment.end,
689689
children: <Widget>[
690-
if (avatar != null) avatar!,
690+
?avatar,
691691
CupertinoUserInterfaceLevel(
692692
data: CupertinoUserInterfaceLevelData.elevated,
693693
child: Tab2ConversationBubble(

dev/integration_tests/flutter_gallery/lib/demo/shrine/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HomePage extends StatelessWidget {
3636
Widget build(BuildContext context) {
3737
return Stack(
3838
children: <Widget>[
39-
if (backdrop != null) backdrop!,
39+
?backdrop,
4040
Align(alignment: Alignment.bottomRight, child: expandingBottomSheet),
4141
],
4242
);

dev/integration_tests/flutter_gallery/lib/gallery/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
266266
static Widget _topHomeLayout(Widget? currentChild, List<Widget> previousChildren) {
267267
return Stack(
268268
alignment: Alignment.topCenter,
269-
children: <Widget>[...previousChildren, if (currentChild != null) currentChild],
269+
children: <Widget>[...previousChildren, ?currentChild],
270270
);
271271
}
272272

dev/packages_autoroller/lib/src/repository.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,7 @@ abstract class Repository {
299299
}
300300
authorArg = '--author="$author"';
301301
}
302-
final List<String> commitCmd = <String>[
303-
'commit',
304-
'--message',
305-
message,
306-
if (authorArg != null) authorArg,
307-
];
302+
final List<String> commitCmd = <String>['commit', '--message', message, ?authorArg];
308303
stdio.printTrace('Executing git $commitCmd...');
309304
final io.ProcessResult commitResult = await git.run(
310305
commitCmd,

dev/tools/android_driver_extensions/lib/skia_gold.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ final class _SkiaGoldComparator extends GoldenFileComparator {
158158
'Golden files in the Flutter framework must end with the file extension '
159159
'.png.',
160160
);
161-
return Uri.parse(<String>[if (namePrefix != null) namePrefix!, golden.toString()].join('.'));
161+
return Uri.parse(<String>[?namePrefix, golden.toString()].join('.'));
162162
}
163163
}

engine/src/flutter/lib/ui/text.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,10 +3526,7 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
35263526
final ByteData? encodedStrutStyle;
35273527
if (strutStyle != null && strutStyle._enabled) {
35283528
final String? fontFamily = strutStyle._fontFamily;
3529-
strutFontFamilies = <String>[
3530-
if (fontFamily != null) fontFamily,
3531-
...?strutStyle._fontFamilyFallback,
3532-
];
3529+
strutFontFamilies = <String>[?fontFamily, ...?strutStyle._fontFamilyFallback];
35333530

35343531
assert(TextLeadingDistribution.values.length <= 2);
35353532
final TextLeadingDistribution leadingDistribution =

examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ class RenderDiagonal extends RenderBox
8787

8888
// Returns children in hit test order.
8989
@override
90-
Iterable<RenderBox> get children => <RenderBox>[
91-
if (_topLeft != null) _topLeft!,
92-
if (_bottomRight != null) _bottomRight!,
93-
];
90+
Iterable<RenderBox> get children => <RenderBox>[?_topLeft, ?_bottomRight];
9491

9592
// LAYOUT
9693

0 commit comments

Comments
 (0)