Skip to content

Commit 2aa348b

Browse files
authored
Use curly_braces_in_flow_control_structures for widgets (#104609)
* Use `curly_braces_in_flow_control_structures` for `widgets` * fix comments * fix comments
1 parent f22c203 commit 2aa348b

File tree

126 files changed

+1998
-1018
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1998
-1018
lines changed

packages/flutter/lib/src/widgets/actions.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,8 +1503,9 @@ class PrioritizedAction extends Action<PrioritizedIntents> {
15031503
@override
15041504
bool isEnabled(PrioritizedIntents intent) {
15051505
final FocusNode? focus = primaryFocus;
1506-
if (focus == null || focus.context == null)
1506+
if (focus == null || focus.context == null) {
15071507
return false;
1508+
}
15081509
for (final Intent candidateIntent in intent.orderedIntents) {
15091510
final Action<Intent>? candidateAction = Actions.maybeFind<Intent>(
15101511
focus.context!,

packages/flutter/lib/src/widgets/animated_cross_fade.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
269269
reverseDuration: widget.reverseDuration,
270270
vsync: this,
271271
);
272-
if (widget.crossFadeState == CrossFadeState.showSecond)
272+
if (widget.crossFadeState == CrossFadeState.showSecond) {
273273
_controller.value = 1.0;
274+
}
274275
_firstAnimation = _initAnimation(widget.firstCurve, true);
275276
_secondAnimation = _initAnimation(widget.secondCurve, false);
276277
_controller.addStatusListener((AnimationStatus status) {
@@ -283,8 +284,9 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
283284

284285
Animation<double> _initAnimation(Curve curve, bool inverted) {
285286
Animation<double> result = _controller.drive(CurveTween(curve: curve));
286-
if (inverted)
287+
if (inverted) {
287288
result = result.drive(Tween<double>(begin: 1.0, end: 0.0));
289+
}
288290
return result;
289291
}
290292

@@ -297,14 +299,18 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
297299
@override
298300
void didUpdateWidget(AnimatedCrossFade oldWidget) {
299301
super.didUpdateWidget(oldWidget);
300-
if (widget.duration != oldWidget.duration)
302+
if (widget.duration != oldWidget.duration) {
301303
_controller.duration = widget.duration;
302-
if (widget.reverseDuration != oldWidget.reverseDuration)
304+
}
305+
if (widget.reverseDuration != oldWidget.reverseDuration) {
303306
_controller.reverseDuration = widget.reverseDuration;
304-
if (widget.firstCurve != oldWidget.firstCurve)
307+
}
308+
if (widget.firstCurve != oldWidget.firstCurve) {
305309
_firstAnimation = _initAnimation(widget.firstCurve, true);
306-
if (widget.secondCurve != oldWidget.secondCurve)
310+
}
311+
if (widget.secondCurve != oldWidget.secondCurve) {
307312
_secondAnimation = _initAnimation(widget.secondCurve, false);
313+
}
308314
if (widget.crossFadeState != oldWidget.crossFadeState) {
309315
switch (widget.crossFadeState) {
310316
case CrossFadeState.showFirst:

packages/flutter/lib/src/widgets/animated_list.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,11 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
488488
int _indexToItemIndex(int index) {
489489
int itemIndex = index;
490490
for (final _ActiveItem item in _outgoingItems) {
491-
if (item.itemIndex <= itemIndex)
491+
if (item.itemIndex <= itemIndex) {
492492
itemIndex += 1;
493-
else
493+
} else {
494494
break;
495+
}
495496
}
496497
return itemIndex;
497498
}
@@ -500,10 +501,11 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
500501
int index = itemIndex;
501502
for (final _ActiveItem item in _outgoingItems) {
502503
assert(item.itemIndex != itemIndex);
503-
if (item.itemIndex < itemIndex)
504+
if (item.itemIndex < itemIndex) {
504505
index -= 1;
505-
else
506+
} else {
506507
break;
508+
}
507509
}
508510
return index;
509511
}
@@ -532,12 +534,14 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
532534
// Increment the incoming and outgoing item indices to account
533535
// for the insertion.
534536
for (final _ActiveItem item in _incomingItems) {
535-
if (item.itemIndex >= itemIndex)
537+
if (item.itemIndex >= itemIndex) {
536538
item.itemIndex += 1;
539+
}
537540
}
538541
for (final _ActiveItem item in _outgoingItems) {
539-
if (item.itemIndex >= itemIndex)
542+
if (item.itemIndex >= itemIndex) {
540543
item.itemIndex += 1;
544+
}
541545
}
542546

543547
final AnimationController controller = AnimationController(
@@ -596,12 +600,14 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
596600
// Decrement the incoming and outgoing item indices to account
597601
// for the removal.
598602
for (final _ActiveItem item in _incomingItems) {
599-
if (item.itemIndex > outgoingItem.itemIndex)
603+
if (item.itemIndex > outgoingItem.itemIndex) {
600604
item.itemIndex -= 1;
605+
}
601606
}
602607
for (final _ActiveItem item in _outgoingItems) {
603-
if (item.itemIndex > outgoingItem.itemIndex)
608+
if (item.itemIndex > outgoingItem.itemIndex) {
604609
item.itemIndex -= 1;
610+
}
605611
}
606612

607613
setState(() => _itemsCount -= 1);

packages/flutter/lib/src/widgets/animated_switcher.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
272272
// transitions.
273273
if (widget.transitionBuilder != oldWidget.transitionBuilder) {
274274
_outgoingEntries.forEach(_updateTransitionForEntry);
275-
if (_currentEntry != null)
275+
if (_currentEntry != null) {
276276
_updateTransitionForEntry(_currentEntry!);
277+
}
277278
_markChildWidgetCacheAsDirty();
278279
}
279280

@@ -307,8 +308,9 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
307308
_markChildWidgetCacheAsDirty();
308309
_currentEntry = null;
309310
}
310-
if (widget.child == null)
311+
if (widget.child == null) {
311312
return;
313+
}
312314
final AnimationController controller = AnimationController(
313315
duration: widget.duration,
314316
reverseDuration: widget.reverseDuration,
@@ -380,10 +382,12 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
380382

381383
@override
382384
void dispose() {
383-
if (_currentEntry != null)
385+
if (_currentEntry != null) {
384386
_currentEntry!.controller.dispose();
385-
for (final _ChildEntry entry in _outgoingEntries)
387+
}
388+
for (final _ChildEntry entry in _outgoingEntries) {
386389
entry.controller.dispose();
390+
}
387391
super.dispose();
388392
}
389393

packages/flutter/lib/src/widgets/app.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,8 +1409,9 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
14091409
assert(route != null, 'The pageRouteBuilder for WidgetsApp must return a valid non-null Route.');
14101410
return route;
14111411
}
1412-
if (widget.onGenerateRoute != null)
1412+
if (widget.onGenerateRoute != null) {
14131413
return widget.onGenerateRoute!(settings);
1414+
}
14141415
return null;
14151416
}
14161417

@@ -1454,12 +1455,14 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
14541455
assert(mounted);
14551456
// The back button dispatcher should handle the pop route if we use a
14561457
// router.
1457-
if (_usesRouterWithDelegates)
1458+
if (_usesRouterWithDelegates) {
14581459
return false;
1460+
}
14591461

14601462
final NavigatorState? navigator = _navigator?.currentState;
1461-
if (navigator == null)
1463+
if (navigator == null) {
14621464
return false;
1465+
}
14631466
return navigator.maybePop();
14641467
}
14651468

@@ -1468,12 +1471,14 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
14681471
assert(mounted);
14691472
// The route name provider should handle the push route if we uses a
14701473
// router.
1471-
if (_usesRouterWithDelegates)
1474+
if (_usesRouterWithDelegates) {
14721475
return false;
1476+
}
14731477

14741478
final NavigatorState? navigator = _navigator?.currentState;
1475-
if (navigator == null)
1479+
if (navigator == null) {
14761480
return false;
1481+
}
14771482
navigator.pushNamed(route);
14781483
return true;
14791484
}
@@ -1487,17 +1492,19 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
14871492
// Attempt to use localeListResolutionCallback.
14881493
if (widget.localeListResolutionCallback != null) {
14891494
final Locale? locale = widget.localeListResolutionCallback!(preferredLocales, widget.supportedLocales);
1490-
if (locale != null)
1495+
if (locale != null) {
14911496
return locale;
1497+
}
14921498
}
14931499
// localeListResolutionCallback failed, falling back to localeResolutionCallback.
14941500
if (widget.localeResolutionCallback != null) {
14951501
final Locale? locale = widget.localeResolutionCallback!(
14961502
preferredLocales != null && preferredLocales.isNotEmpty ? preferredLocales.first : null,
14971503
widget.supportedLocales,
14981504
);
1499-
if (locale != null)
1505+
if (locale != null) {
15001506
return locale;
1507+
}
15011508
}
15021509
// Both callbacks failed, falling back to default algorithm.
15031510
return basicLocaleListResolution(preferredLocales, supportedLocales);
@@ -1533,13 +1540,16 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
15331540
final Set<Type> unsupportedTypes =
15341541
_localizationsDelegates.map<Type>((LocalizationsDelegate<dynamic> delegate) => delegate.type).toSet();
15351542
for (final LocalizationsDelegate<dynamic> delegate in _localizationsDelegates) {
1536-
if (!unsupportedTypes.contains(delegate.type))
1543+
if (!unsupportedTypes.contains(delegate.type)) {
15371544
continue;
1538-
if (delegate.isSupported(appLocale))
1545+
}
1546+
if (delegate.isSupported(appLocale)) {
15391547
unsupportedTypes.remove(delegate.type);
1548+
}
15401549
}
1541-
if (unsupportedTypes.isEmpty)
1550+
if (unsupportedTypes.isEmpty) {
15421551
return true;
1552+
}
15431553

15441554
FlutterError.reportError(FlutterErrorDetails(
15451555
exception: "Warning: This application's locale, $appLocale, is not supported by all of its localization delegates.",

packages/flutter/lib/src/widgets/async.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ class AsyncSnapshot<T> {
246246
/// Throws [error], if [hasError]. Throws [StateError], if neither [hasData]
247247
/// nor [hasError].
248248
T get requireData {
249-
if (hasData)
249+
if (hasData) {
250250
return data!;
251-
if (hasError)
251+
}
252+
if (hasError) {
252253
Error.throwWithStackTrace(error!, stackTrace!);
254+
}
253255
throw StateError('Snapshot has neither data nor error');
254256
}
255257

@@ -294,8 +296,9 @@ class AsyncSnapshot<T> {
294296

295297
@override
296298
bool operator ==(Object other) {
297-
if (identical(this, other))
299+
if (identical(this, other)) {
298300
return true;
301+
}
299302
return other is AsyncSnapshot<T>
300303
&& other.connectionState == connectionState
301304
&& other.data == data

packages/flutter/lib/src/widgets/autofill.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ class AutofillGroupState extends State<AutofillGroup> with AutofillScopeMixin {
186186
void dispose() {
187187
super.dispose();
188188

189-
if (!_isTopmostAutofillGroup || widget.onDisposeAction == null)
189+
if (!_isTopmostAutofillGroup || widget.onDisposeAction == null) {
190190
return;
191+
}
191192
switch (widget.onDisposeAction) {
192193
case AutofillContextAction.cancel:
193194
TextInput.finishAutofillContext(shouldSave: false);

packages/flutter/lib/src/widgets/automatic_keep_alive.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class _AutomaticKeepAliveState extends State<AutomaticKeepAlive> {
6969
@override
7070
void dispose() {
7171
if (_handles != null) {
72-
for (final Listenable handle in _handles!.keys)
72+
for (final Listenable handle in _handles!.keys) {
7373
handle.removeListener(_handles![handle]!);
74+
}
7475
}
7576
super.dispose();
7677
}
@@ -368,33 +369,38 @@ mixin AutomaticKeepAliveClientMixin<T extends StatefulWidget> on State<T> {
368369
@protected
369370
void updateKeepAlive() {
370371
if (wantKeepAlive) {
371-
if (_keepAliveHandle == null)
372+
if (_keepAliveHandle == null) {
372373
_ensureKeepAlive();
374+
}
373375
} else {
374-
if (_keepAliveHandle != null)
376+
if (_keepAliveHandle != null) {
375377
_releaseKeepAlive();
378+
}
376379
}
377380
}
378381

379382
@override
380383
void initState() {
381384
super.initState();
382-
if (wantKeepAlive)
385+
if (wantKeepAlive) {
383386
_ensureKeepAlive();
387+
}
384388
}
385389

386390
@override
387391
void deactivate() {
388-
if (_keepAliveHandle != null)
392+
if (_keepAliveHandle != null) {
389393
_releaseKeepAlive();
394+
}
390395
super.deactivate();
391396
}
392397

393398
@mustCallSuper
394399
@override
395400
Widget build(BuildContext context) {
396-
if (wantKeepAlive && _keepAliveHandle == null)
401+
if (wantKeepAlive && _keepAliveHandle == null) {
397402
_ensureKeepAlive();
403+
}
398404
return const _NullWidget();
399405
}
400406
}

packages/flutter/lib/src/widgets/banner.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ class BannerPainter extends CustomPainter {
135135

136136
@override
137137
void paint(Canvas canvas, Size size) {
138-
if (!_prepared)
138+
if (!_prepared) {
139139
_prepare();
140+
}
140141
canvas
141142
..translate(_translationX(size.width), _translationY(size.height))
142143
..rotate(_rotation)

0 commit comments

Comments
 (0)