Skip to content

Commit

Permalink
Use curly_braces_in_flow_control_structures for widgets (flutter#…
Browse files Browse the repository at this point in the history
…104609)

* Use `curly_braces_in_flow_control_structures` for `widgets`

* fix comments

* fix comments
  • Loading branch information
guidezpl authored and camsim99 committed Aug 10, 2022
1 parent 62ba8a6 commit bf4bb74
Show file tree
Hide file tree
Showing 126 changed files with 1,998 additions and 1,018 deletions.
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/widgets/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,9 @@ class PrioritizedAction extends Action<PrioritizedIntents> {
@override
bool isEnabled(PrioritizedIntents intent) {
final FocusNode? focus = primaryFocus;
if (focus == null || focus.context == null)
if (focus == null || focus.context == null) {
return false;
}
for (final Intent candidateIntent in intent.orderedIntents) {
final Action<Intent>? candidateAction = Actions.maybeFind<Intent>(
focus.context!,
Expand Down
18 changes: 12 additions & 6 deletions packages/flutter/lib/src/widgets/animated_cross_fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
reverseDuration: widget.reverseDuration,
vsync: this,
);
if (widget.crossFadeState == CrossFadeState.showSecond)
if (widget.crossFadeState == CrossFadeState.showSecond) {
_controller.value = 1.0;
}
_firstAnimation = _initAnimation(widget.firstCurve, true);
_secondAnimation = _initAnimation(widget.secondCurve, false);
_controller.addStatusListener((AnimationStatus status) {
Expand All @@ -283,8 +284,9 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid

Animation<double> _initAnimation(Curve curve, bool inverted) {
Animation<double> result = _controller.drive(CurveTween(curve: curve));
if (inverted)
if (inverted) {
result = result.drive(Tween<double>(begin: 1.0, end: 0.0));
}
return result;
}

Expand All @@ -297,14 +299,18 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
@override
void didUpdateWidget(AnimatedCrossFade oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.duration != oldWidget.duration)
if (widget.duration != oldWidget.duration) {
_controller.duration = widget.duration;
if (widget.reverseDuration != oldWidget.reverseDuration)
}
if (widget.reverseDuration != oldWidget.reverseDuration) {
_controller.reverseDuration = widget.reverseDuration;
if (widget.firstCurve != oldWidget.firstCurve)
}
if (widget.firstCurve != oldWidget.firstCurve) {
_firstAnimation = _initAnimation(widget.firstCurve, true);
if (widget.secondCurve != oldWidget.secondCurve)
}
if (widget.secondCurve != oldWidget.secondCurve) {
_secondAnimation = _initAnimation(widget.secondCurve, false);
}
if (widget.crossFadeState != oldWidget.crossFadeState) {
switch (widget.crossFadeState) {
case CrossFadeState.showFirst:
Expand Down
22 changes: 14 additions & 8 deletions packages/flutter/lib/src/widgets/animated_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,11 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
int _indexToItemIndex(int index) {
int itemIndex = index;
for (final _ActiveItem item in _outgoingItems) {
if (item.itemIndex <= itemIndex)
if (item.itemIndex <= itemIndex) {
itemIndex += 1;
else
} else {
break;
}
}
return itemIndex;
}
Expand All @@ -500,10 +501,11 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
int index = itemIndex;
for (final _ActiveItem item in _outgoingItems) {
assert(item.itemIndex != itemIndex);
if (item.itemIndex < itemIndex)
if (item.itemIndex < itemIndex) {
index -= 1;
else
} else {
break;
}
}
return index;
}
Expand Down Expand Up @@ -532,12 +534,14 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
// Increment the incoming and outgoing item indices to account
// for the insertion.
for (final _ActiveItem item in _incomingItems) {
if (item.itemIndex >= itemIndex)
if (item.itemIndex >= itemIndex) {
item.itemIndex += 1;
}
}
for (final _ActiveItem item in _outgoingItems) {
if (item.itemIndex >= itemIndex)
if (item.itemIndex >= itemIndex) {
item.itemIndex += 1;
}
}

final AnimationController controller = AnimationController(
Expand Down Expand Up @@ -596,12 +600,14 @@ class SliverAnimatedListState extends State<SliverAnimatedList> with TickerProvi
// Decrement the incoming and outgoing item indices to account
// for the removal.
for (final _ActiveItem item in _incomingItems) {
if (item.itemIndex > outgoingItem.itemIndex)
if (item.itemIndex > outgoingItem.itemIndex) {
item.itemIndex -= 1;
}
}
for (final _ActiveItem item in _outgoingItems) {
if (item.itemIndex > outgoingItem.itemIndex)
if (item.itemIndex > outgoingItem.itemIndex) {
item.itemIndex -= 1;
}
}

setState(() => _itemsCount -= 1);
Expand Down
12 changes: 8 additions & 4 deletions packages/flutter/lib/src/widgets/animated_switcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
// transitions.
if (widget.transitionBuilder != oldWidget.transitionBuilder) {
_outgoingEntries.forEach(_updateTransitionForEntry);
if (_currentEntry != null)
if (_currentEntry != null) {
_updateTransitionForEntry(_currentEntry!);
}
_markChildWidgetCacheAsDirty();
}

Expand Down Expand Up @@ -307,8 +308,9 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
_markChildWidgetCacheAsDirty();
_currentEntry = null;
}
if (widget.child == null)
if (widget.child == null) {
return;
}
final AnimationController controller = AnimationController(
duration: widget.duration,
reverseDuration: widget.reverseDuration,
Expand Down Expand Up @@ -380,10 +382,12 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider

@override
void dispose() {
if (_currentEntry != null)
if (_currentEntry != null) {
_currentEntry!.controller.dispose();
for (final _ChildEntry entry in _outgoingEntries)
}
for (final _ChildEntry entry in _outgoingEntries) {
entry.controller.dispose();
}
super.dispose();
}

Expand Down
30 changes: 20 additions & 10 deletions packages/flutter/lib/src/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,9 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
assert(route != null, 'The pageRouteBuilder for WidgetsApp must return a valid non-null Route.');
return route;
}
if (widget.onGenerateRoute != null)
if (widget.onGenerateRoute != null) {
return widget.onGenerateRoute!(settings);
}
return null;
}

Expand Down Expand Up @@ -1454,12 +1455,14 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
assert(mounted);
// The back button dispatcher should handle the pop route if we use a
// router.
if (_usesRouterWithDelegates)
if (_usesRouterWithDelegates) {
return false;
}

final NavigatorState? navigator = _navigator?.currentState;
if (navigator == null)
if (navigator == null) {
return false;
}
return navigator.maybePop();
}

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

final NavigatorState? navigator = _navigator?.currentState;
if (navigator == null)
if (navigator == null) {
return false;
}
navigator.pushNamed(route);
return true;
}
Expand All @@ -1487,17 +1492,19 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
// Attempt to use localeListResolutionCallback.
if (widget.localeListResolutionCallback != null) {
final Locale? locale = widget.localeListResolutionCallback!(preferredLocales, widget.supportedLocales);
if (locale != null)
if (locale != null) {
return locale;
}
}
// localeListResolutionCallback failed, falling back to localeResolutionCallback.
if (widget.localeResolutionCallback != null) {
final Locale? locale = widget.localeResolutionCallback!(
preferredLocales != null && preferredLocales.isNotEmpty ? preferredLocales.first : null,
widget.supportedLocales,
);
if (locale != null)
if (locale != null) {
return locale;
}
}
// Both callbacks failed, falling back to default algorithm.
return basicLocaleListResolution(preferredLocales, supportedLocales);
Expand Down Expand Up @@ -1533,13 +1540,16 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
final Set<Type> unsupportedTypes =
_localizationsDelegates.map<Type>((LocalizationsDelegate<dynamic> delegate) => delegate.type).toSet();
for (final LocalizationsDelegate<dynamic> delegate in _localizationsDelegates) {
if (!unsupportedTypes.contains(delegate.type))
if (!unsupportedTypes.contains(delegate.type)) {
continue;
if (delegate.isSupported(appLocale))
}
if (delegate.isSupported(appLocale)) {
unsupportedTypes.remove(delegate.type);
}
}
if (unsupportedTypes.isEmpty)
if (unsupportedTypes.isEmpty) {
return true;
}

FlutterError.reportError(FlutterErrorDetails(
exception: "Warning: This application's locale, $appLocale, is not supported by all of its localization delegates.",
Expand Down
9 changes: 6 additions & 3 deletions packages/flutter/lib/src/widgets/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ class AsyncSnapshot<T> {
/// Throws [error], if [hasError]. Throws [StateError], if neither [hasData]
/// nor [hasError].
T get requireData {
if (hasData)
if (hasData) {
return data!;
if (hasError)
}
if (hasError) {
Error.throwWithStackTrace(error!, stackTrace!);
}
throw StateError('Snapshot has neither data nor error');
}

Expand Down Expand Up @@ -294,8 +296,9 @@ class AsyncSnapshot<T> {

@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
}
return other is AsyncSnapshot<T>
&& other.connectionState == connectionState
&& other.data == data
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/widgets/autofill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ class AutofillGroupState extends State<AutofillGroup> with AutofillScopeMixin {
void dispose() {
super.dispose();

if (!_isTopmostAutofillGroup || widget.onDisposeAction == null)
if (!_isTopmostAutofillGroup || widget.onDisposeAction == null) {
return;
}
switch (widget.onDisposeAction) {
case AutofillContextAction.cancel:
TextInput.finishAutofillContext(shouldSave: false);
Expand Down
18 changes: 12 additions & 6 deletions packages/flutter/lib/src/widgets/automatic_keep_alive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class _AutomaticKeepAliveState extends State<AutomaticKeepAlive> {
@override
void dispose() {
if (_handles != null) {
for (final Listenable handle in _handles!.keys)
for (final Listenable handle in _handles!.keys) {
handle.removeListener(_handles![handle]!);
}
}
super.dispose();
}
Expand Down Expand Up @@ -368,33 +369,38 @@ mixin AutomaticKeepAliveClientMixin<T extends StatefulWidget> on State<T> {
@protected
void updateKeepAlive() {
if (wantKeepAlive) {
if (_keepAliveHandle == null)
if (_keepAliveHandle == null) {
_ensureKeepAlive();
}
} else {
if (_keepAliveHandle != null)
if (_keepAliveHandle != null) {
_releaseKeepAlive();
}
}
}

@override
void initState() {
super.initState();
if (wantKeepAlive)
if (wantKeepAlive) {
_ensureKeepAlive();
}
}

@override
void deactivate() {
if (_keepAliveHandle != null)
if (_keepAliveHandle != null) {
_releaseKeepAlive();
}
super.deactivate();
}

@mustCallSuper
@override
Widget build(BuildContext context) {
if (wantKeepAlive && _keepAliveHandle == null)
if (wantKeepAlive && _keepAliveHandle == null) {
_ensureKeepAlive();
}
return const _NullWidget();
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/widgets/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ class BannerPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
if (!_prepared)
if (!_prepared) {
_prepare();
}
canvas
..translate(_translationX(size.width), _translationY(size.height))
..rotate(_rotation)
Expand Down
Loading

0 comments on commit bf4bb74

Please sign in to comment.