Unverified Commit 2aa348b9 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Use `curly_braces_in_flow_control_structures` for `widgets` (#104609)

* Use `curly_braces_in_flow_control_structures` for `widgets`

* fix comments

* fix comments
parent f22c2033
......@@ -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!,
......
......@@ -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) {
......@@ -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;
}
......@@ -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:
......
......@@ -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;
}
......@@ -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;
}
......@@ -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(
......@@ -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);
......
......@@ -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();
}
......@@ -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,
......@@ -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();
}
......
......@@ -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;
}
......@@ -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();
}
......@@ -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;
}
......@@ -1487,8 +1492,9 @@ 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) {
......@@ -1496,8 +1502,9 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
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);
......@@ -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.",
......
......@@ -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');
}
......@@ -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
......
......@@ -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);
......
......@@ -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();
}
......@@ -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();
}
}
......
......@@ -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)
......
......@@ -2170,8 +2170,9 @@ class LayoutId extends ParentDataWidget<MultiChildLayoutParentData> {
if (parentData.id != id) {
parentData.id = id;
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
if (targetParent is RenderObject) {
targetParent.markNeedsLayout();
}
}
}
......@@ -3175,8 +3176,9 @@ class _OffstageElement extends SingleChildRenderObjectElement {
@override
void debugVisitOnstageChildren(ElementVisitor visitor) {
if (!(widget as Offstage).offstage)
if (!(widget as Offstage).offstage) {
super.debugVisitOnstageChildren(visitor);
}
}
}
......@@ -4133,8 +4135,9 @@ class Positioned extends ParentDataWidget<StackParentData> {
if (needsLayout) {
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
if (targetParent is RenderObject) {
targetParent.markNeedsLayout();
}
}
}
......@@ -4993,8 +4996,9 @@ class Flexible extends ParentDataWidget<FlexParentData> {
if (needsLayout) {
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
if (targetParent is RenderObject) {
targetParent.markNeedsLayout();
}
}
}
......@@ -6437,12 +6441,15 @@ class MouseRegion extends SingleChildRenderObjectWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
final List<String> listeners = <String>[];
if (onEnter != null)
if (onEnter != null) {
listeners.add('enter');
if (onExit != null)
}
if (onExit != null) {
listeners.add('exit');
if (onHover != null)
}
if (onHover != null) {
listeners.add('hover');
}
properties.add(IterableProperty<String>('listeners', listeners, ifEmpty: '<none>'));
properties.add(DiagnosticsProperty<MouseCursor>('cursor', cursor, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('opaque', opaque, defaultValue: true));
......@@ -6957,8 +6964,9 @@ class Semantics extends SingleChildRenderObjectWidget {
}
TextDirection? _getTextDirection(BuildContext context) {
if (properties.textDirection != null)
if (properties.textDirection != null) {
return properties.textDirection;
}
final bool containsText = properties.attributedLabel != null ||
properties.label != null ||
......@@ -6966,8 +6974,9 @@ class Semantics extends SingleChildRenderObjectWidget {
properties.hint != null ||
properties.tooltip != null;
if (!containsText)
if (!containsText) {
return null;
}
return Directionality.maybeOf(context);
}
......@@ -7195,8 +7204,9 @@ class KeyedSubtree extends StatelessWidget {
/// Wrap each item in a KeyedSubtree whose key is based on the item's existing key or
/// the sum of its list index and `baseIndex`.
static List<Widget> ensureUniqueKeysForList(List<Widget> items, { int baseIndex = 0 }) {
if (items == null || items.isEmpty)
if (items == null || items.isEmpty) {
return items;
}
final List<Widget> itemsWithUniqueKeys = <Widget>[];
int itemIndex = baseIndex;
......
......@@ -375,8 +375,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
getter: () =>
Future<bool>.value(WidgetsApp.showPerformanceOverlayOverride),
setter: (bool value) {
if (WidgetsApp.showPerformanceOverlayOverride == value)
if (WidgetsApp.showPerformanceOverlayOverride == value) {
return Future<void>.value();
}
WidgetsApp.showPerformanceOverlayOverride = value;
return _forceRebuild();
},
......@@ -431,16 +432,18 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
name: 'profileWidgetBuilds',
getter: () async => debugProfileBuildsEnabled,
setter: (bool value) async {
if (debugProfileBuildsEnabled != value)
if (debugProfileBuildsEnabled != value) {
debugProfileBuildsEnabled = value;
}
},
);
registerBoolServiceExtension(
name: 'profileUserWidgetBuilds',
getter: () async => debugProfileBuildsEnabledUserWidgets,
setter: (bool value) async {
if (debugProfileBuildsEnabledUserWidgets != value)
if (debugProfileBuildsEnabledUserWidgets != value) {
debugProfileBuildsEnabledUserWidgets = value;
}
},
);
}
......@@ -450,8 +453,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
name: 'debugAllowBanner',
getter: () => Future<bool>.value(WidgetsApp.debugAllowBannerOverride),
setter: (bool value) {
if (WidgetsApp.debugAllowBannerOverride == value)
if (WidgetsApp.debugAllowBannerOverride == value) {
return Future<void>.value();
}
WidgetsApp.debugAllowBannerOverride = value;
return _forceRebuild();
},
......@@ -463,8 +467,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
name: 'debugWidgetInspector',
getter: () async => WidgetsApp.debugShowWidgetInspectorOverride,
setter: (bool value) {
if (WidgetsApp.debugShowWidgetInspectorOverride == value)
if (WidgetsApp.debugShowWidgetInspectorOverride == value) {
return Future<void>.value();
}
WidgetsApp.debugShowWidgetInspectorOverride = value;
return _forceRebuild();
},
......@@ -541,29 +546,33 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@override
void handleMetricsChanged() {
super.handleMetricsChanged();
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeMetrics();
}
}
@override
void handleTextScaleFactorChanged() {
super.handleTextScaleFactorChanged();
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeTextScaleFactor();
}
}
@override
void handlePlatformBrightnessChanged() {
super.handlePlatformBrightnessChanged();
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangePlatformBrightness();
}
}
@override
void handleAccessibilityFeaturesChanged() {
super.handleAccessibilityFeaturesChanged();
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeAccessibilityFeatures();
}
}
/// Called when the system locale changes.
......@@ -586,8 +595,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@protected
@mustCallSuper
void dispatchLocalesChanged(List<Locale>? locales) {
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeLocales(locales);
}
}
/// Notify all the observers that the active set of [AccessibilityFeatures]
......@@ -599,8 +609,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@protected
@mustCallSuper
void dispatchAccessibilityFeaturesChanged() {
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeAccessibilityFeatures();
}
}
/// Called when the system pops the current route.
......@@ -620,8 +631,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@protected
Future<void> handlePopRoute() async {
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) {
if (await observer.didPopRoute())
if (await observer.didPopRoute()) {
return;
}
}
SystemNavigator.pop();
}
......@@ -640,8 +652,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@mustCallSuper
Future<void> handlePushRoute(String route) async {
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) {
if (await observer.didPushRoute(route))
if (await observer.didPushRoute(route)) {
return;
}
}
}
......@@ -654,8 +667,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
state: routeArguments['state'] as Object?,
),
)
)
return;
) {
return;
}
}
}
......@@ -674,15 +688,17 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@override
void handleAppLifecycleStateChanged(AppLifecycleState state) {
super.handleAppLifecycleStateChanged(state);
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didChangeAppLifecycleState(state);
}
}
@override
void handleMemoryPressure() {
super.handleMemoryPressure();
for (final WidgetsBindingObserver observer in _observers)
for (final WidgetsBindingObserver observer in _observers) {
observer.didHaveMemoryPressure();
}
}
bool _needToReportFirstFrame = true;
......@@ -862,8 +878,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
}
try {
if (renderViewElement != null)
if (renderViewElement != null) {
buildOwner!.buildScope(renderViewElement!);
}
super.drawFrame();
buildOwner!.finalizeTree();
} finally {
......@@ -1128,8 +1145,9 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RootRenderObje
@override
void visitChildren(ElementVisitor visitor) {
if (_child != null)
if (_child != null) {
visitor(_child!);
}
}
@override
......@@ -1239,8 +1257,9 @@ class WidgetsFlutterBinding extends BindingBase with GestureBinding, SchedulerBi
/// [WidgetsFlutterBinding]. See
/// [TestWidgetsFlutterBinding.ensureInitialized].
static WidgetsBinding ensureInitialized() {
if (WidgetsBinding._instance == null)
if (WidgetsBinding._instance == null) {
WidgetsFlutterBinding();
}
return WidgetsBinding.instance;
}
}
......@@ -369,11 +369,13 @@ class Container extends StatelessWidget {
final Clip clipBehavior;
EdgeInsetsGeometry? get _paddingIncludingDecoration {
if (decoration == null || decoration!.padding == null)
if (decoration == null || decoration!.padding == null) {
return padding;
}
final EdgeInsetsGeometry? decorationPadding = decoration!.padding;
if (padding == null)
if (padding == null) {
return decorationPadding;
}
return padding!.add(decorationPadding!);
}
......@@ -392,11 +394,13 @@ class Container extends StatelessWidget {
}
final EdgeInsetsGeometry? effectivePadding = _paddingIncludingDecoration;
if (effectivePadding != null)
if (effectivePadding != null) {
current = Padding(padding: effectivePadding, child: current);
}
if (color != null)
if (color != null) {
current = ColoredBox(color: color!, child: current);
}
if (clipBehavior != Clip.none) {
assert(decoration != null);
......@@ -410,8 +414,9 @@ class Container extends StatelessWidget {
);
}
if (decoration != null)
if (decoration != null) {
current = DecoratedBox(decoration: decoration!, child: current);
}
if (foregroundDecoration != null) {
current = DecoratedBox(
......@@ -421,14 +426,17 @@ class Container extends StatelessWidget {
);
}
if (constraints != null)
if (constraints != null) {
current = ConstrainedBox(constraints: constraints!, child: current);
}
if (margin != null)
if (margin != null) {
current = Padding(padding: margin!, child: current);
}
if (transform != null)
if (transform != null) {
current = Transform(transform: transform!, alignment: transformAlignment, child: current);
}
return current!;
}
......@@ -439,10 +447,11 @@ class Container extends StatelessWidget {
properties.add(DiagnosticsProperty<AlignmentGeometry>('alignment', alignment, showName: false, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null));
properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.none));
if (color != null)
if (color != null) {
properties.add(DiagnosticsProperty<Color>('bg', color));
else
} else {
properties.add(DiagnosticsProperty<Decoration>('bg', decoration, defaultValue: null));
}
properties.add(DiagnosticsProperty<Decoration>('fg', foregroundDecoration, defaultValue: null));
properties.add(DiagnosticsProperty<BoxConstraints>('constraints', constraints, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('margin', margin, defaultValue: null));
......
......@@ -165,10 +165,12 @@ Key? _firstNonUniqueKey(Iterable<Widget> widgets) {
final Set<Key> keySet = HashSet<Key>();
for (final Widget widget in widgets) {
assert(widget != null);
if (widget.key == null)
if (widget.key == null) {
continue;
if (!keySet.add(widget.key!))
}
if (!keySet.add(widget.key!)) {
return widget.key;
}
}
return null;
}
......@@ -217,8 +219,9 @@ bool debugChildrenHaveDuplicateKeys(Widget parent, Iterable<Widget> children) {
bool debugItemsHaveDuplicateKeys(Iterable<Widget> items) {
assert(() {
final Key? nonUniqueKey = _firstNonUniqueKey(items);
if (nonUniqueKey != null)
if (nonUniqueKey != null) {
throw FlutterError('Duplicate key found: $nonUniqueKey.');
}
return true;
}());
return false;
......
......@@ -276,13 +276,15 @@ class _DismissibleClipper extends CustomClipper<Rect> {
switch (axis) {
case Axis.horizontal:
final double offset = moveAnimation.value.dx * size.width;
if (offset < 0)
if (offset < 0) {
return Rect.fromLTRB(size.width + offset, 0.0, size.width, size.height);
}
return Rect.fromLTRB(0.0, 0.0, offset, size.height);
case Axis.vertical:
final double offset = moveAnimation.value.dy * size.height;
if (offset < 0)
if (offset < 0) {
return Rect.fromLTRB(0.0, size.height + offset, size.width, size.height);
}
return Rect.fromLTRB(0.0, 0.0, size.width, offset);
}
}
......@@ -338,8 +340,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
}
DismissDirection _extentToDirection(double extent) {
if (extent == 0.0)
if (extent == 0.0) {
return DismissDirection.none;
}
if (_directionIsXAxis) {
switch (Directionality.of(context)) {
case TextDirection.rtl:
......@@ -363,8 +366,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
}
void _handleDragStart(DragStartDetails details) {
if (_confirming)
if (_confirming) {
return;
}
_dragUnderway = true;
if (_moveController!.isAnimating) {
_dragExtent = _moveController!.value * _overallDragAxisExtent * _dragExtent.sign;
......@@ -379,8 +383,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
}
void _handleDragUpdate(DragUpdateDetails details) {
if (!_isActive || _moveController!.isAnimating)
if (!_isActive || _moveController!.isAnimating) {
return;
}
final double delta = details.primaryDelta!;
final double oldDragExtent = _dragExtent;
......@@ -391,24 +396,28 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
break;
case DismissDirection.up:
if (_dragExtent + delta < 0)
if (_dragExtent + delta < 0) {
_dragExtent += delta;
}
break;
case DismissDirection.down:
if (_dragExtent + delta > 0)
if (_dragExtent + delta > 0) {
_dragExtent += delta;
}
break;
case DismissDirection.endToStart:
switch (Directionality.of(context)) {
case TextDirection.rtl:
if (_dragExtent + delta > 0)
if (_dragExtent + delta > 0) {
_dragExtent += delta;
}
break;
case TextDirection.ltr:
if (_dragExtent + delta < 0)
if (_dragExtent + delta < 0) {
_dragExtent += delta;
}
break;
}
break;
......@@ -416,12 +425,14 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
case DismissDirection.startToEnd:
switch (Directionality.of(context)) {
case TextDirection.rtl:
if (_dragExtent + delta < 0)
if (_dragExtent + delta < 0) {
_dragExtent += delta;
}
break;
case TextDirection.ltr:
if (_dragExtent + delta > 0)
if (_dragExtent + delta > 0) {
_dragExtent += delta;
}
break;
}
break;
......@@ -481,25 +492,29 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
DismissDirection flingDirection;
// Verify that the fling is in the generally right direction and fast enough.
if (_directionIsXAxis) {
if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta || vx.abs() < _kMinFlingVelocity)
if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta || vx.abs() < _kMinFlingVelocity) {
return _FlingGestureKind.none;
}
assert(vx != 0.0);
flingDirection = _extentToDirection(vx);
} else {
if (vy.abs() - vx.abs() < _kMinFlingVelocityDelta || vy.abs() < _kMinFlingVelocity)
if (vy.abs() - vx.abs() < _kMinFlingVelocityDelta || vy.abs() < _kMinFlingVelocity) {
return _FlingGestureKind.none;
}
assert(vy != 0.0);
flingDirection = _extentToDirection(vy);
}
assert(_dismissDirection != null);
if (flingDirection == _dismissDirection)
if (flingDirection == _dismissDirection) {
return _FlingGestureKind.forward;
}
return _FlingGestureKind.reverse;
}
void _handleDragEnd(DragEndDetails details) {
if (!_isActive || _moveController!.isAnimating)
if (!_isActive || _moveController!.isAnimating) {
return;
}
_dragUnderway = false;
if (_moveController!.isCompleted) {
_handleMoveCompleted();
......@@ -551,10 +566,11 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
}
final bool result = await _confirmStartResizeAnimation();
if (mounted) {
if (result)
if (result) {
_startResizeAnimation();
else
} else {
_moveController!.reverse();
}
}
}
......@@ -618,8 +634,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
Widget? background = widget.background;
if (widget.secondaryBackground != null) {
final DismissDirection direction = _dismissDirection;
if (direction == DismissDirection.endToStart || direction == DismissDirection.up)
if (direction == DismissDirection.endToStart || direction == DismissDirection.up) {
background = widget.secondaryBackground;
}
}
if (_resizeAnimation != null) {
......@@ -672,8 +689,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
// If the DismissDirection is none, we do not add drag gestures because the content
// cannot be dragged.
if (widget.direction == DismissDirection.none)
if (widget.direction == DismissDirection.none) {
return content;
}
// We are not resizing but we may be being dragging in widget.direction.
return GestureDetector(
......
......@@ -479,8 +479,9 @@ class LongPressDraggable<T extends Object> extends Draggable<T> {
return DelayedMultiDragGestureRecognizer(delay: delay)
..onStart = (Offset position) {
final Drag? result = onStart(position);
if (result != null && hapticFeedbackOnStart)
if (result != null && hapticFeedbackOnStart) {
HapticFeedback.selectionClick();
}
return result;
};
}
......@@ -518,21 +519,24 @@ class _DraggableState<T extends Object> extends State<Draggable<T>> {
int _activeCount = 0;
void _disposeRecognizerIfInactive() {
if (_activeCount > 0)
if (_activeCount > 0) {
return;
}
_recognizer!.dispose();
_recognizer = null;
}
void _routePointer(PointerDownEvent event) {
if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!)
if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!) {
return;
}
_recognizer!.addPointer(event);
}
_DragAvatar<T>? _startDrag(Offset position) {
if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!)
if (widget.maxSimultaneousDrags != null && _activeCount >= widget.maxSimultaneousDrags!) {
return null;
}
final Offset dragStartPoint;
if (widget.dragAnchorStrategy == null) {
switch (widget.dragAnchor) {
......@@ -580,10 +584,12 @@ class _DraggableState<T extends Object> extends State<Draggable<T>> {
offset: offset,
));
}
if (wasAccepted && widget.onDragCompleted != null)
if (wasAccepted && widget.onDragCompleted != null) {
widget.onDragCompleted!();
if (!wasAccepted && widget.onDraggableCanceled != null)
}
if (!wasAccepted && widget.onDraggableCanceled != null) {
widget.onDraggableCanceled!(velocity, offset);
}
},
);
widget.onDragStarted?.call();
......@@ -734,8 +740,9 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
// because dart doubles and ints are backed by the same kind of object on web.
// JavaScript does not support integers.
bool isExpectedDataType(Object? data, Type type) {
if (kIsWeb && ((type == int && T == double) || (type == double && T == int)))
if (kIsWeb && ((type == int && T == double) || (type == double && T == int))) {
return false;
}
return data is T?;
}
......@@ -757,8 +764,9 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
void didLeave(_DragAvatar<Object> avatar) {
assert(_candidateAvatars.contains(avatar) || _rejectedAvatars.contains(avatar));
if (!mounted)
if (!mounted) {
return;
}
setState(() {
_candidateAvatars.remove(avatar);
_rejectedAvatars.remove(avatar);
......@@ -768,8 +776,9 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
void didDrop(_DragAvatar<Object> avatar) {
assert(_candidateAvatars.contains(avatar));
if (!mounted)
if (!mounted) {
return;
}
setState(() {
_candidateAvatars.remove(avatar);
});
......@@ -778,8 +787,9 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
}
void didMove(_DragAvatar<Object> avatar) {
if (!mounted)
if (!mounted) {
return;
}
widget.onMove?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
}
......@@ -898,8 +908,9 @@ class _DragAvatar<T extends Object> extends Drag {
// Enter new targets.
final _DragTargetState<Object>? newTarget = targets.cast<_DragTargetState<Object>?>().firstWhere(
(_DragTargetState<Object>? target) {
if (target == null)
if (target == null) {
return false;
}
_enteredTargets.add(target);
return target.didEnter(this);
},
......@@ -922,16 +933,18 @@ class _DragAvatar<T extends Object> extends Drag {
final HitTestTarget target = entry.target;
if (target is RenderMetaData) {
final dynamic metaData = target.metaData;
if (metaData is _DragTargetState && metaData.isExpectedDataType(data, T))
if (metaData is _DragTargetState && metaData.isExpectedDataType(data, T)) {
targets.add(metaData);
}
}
}
return targets;
}
void _leaveAllEntered() {
for (int i = 0; i < _enteredTargets.length; i += 1)
for (int i = 0; i < _enteredTargets.length; i += 1) {
_enteredTargets[i].didLeave(this);
}
_enteredTargets.clear();
}
......
......@@ -753,8 +753,9 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
/// Use [nearestScope] to start at this node instead of above it.
FocusScopeNode? get enclosingScope {
for (final FocusNode node in ancestors) {
if (node is FocusScopeNode)
if (node is FocusScopeNode) {
return node;
}
}
return null;
}
......@@ -1319,8 +1320,9 @@ class FocusScopeNode extends FocusNode {
assert(findFirstFocus != null);
// It is possible that a previously focused child is no longer focusable.
while (this.focusedChild != null && !this.focusedChild!.canRequestFocus)
while (this.focusedChild != null && !this.focusedChild!.canRequestFocus) {
_focusedChildren.removeLast();
}
final FocusNode? focusedChild = this.focusedChild;
// If findFirstFocus is false, then the request is to make this scope the
......
......@@ -156,8 +156,9 @@ class FormState extends State<Form> {
/// Saves every [FormField] that is a descendant of this [Form].
void save() {
for (final FormFieldState<dynamic> field in _fields)
for (final FormFieldState<dynamic> field in _fields) {
field.save();
}
}
/// Resets every [FormField] that is a descendant of this [Form] back to its
......@@ -168,8 +169,9 @@ class FormState extends State<Form> {
/// If the form's [Form.autovalidateMode] property is [AutovalidateMode.always],
/// the fields will all be revalidated after being reset.
void reset() {
for (final FormFieldState<dynamic> field in _fields)
for (final FormFieldState<dynamic> field in _fields) {
field.reset();
}
_hasInteractedByUser = false;
_fieldDidChange();
}
......@@ -186,8 +188,9 @@ class FormState extends State<Form> {
bool _validate() {
bool hasError = false;
for (final FormFieldState<dynamic> field in _fields)
for (final FormFieldState<dynamic> field in _fields) {
hasError = !field.validate() || hasError;
}
return !hasError;
}
}
......@@ -391,8 +394,9 @@ class FormFieldState<T> extends State<FormField<T>> with RestorationMixin {
}
void _validate() {
if (widget.validator != null)
if (widget.validator != null) {
_errorText.value = widget.validator!(_value);
}
}
/// Updates this field's state to the new value. Useful for responding to
......
......@@ -1434,8 +1434,9 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
/// If this is never called, then the actions are not filtered. If the list of
/// actions to filter changes, it must be called again.
void replaceSemanticsActions(Set<SemanticsAction> actions) {
if (widget.excludeFromSemantics)
if (widget.excludeFromSemantics) {
return;
}
final RenderSemanticsGestureHandler? semanticsGestureHandler = context.findRenderObject() as RenderSemanticsGestureHandler?;
assert(() {
......@@ -1453,8 +1454,9 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
@override
void dispose() {
for (final GestureRecognizer recognizer in _recognizers!.values)
for (final GestureRecognizer recognizer in _recognizers!.values) {
recognizer.dispose();
}
_recognizers = null;
super.dispose();
}
......@@ -1472,15 +1474,17 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
gestures[type]!.initializer(_recognizers![type]!);
}
for (final Type type in oldRecognizers.keys) {
if (!_recognizers!.containsKey(type))
if (!_recognizers!.containsKey(type)) {
oldRecognizers[type]!.dispose();
}
}
}
void _handlePointerDown(PointerDownEvent event) {
assert(_recognizers != null);
for (final GestureRecognizer recognizer in _recognizers!.values)
for (final GestureRecognizer recognizer in _recognizers!.values) {
recognizer.addPointer(event);
}
}
void _handlePointerPanZoomStart(PointerPanZoomStartEvent event) {
......@@ -1611,8 +1615,9 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
GestureTapCallback? _getTapHandler(Map<Type, GestureRecognizer> recognizers) {
final TapGestureRecognizer? tap = recognizers[TapGestureRecognizer] as TapGestureRecognizer?;
if (tap == null)
if (tap == null) {
return null;
}
return () {
assert(tap != null);
......@@ -1624,8 +1629,9 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
GestureLongPressCallback? _getLongPressHandler(Map<Type, GestureRecognizer> recognizers) {
final LongPressGestureRecognizer? longPress = recognizers[LongPressGestureRecognizer] as LongPressGestureRecognizer?;
if (longPress == null)
if (longPress == null) {
return null;
}
return () {
longPress.onLongPressDown?.call(const LongPressDownDetails());
......@@ -1658,13 +1664,16 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
pan.onEnd?.call(DragEndDetails());
};
if (horizontalHandler == null && panHandler == null)
if (horizontalHandler == null && panHandler == null) {
return null;
}
return (DragUpdateDetails details) {
if (horizontalHandler != null)
if (horizontalHandler != null) {
horizontalHandler(details);
if (panHandler != null)
}
if (panHandler != null) {
panHandler(details);
}
};
}
......@@ -1690,13 +1699,16 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
pan.onEnd?.call(DragEndDetails());
};
if (verticalHandler == null && panHandler == null)
if (verticalHandler == null && panHandler == null) {
return null;
}
return (DragUpdateDetails details) {
if (verticalHandler != null)
if (verticalHandler != null) {
verticalHandler(details);
if (panHandler != null)
}
if (panHandler != null) {
panHandler(details);
}
};
}
}
......@@ -378,8 +378,9 @@ class _HeroState extends State<Hero> {
// This method can be safely called even when this [Hero] is currently not in
// a flight.
void endFlight({ bool keepPlaceholder = false }) {
if (keepPlaceholder || _placeholderSize == null)
if (keepPlaceholder || _placeholderSize == null) {
return;
}
_placeholderSize = null;
if (mounted) {
......@@ -590,8 +591,9 @@ class _HeroFlight {
return;
}
if (_scheduledPerformAnimationUpdate)
if (_scheduledPerformAnimationUpdate) {
return;
}
// The `navigator` must be non-null here, or the first if clause above would
// have returned from this method.
......@@ -730,10 +732,11 @@ class _HeroFlight {
);
shuttle = null;
if (newManifest.type == HeroFlightDirection.pop)
if (newManifest.type == HeroFlightDirection.pop) {
_proxyAnimation.parent = ReverseAnimation(newManifest.animation);
else
} else {
_proxyAnimation.parent = newManifest.animation;
}
manifest.fromHero.endFlight(keepPlaceholder: true);
manifest.toHero.endFlight(keepPlaceholder: true);
......@@ -796,8 +799,9 @@ class HeroController extends NavigatorObserver {
assert(route != null);
// Don't trigger another flight when a pop is committed as a user gesture
// back swipe is snapped.
if (!navigator!.userGestureInProgress)
if (!navigator!.userGestureInProgress) {
_maybeStartHeroTransition(route, previousRoute, HeroFlightDirection.pop, false);
}
}
@override
......@@ -818,8 +822,9 @@ class HeroController extends NavigatorObserver {
@override
void didStopUserGesture() {
if (navigator!.userGestureInProgress)
if (navigator!.userGestureInProgress) {
return;
}
// When the user gesture ends, if the user horizontal drag gesture initiated
// the flight (i.e. the back swipe) didn't move towards the pop direction at
......@@ -908,8 +913,9 @@ class HeroController extends NavigatorObserver {
// callback was called, then don't actually start a transition, and we don'
// t have to worry about any Hero widget we might have hidden in a previous
// flight, or ongoing flights.
if (navigator == null || overlay == null)
if (navigator == null || overlay == null) {
return;
}
final RenderObject? navigatorRenderObject = navigator.context.findRenderObject();
......@@ -975,8 +981,9 @@ class HeroController extends NavigatorObserver {
// This can happen in a route pop transition when a fromHero is no longer
// mounted, or kept alive by the [KeepAlive] mechanism but no longer visible.
// TODO(LongCatIsLooong): resume aborted flights: https://github.com/flutter/flutter/issues/72947
for (final _HeroState toHero in toHeroes.values)
for (final _HeroState toHero in toHeroes.values) {
toHero.endFlight();
}
}
void _handleFlightEnded(_HeroFlight flight) {
......
......@@ -181,8 +181,9 @@ class Icon extends StatelessWidget {
final double iconOpacity = iconTheme.opacity ?? 1.0;
Color iconColor = color ?? iconTheme.color!;
if (iconOpacity != 1.0)
if (iconOpacity != 1.0) {
iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
}
Widget iconWidget = RichText(
overflow: TextOverflow.visible, // Never clip.
......
......@@ -49,8 +49,9 @@ class IconData {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is IconData
&& other.codePoint == codePoint
&& other.fontFamily == fontFamily
......
......@@ -49,8 +49,9 @@ class IconThemeData with Diagnosticable {
/// replaced by the non-null parameters of the given icon theme. If the given
/// icon theme is null, simply returns this icon theme.
IconThemeData merge(IconThemeData? other) {
if (other == null)
if (other == null) {
return this;
}
return copyWith(
color: other.color,
opacity: other.opacity,
......@@ -108,8 +109,9 @@ class IconThemeData with Diagnosticable {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is IconThemeData
&& other.color == color
&& other.opacity == opacity
......
......@@ -1065,10 +1065,11 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
_updateInvertColors();
_resolveImage();
if (TickerMode.of(context))
if (TickerMode.of(context)) {
_listenToStream();
else
} else {
_stopListeningToStream(keepStreamAlive: true);
}
super.didChangeDependencies();
}
......@@ -1082,8 +1083,9 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
_imageStream!.addListener(_getListener(recreateListener: true));
_imageStream!.removeListener(oldListener);
}
if (widget.image != oldWidget.image)
if (widget.image != oldWidget.image) {
_resolveImage();
}
}
@override
......@@ -1176,14 +1178,17 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
// registration from the old stream to the new stream (if a listener was
// registered).
void _updateSourceStream(ImageStream newStream) {
if (_imageStream?.key == newStream.key)
if (_imageStream?.key == newStream.key) {
return;
}
if (_isListeningToStream)
if (_isListeningToStream) {
_imageStream!.removeListener(_getListener());
}
if (!widget.gaplessPlayback)
if (!widget.gaplessPlayback) {
setState(() { _replaceImage(info: null); });
}
setState(() {
_loadingProgress = null;
......@@ -1192,13 +1197,15 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
});
_imageStream = newStream;
if (_isListeningToStream)
if (_isListeningToStream) {
_imageStream!.addListener(_getListener());
}
}
void _listenToStream() {
if (_isListeningToStream)
if (_isListeningToStream) {
return;
}
_imageStream!.addListener(_getListener());
_completerHandle?.dispose();
......@@ -1215,8 +1222,9 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
/// to true, which create [ImageStreamCompleterHandle] to keep the completer
/// alive and is compatible with the [TickerMode] being off.
void _stopListeningToStream({bool keepStreamAlive = false}) {
if (!_isListeningToStream)
if (!_isListeningToStream) {
return;
}
if (keepStreamAlive && _completerHandle == null && _imageStream?.completer != null) {
_completerHandle = _imageStream!.completer!.keepAlive();
......@@ -1257,10 +1265,12 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
if (_lastException != null) {
if (widget.errorBuilder != null)
if (widget.errorBuilder != null) {
return widget.errorBuilder!(context, _lastException!, _lastStack);
if (kDebugMode)
}
if (kDebugMode) {
return _debugBuildErrorWidget(context, _lastException!);
}
}
Widget result = RawImage(
......@@ -1295,11 +1305,13 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
);
}
if (widget.frameBuilder != null)
if (widget.frameBuilder != null) {
result = widget.frameBuilder!(context, result, _frameNumber, _wasSynchronouslyLoaded);
}
if (widget.loadingBuilder != null)
if (widget.loadingBuilder != null) {
result = widget.loadingBuilder!(context, result, _loadingProgress);
}
return result;
}
......
......@@ -69,17 +69,19 @@ class ImageIcon extends StatelessWidget {
final IconThemeData iconTheme = IconTheme.of(context);
final double? iconSize = size ?? iconTheme.size;
if (image == null)
if (image == null) {
return Semantics(
label: semanticLabel,
child: SizedBox(width: iconSize, height: iconSize),
);
}
final double? iconOpacity = iconTheme.opacity;
Color iconColor = color ?? iconTheme.color!;
if (iconOpacity != null && iconOpacity != 1.0)
if (iconOpacity != null && iconOpacity != 1.0) {
iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
}
return Semantics(
label: semanticLabel,
......
......@@ -415,8 +415,9 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
}
void _updateTween(Tween<dynamic>? tween, dynamic targetValue) {
if (tween == null)
if (tween == null) {
return;
}
tween
..begin = tween.evaluate(_animation)
..end = targetValue;
......@@ -427,10 +428,11 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
forEachTween((Tween<dynamic>? tween, dynamic targetValue, TweenConstructor<dynamic> constructor) {
if (targetValue != null) {
tween ??= constructor(targetValue);
if (_shouldAnimateTween(tween, targetValue))
if (_shouldAnimateTween(tween, targetValue)) {
shouldStartAnimation = true;
else
} else {
tween.end ??= tween.begin;
}
} else {
tween = null;
}
......
......@@ -119,23 +119,26 @@ abstract class InheritedModel<T> extends InheritedWidget {
// with the one that supports the specified model [aspect].
static void _findModels<T extends InheritedModel<Object>>(BuildContext context, Object aspect, List<InheritedElement> results) {
final InheritedElement? model = context.getElementForInheritedWidgetOfExactType<T>();
if (model == null)
if (model == null) {
return;
}
results.add(model);
assert(model.widget is T);
final T modelWidget = model.widget as T;
if (modelWidget.isSupportedAspect(aspect))
if (modelWidget.isSupportedAspect(aspect)) {
return;
}
Element? modelParent;
model.visitAncestorElements((Element ancestor) {
modelParent = ancestor;
return false;
});
if (modelParent == null)
if (modelParent == null) {
return;
}
_findModels<T>(modelParent!, aspect, results);
}
......@@ -156,8 +159,9 @@ abstract class InheritedModel<T> extends InheritedWidget {
///
/// If no ancestor of type T exists, null is returned.
static T? inheritFrom<T extends InheritedModel<Object>>(BuildContext context, { Object? aspect }) {
if (aspect == null)
if (aspect == null) {
return context.dependOnInheritedWidgetOfExactType<T>();
}
// Create a dependency on all of the type T ancestor models up until
// a model is found for which isSupportedAspect(aspect) is true.
......@@ -170,8 +174,9 @@ abstract class InheritedModel<T> extends InheritedWidget {
final InheritedElement lastModel = models.last;
for (final InheritedElement model in models) {
final T value = context.dependOnInheritedElement(model, aspect: aspect) as T;
if (model == lastModel)
if (model == lastModel) {
return value;
}
}
assert(false);
......@@ -187,8 +192,9 @@ class InheritedModelElement<T> extends InheritedElement {
@override
void updateDependencies(Element dependent, Object? aspect) {
final Set<T>? dependencies = getDependencies(dependent) as Set<T>?;
if (dependencies != null && dependencies.isEmpty)
if (dependencies != null && dependencies.isEmpty) {
return;
}
if (aspect == null) {
setDependencies(dependent, HashSet<T>());
......@@ -201,9 +207,11 @@ class InheritedModelElement<T> extends InheritedElement {
@override
void notifyDependent(InheritedModel<T> oldWidget, Element dependent) {
final Set<T>? dependencies = getDependencies(dependent) as Set<T>?;
if (dependencies == null)
if (dependencies == null) {
return;
if (dependencies.isEmpty || (widget as InheritedModel<T>).updateShouldNotifyDependent(oldWidget, dependencies))
}
if (dependencies.isEmpty || (widget as InheritedModel<T>).updateShouldNotifyDependent(oldWidget, dependencies)) {
dependent.didChangeDependencies();
}
}
}
......@@ -109,8 +109,9 @@ class _InheritedNotifierElement<T extends Listenable> extends InheritedElement {
@override
Widget build() {
if (_dirty)
if (_dirty) {
notifyClients(widget as InheritedNotifier<T>);
}
return super.build();
}
......
......@@ -153,8 +153,9 @@ class _CaptureAll extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget wrappedChild = child;
for (final InheritedTheme theme in themes)
for (final InheritedTheme theme in themes) {
wrappedChild = theme.wrap(context, wrappedChild);
}
return wrappedChild;
}
}
......@@ -63,8 +63,9 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb
@override
void visitChildren(ElementVisitor visitor) {
if (_child != null)
if (_child != null) {
visitor(_child!);
}
}
@override
......@@ -183,8 +184,9 @@ mixin RenderConstrainedLayoutBuilder<ConstraintType extends Constraints, ChildTy
LayoutCallback<ConstraintType>? _callback;
/// Change the layout callback.
void updateCallback(LayoutCallback<ConstraintType>? value) {
if (value == _callback)
if (value == _callback) {
return;
}
_callback = value;
markNeedsLayout();
}
......@@ -322,8 +324,9 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren
@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
if (child != null)
if (child != null) {
return child!.getDistanceToActualBaseline(baseline);
}
return super.computeDistanceToActualBaseline(baseline);
}
......@@ -334,8 +337,9 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren
@override
void paint(PaintingContext context, Offset offset) {
if (child != null)
if (child != null) {
context.paintChild(child!, offset);
}
}
bool _debugThrowIfNotCheckingIntrinsics() {
......
......@@ -91,8 +91,9 @@ class ListWheelChildListDelegate extends ListWheelChildDelegate {
@override
Widget? build(BuildContext context, int index) {
if (index < 0 || index >= children.length)
if (index < 0 || index >= children.length) {
return null;
}
return IndexedSemantics(index: index, child: children[index]);
}
......@@ -137,8 +138,9 @@ class ListWheelChildLoopingListDelegate extends ListWheelChildDelegate {
@override
Widget? build(BuildContext context, int index) {
if (children.isEmpty)
if (children.isEmpty) {
return null;
}
return IndexedSemantics(index: index, child: children[index % children.length]);
}
......@@ -184,8 +186,9 @@ class ListWheelChildBuilderDelegate extends ListWheelChildDelegate {
final Widget? child = builder(context, index);
return child == null ? null : IndexedSemantics(index: index, child: child);
}
if (index < 0 || index >= childCount!)
if (index < 0 || index >= childCount!) {
return null;
}
return IndexedSemantics(index: index, child: builder(context, index));
}
......@@ -830,8 +833,9 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
void performRebuild() {
_childWidgets.clear();
super.performRebuild();
if (_childElements.isEmpty)
if (_childElements.isEmpty) {
return;
}
final int firstIndex = _childElements.firstKey()!;
final int lastIndex = _childElements.lastKey()!;
......@@ -892,8 +896,9 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
final ListWheelParentData? newParentData = newChild?.renderObject?.parentData as ListWheelParentData?;
if (newParentData != null) {
newParentData.index = newSlot! as int;
if (oldParentData != null)
if (oldParentData != null) {
newParentData.offset = oldParentData.offset;
}
}
return newChild;
......
......@@ -68,8 +68,9 @@ Future<Map<Type, dynamic>> _loadAll(Locale locale, Iterable<LocalizationsDelegat
}
// All of the delegate.load() values were synchronous futures, we're done.
if (pendingList == null)
if (pendingList == null) {
return SynchronousFuture<Map<Type, dynamic>>(output);
}
// Some of delegate.load() values were asynchronous futures. Wait for them.
return Future.wait<dynamic>(pendingList.map<Future<dynamic>>((_Pending p) => p.futureValue))
......@@ -381,8 +382,9 @@ class Localizations extends StatefulWidget {
Widget? child,
}) {
final List<LocalizationsDelegate<dynamic>> mergedDelegates = Localizations._delegatesOf(context);
if (delegates != null)
if (delegates != null) {
mergedDelegates.insertAll(0, delegates);
}
return Localizations(
key: key,
locale: locale ?? Localizations.localeOf(context),
......@@ -496,15 +498,17 @@ class _LocalizationsState extends State<Localizations> {
}
bool _anyDelegatesShouldReload(Localizations old) {
if (widget.delegates.length != old.delegates.length)
if (widget.delegates.length != old.delegates.length) {
return true;
}
final List<LocalizationsDelegate<dynamic>> delegates = widget.delegates.toList();
final List<LocalizationsDelegate<dynamic>> oldDelegates = old.delegates.toList();
for (int i = 0; i < delegates.length; i += 1) {
final LocalizationsDelegate<dynamic> delegate = delegates[i];
final LocalizationsDelegate<dynamic> oldDelegate = oldDelegates[i];
if (delegate.runtimeType != oldDelegate.runtimeType || delegate.shouldReload(oldDelegate))
if (delegate.runtimeType != oldDelegate.runtimeType || delegate.shouldReload(oldDelegate)) {
return true;
}
}
return false;
}
......@@ -515,8 +519,9 @@ class _LocalizationsState extends State<Localizations> {
if (widget.locale != old.locale
|| (widget.delegates == null)
|| (widget.delegates != null && old.delegates == null)
|| (widget.delegates != null && _anyDelegatesShouldReload(old)))
|| (widget.delegates != null && _anyDelegatesShouldReload(old))) {
load(widget.locale);
}
}
void load(Locale locale) {
......@@ -568,8 +573,9 @@ class _LocalizationsState extends State<Localizations> {
@override
Widget build(BuildContext context) {
if (_locale == null)
if (_locale == null) {
return Container();
}
return Semantics(
textDirection: _textDirection,
child: _LocalizationsScope(
......
......@@ -436,8 +436,9 @@ class MediaQueryData {
bool removeRight = false,
bool removeBottom = false,
}) {
if (!(removeLeft || removeTop || removeRight || removeBottom))
if (!(removeLeft || removeTop || removeRight || removeBottom)) {
return this;
}
return copyWith(
padding: padding.copyWith(
left: removeLeft ? 0.0 : null,
......@@ -473,8 +474,9 @@ class MediaQueryData {
bool removeRight = false,
bool removeBottom = false,
}) {
if (!(removeLeft || removeTop || removeRight || removeBottom))
if (!(removeLeft || removeTop || removeRight || removeBottom)) {
return this;
}
return copyWith(
viewPadding: viewPadding.copyWith(
left: removeLeft ? math.max(0.0, viewPadding.left - viewInsets.left) : null,
......@@ -510,8 +512,9 @@ class MediaQueryData {
bool removeRight = false,
bool removeBottom = false,
}) {
if (!(removeLeft || removeTop || removeRight || removeBottom))
if (!(removeLeft || removeTop || removeRight || removeBottom)) {
return this;
}
return copyWith(
padding: padding.copyWith(
left: removeLeft ? 0.0 : null,
......@@ -548,8 +551,9 @@ class MediaQueryData {
assert(subScreen.left >= 0.0 && subScreen.top >= 0.0 &&
subScreen.right <= size.width && subScreen.bottom <= size.height,
"'subScreen' argument cannot be outside the bounds of the screen");
if (subScreen.size == size && subScreen.topLeft == Offset.zero)
if (subScreen.size == size && subScreen.topLeft == Offset.zero) {
return this;
}
final double rightInset = size.width - subScreen.right;
final double bottomInset = size.height - subScreen.bottom;
return copyWith(
......@@ -579,8 +583,9 @@ class MediaQueryData {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is MediaQueryData
&& other.size == size
&& other.devicePixelRatio == devicePixelRatio
......
......@@ -238,8 +238,9 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer {
@protected
@override
bool isPointerAllowed(PointerDownEvent event) {
if (onAnyTapUp == null)
if (onAnyTapUp == null) {
return false;
}
return super.isPointerAllowed(event);
}
......
......@@ -152,10 +152,11 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
// widgets, then align its left or right edge with the adjacent boundary.
if (centerMiddle) {
middleStart = (size.width - middleSize.width) / 2.0;
if (middleStart + middleSize.width > size.width - trailingWidth)
if (middleStart + middleSize.width > size.width - trailingWidth) {
middleStart = size.width - trailingWidth - middleSize.width;
else if (middleStart < middleStartMargin)
} else if (middleStart < middleStartMargin) {
middleStart = middleStartMargin;
}
}
final double middleX;
......
......@@ -276,8 +276,9 @@ class _RenderOverflowBar extends RenderBox
double _spacing;
set spacing (double value) {
assert(value != null);
if (_spacing == value)
if (_spacing == value) {
return;
}
_spacing = value;
markNeedsLayout();
}
......@@ -285,8 +286,9 @@ class _RenderOverflowBar extends RenderBox
MainAxisAlignment? get alignment => _alignment;
MainAxisAlignment? _alignment;
set alignment (MainAxisAlignment? value) {
if (_alignment == value)
if (_alignment == value) {
return;
}
_alignment = value;
markNeedsLayout();
}
......@@ -295,8 +297,9 @@ class _RenderOverflowBar extends RenderBox
double _overflowSpacing;
set overflowSpacing (double value) {
assert(value != null);
if (_overflowSpacing == value)
if (_overflowSpacing == value) {
return;
}
_overflowSpacing = value;
markNeedsLayout();
}
......@@ -305,8 +308,9 @@ class _RenderOverflowBar extends RenderBox
OverflowBarAlignment _overflowAlignment;
set overflowAlignment (OverflowBarAlignment value) {
assert(value != null);
if (_overflowAlignment == value)
if (_overflowAlignment == value) {
return;
}
_overflowAlignment = value;
markNeedsLayout();
}
......@@ -315,8 +319,9 @@ class _RenderOverflowBar extends RenderBox
VerticalDirection _overflowDirection;
set overflowDirection (VerticalDirection value) {
assert(value != null);
if (_overflowDirection == value)
if (_overflowDirection == value) {
return;
}
_overflowDirection = value;
markNeedsLayout();
}
......@@ -324,8 +329,9 @@ class _RenderOverflowBar extends RenderBox
TextDirection get textDirection => _textDirection;
TextDirection _textDirection;
set textDirection(TextDirection value) {
if (_textDirection == value)
if (_textDirection == value) {
return;
}
_textDirection = value;
markNeedsLayout();
}
......@@ -334,8 +340,9 @@ class _RenderOverflowBar extends RenderBox
Clip _clipBehavior = Clip.none;
set clipBehavior(Clip value) {
assert(value != null);
if (value == _clipBehavior)
if (value == _clipBehavior) {
return;
}
_clipBehavior = value;
markNeedsPaint();
markNeedsSemanticsUpdate();
......@@ -343,15 +350,17 @@ class _RenderOverflowBar extends RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! _OverflowBarParentData)
if (child.parentData is! _OverflowBarParentData) {
child.parentData = _OverflowBarParentData();
}
}
@override
double computeMinIntrinsicHeight(double width) {
RenderBox? child = firstChild;
if (child == null)
if (child == null) {
return 0;
}
double barWidth = 0.0;
while (child != null) {
barWidth += child.getMinIntrinsicWidth(double.infinity);
......@@ -380,8 +389,9 @@ class _RenderOverflowBar extends RenderBox
@override
double computeMaxIntrinsicHeight(double width) {
RenderBox? child = firstChild;
if (child == null)
if (child == null) {
return 0;
}
double barWidth = 0.0;
while (child != null) {
barWidth += child.getMinIntrinsicWidth(double.infinity);
......@@ -410,8 +420,9 @@ class _RenderOverflowBar extends RenderBox
@override
double computeMinIntrinsicWidth(double height) {
RenderBox? child = firstChild;
if (child == null)
if (child == null) {
return 0;
}
double width = 0.0;
while (child != null) {
width += child.getMinIntrinsicWidth(double.infinity);
......@@ -423,8 +434,9 @@ class _RenderOverflowBar extends RenderBox
@override
double computeMaxIntrinsicWidth(double height) {
RenderBox? child = firstChild;
if (child == null)
if (child == null) {
return 0;
}
double width = 0.0;
while (child != null) {
width += child.getMaxIntrinsicWidth(double.infinity);
......
......@@ -90,8 +90,9 @@ class OverlayEntry implements Listenable {
bool _opaque;
set opaque(bool value) {
assert(!_disposedByOwner);
if (_opaque == value)
if (_opaque == value) {
return;
}
_opaque = value;
_overlay?._didChangeEntryOpacity();
}
......@@ -115,8 +116,9 @@ class OverlayEntry implements Listenable {
set maintainState(bool value) {
assert(!_disposedByOwner);
assert(_maintainState != null);
if (_maintainState == value)
if (_maintainState == value) {
return;
}
_maintainState = value;
assert(_overlay != null);
_overlay!._didChangeEntryOpacity();
......@@ -160,8 +162,9 @@ class OverlayEntry implements Listenable {
assert(!_disposedByOwner);
final OverlayState overlay = _overlay!;
_overlay = null;
if (!overlay.mounted)
if (!overlay.mounted) {
return;
}
overlay._entries.remove(this);
if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
......@@ -381,10 +384,12 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
int _insertionIndex(OverlayEntry? below, OverlayEntry? above) {
assert(above == null || below == null);
if (below != null)
if (below != null) {
return _entries.indexOf(below);
if (above != null)
}
if (above != null) {
return _entries.indexOf(above) + 1;
}
return _entries.length;
}
......@@ -422,8 +427,9 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
entries.every((OverlayEntry entry) => entry._overlay == null),
'One or more of the specified entries are already present in another Overlay.',
);
if (entries.isEmpty)
if (entries.isEmpty) {
return;
}
for (final OverlayEntry entry in entries) {
assert(entry._overlay == null);
entry._overlay = this;
......@@ -477,10 +483,12 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
newEntriesList.every((OverlayEntry entry) => _entries.indexOf(entry) == _entries.lastIndexOf(entry)),
'One or more of the specified entries are specified multiple times.',
);
if (newEntriesList.isEmpty)
if (newEntriesList.isEmpty) {
return;
if (listEquals(_entries, newEntriesList))
}
if (listEquals(_entries, newEntriesList)) {
return;
}
final LinkedHashSet<OverlayEntry> old = LinkedHashSet<OverlayEntry>.of(_entries);
for (final OverlayEntry entry in newEntriesList) {
entry._overlay ??= this;
......@@ -515,8 +523,9 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
result = true;
break;
}
if (candidate.opaque)
if (candidate.opaque) {
break;
}
}
return true;
}());
......@@ -545,8 +554,9 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
key: entry._key,
entry: entry,
));
if (entry.opaque)
if (entry.opaque) {
onstage = false;
}
} else if (entry.maintainState) {
children.add(_OverlayEntryWidget(
key: entry._key,
......@@ -651,15 +661,17 @@ class _RenderTheatre extends RenderBox with ContainerRenderObjectMixin<RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! StackParentData)
if (child.parentData is! StackParentData) {
child.parentData = StackParentData();
}
}
Alignment? _resolvedAlignment;
void _resolve() {
if (_resolvedAlignment != null)
if (_resolvedAlignment != null) {
return;
}
_resolvedAlignment = AlignmentDirectional.topStart.resolve(textDirection);
}
......@@ -671,8 +683,9 @@ class _RenderTheatre extends RenderBox with ContainerRenderObjectMixin<RenderBox
TextDirection get textDirection => _textDirection;
TextDirection _textDirection;
set textDirection(TextDirection value) {
if (_textDirection == value)
if (_textDirection == value) {
return;
}
_textDirection = value;
_markNeedResolution();
}
......@@ -813,8 +826,9 @@ class _RenderTheatre extends RenderBox with ContainerRenderObjectMixin<RenderBox
return child!.hitTest(result, position: transformed);
},
);
if (isHit)
if (isHit) {
return true;
}
child = childParentData.previousSibling;
}
return false;
......
......@@ -202,8 +202,9 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
final Map<bool, bool> _accepted = <bool, bool>{false: true, true: true};
bool _handleScrollNotification(ScrollNotification notification) {
if (!widget.notificationPredicate(notification))
if (!widget.notificationPredicate(notification)) {
return false;
}
// Update the paint offset with the current scroll position. This makes
// sure that the glow effect correctly scrolls in line with the current
......@@ -358,8 +359,9 @@ class _GlowController extends ChangeNotifier {
Color _color;
set color(Color value) {
assert(color != null);
if (color == value)
if (color == value) {
return;
}
_color = value;
notifyListeners();
}
......@@ -368,8 +370,9 @@ class _GlowController extends ChangeNotifier {
Axis _axis;
set axis(Axis value) {
assert(axis != null);
if (axis == value)
if (axis == value) {
return;
}
_axis = value;
notifyListeners();
}
......@@ -459,13 +462,15 @@ class _GlowController extends ChangeNotifier {
}
void scrollEnd() {
if (_state == _GlowState.pull)
if (_state == _GlowState.pull) {
_recede(_recedeTime);
}
}
void _changePhase(AnimationStatus status) {
if (status != AnimationStatus.completed)
if (status != AnimationStatus.completed) {
return;
}
switch (_state) {
case _GlowState.absorb:
_recede(_recedeTime);
......@@ -481,8 +486,9 @@ class _GlowController extends ChangeNotifier {
}
void _recede(Duration duration) {
if (_state == _GlowState.recede || _state == _GlowState.idle)
if (_state == _GlowState.recede || _state == _GlowState.idle) {
return;
}
_pullRecedeTimer?.cancel();
_pullRecedeTimer = null;
_glowOpacityTween.begin = _glowOpacity.value;
......@@ -509,8 +515,9 @@ class _GlowController extends ChangeNotifier {
}
void paint(Canvas canvas, Size size) {
if (_glowOpacity.value == 0.0)
if (_glowOpacity.value == 0.0) {
return;
}
final double baseGlowScale = size.width > size.height ? size.height / size.width : 1.0;
final double radius = size.width * 3.0 / 2.0;
final double height = math.min(size.height, size.width * _widthToHeightFactor);
......@@ -556,8 +563,9 @@ class _GlowingOverscrollIndicatorPainter extends CustomPainter {
static const double piOver2 = math.pi / 2.0;
void _paintSide(Canvas canvas, Size size, _GlowController? controller, AxisDirection axisDirection, GrowthDirection growthDirection) {
if (controller == null)
if (controller == null) {
return;
}
switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) {
case AxisDirection.up:
controller.paint(canvas, size);
......@@ -690,8 +698,9 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
bool _accepted = true;
bool _handleScrollNotification(ScrollNotification notification) {
if (!widget.notificationPredicate(notification))
if (!widget.notificationPredicate(notification)) {
return false;
}
if (notification is OverscrollNotification) {
_lastOverscrollNotification = notification;
......@@ -878,13 +887,15 @@ class _StretchController extends ChangeNotifier {
}
void scrollEnd() {
if (_state == _StretchState.pull)
if (_state == _StretchState.pull) {
_recede(_stretchDuration);
}
}
void _changePhase(AnimationStatus status) {
if (status != AnimationStatus.completed)
if (status != AnimationStatus.completed) {
return;
}
switch (_state) {
case _StretchState.absorb:
_recede(_stretchDuration);
......@@ -900,8 +911,9 @@ class _StretchController extends ChangeNotifier {
}
void _recede(Duration duration) {
if (_state == _StretchState.recede || _state == _StretchState.idle)
if (_state == _StretchState.recede || _state == _StretchState.idle) {
return;
}
_stretchSizeTween.begin = _stretchSize.value;
_stretchSizeTween.end = 0.0;
_stretchController.duration = duration;
......
......@@ -33,8 +33,9 @@ class _StorageEntryIdentifier {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is _StorageEntryIdentifier
&& listEquals<PageStorageKey<dynamic>>(other.keys, keys);
}
......@@ -56,8 +57,9 @@ class PageStorageBucket {
static bool _maybeAddKey(BuildContext context, List<PageStorageKey<dynamic>> keys) {
final Widget widget = context.widget;
final Key? key = widget.key;
if (key is PageStorageKey)
if (key is PageStorageKey) {
keys.add(key);
}
return widget is! PageStorage;
}
......@@ -91,8 +93,9 @@ class PageStorageBucket {
_storage![identifier] = data;
} else {
final _StorageEntryIdentifier contextIdentifier = _computeIdentifier(context);
if (contextIdentifier.isNotEmpty)
if (contextIdentifier.isNotEmpty) {
_storage![contextIdentifier] = data;
}
}
}
......@@ -105,10 +108,12 @@ class PageStorageBucket {
/// If an explicit identifier is not provided and no [PageStorageKey]s
/// are found, then null is returned.
dynamic readState(BuildContext context, { Object? identifier }) {
if (_storage == null)
if (_storage == null) {
return null;
if (identifier != null)
}
if (identifier != null) {
return _storage![identifier];
}
final _StorageEntryIdentifier contextIdentifier = _computeIdentifier(context);
return contextIdentifier.isNotEmpty ? _storage![contextIdentifier] : null;
}
......
......@@ -358,12 +358,14 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
double get viewportFraction => _viewportFraction;
double _viewportFraction;
set viewportFraction(double value) {
if (_viewportFraction == value)
if (_viewportFraction == value) {
return;
}
final double? oldPage = page;
_viewportFraction = value;
if (oldPage != null)
if (oldPage != null) {
forcePixels(getPixelsFromPage(oldPage));
}
}
// The amount of offset that will be added to [minScrollExtent] and subtracted
......@@ -408,8 +410,9 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
void restoreScrollOffset() {
if (!hasPixels) {
final double? value = PageStorage.of(context.storageContext)?.readState(context.storageContext) as double?;
if (value != null)
if (value != null) {
_pageToUseOnStartup = value;
}
}
}
......@@ -525,23 +528,26 @@ class PageScrollPhysics extends ScrollPhysics {
}
double _getPage(ScrollMetrics position) {
if (position is _PagePosition)
if (position is _PagePosition) {
return position.page!;
}
return position.pixels / position.viewportDimension;
}
double _getPixels(ScrollMetrics position, double page) {
if (position is _PagePosition)
if (position is _PagePosition) {
return position.getPixelsFromPage(page);
}
return page * position.viewportDimension;
}
double _getTargetPixels(ScrollMetrics position, Tolerance tolerance, double velocity) {
double page = _getPage(position);
if (velocity < -tolerance.velocity)
if (velocity < -tolerance.velocity) {
page -= 0.5;
else if (velocity > tolerance.velocity)
} else if (velocity > tolerance.velocity) {
page += 0.5;
}
return _getPixels(position, page.roundToDouble());
}
......@@ -550,12 +556,14 @@ class PageScrollPhysics extends ScrollPhysics {
// If we're out of range and not headed back in range, defer to the parent
// ballistics, which should put us back in range at a page boundary.
if ((velocity <= 0.0 && position.pixels <= position.minScrollExtent) ||
(velocity >= 0.0 && position.pixels >= position.maxScrollExtent))
(velocity >= 0.0 && position.pixels >= position.maxScrollExtent)) {
return super.createBallisticSimulation(position, velocity);
}
final Tolerance tolerance = this.tolerance;
final double target = _getTargetPixels(position, tolerance, velocity);
if (target != position.pixels)
if (target != position.pixels) {
return ScrollSpringSimulation(spring, position.pixels, target, velocity, tolerance: tolerance);
}
return null;
}
......
......@@ -103,24 +103,27 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
}
void _handleFocusChanged() {
if (widget.focusNode.hasFocus)
if (widget.focusNode.hasFocus) {
_attachKeyboardIfDetached();
else
} else {
_detachKeyboardIfAttached();
}
}
bool _listening = false;
void _attachKeyboardIfDetached() {
if (_listening)
if (_listening) {
return;
}
RawKeyboard.instance.addListener(_handleRawKeyEvent);
_listening = true;
}
void _detachKeyboardIfAttached() {
if (!_listening)
if (!_listening) {
return;
}
RawKeyboard.instance.removeListener(_handleRawKeyEvent);
_listening = false;
}
......
......@@ -707,8 +707,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
overlay.insert(_overlayEntry!);
for (final _ReorderableItemState childItem in _items.values) {
if (childItem == item || !childItem.mounted)
if (childItem == item || !childItem.mounted) {
continue;
}
childItem.updateForGap(_insertIndex!, _dragInfo!.itemExtent, false, _reverse);
}
return _dragInfo;
......@@ -784,8 +785,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
}
void _handleScrollableAutoScrolled() {
if (_dragInfo == null)
if (_dragInfo == null) {
return;
}
_dragUpdateItems();
// Continue scrolling if the drag is still in progress.
_autoScroller?.startAutoScrollIfNecessary(_dragTargetRect);
......@@ -800,8 +802,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
// Find the new index for inserting the item being dragged.
int newIndex = _insertIndex!;
for (final _ReorderableItemState item in _items.values) {
if (item.index == _dragIndex! || !item.mounted)
if (item.index == _dragIndex! || !item.mounted) {
continue;
}
Rect geometry = item.targetGeometry();
if (!_dragStartTransitionComplete && _dragIndex! <= item.index) {
......@@ -862,8 +865,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
if (newIndex != _insertIndex) {
_insertIndex = newIndex;
for (final _ReorderableItemState item in _items.values) {
if (item.index == _dragIndex! || !item.mounted)
if (item.index == _dragIndex! || !item.mounted) {
continue;
}
item.updateForGap(newIndex, gapExtent, true, _reverse);
}
}
......@@ -1386,8 +1390,9 @@ class _ReorderableItemGlobalKey extends GlobalObjectKey {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is _ReorderableItemGlobalKey
&& other.subKey == subKey
&& other.index == index
......
......@@ -739,8 +739,9 @@ mixin RestorationMixin<S extends StatefulWidget> on State<S> {
if (!property.isRegistered) {
property._register(restorationId, this);
void listener() {
if (bucket == null)
if (bucket == null) {
return;
}
_updateProperty(property);
}
property.addListener(listener);
......
......@@ -588,8 +588,9 @@ class _RouterState<T> extends State<Router<T>> with RestorationMixin {
bool _routeInformationReportingTaskScheduled = false;
void _scheduleRouteInformationReportingTask() {
if (_routeInformationReportingTaskScheduled || widget.routeInformationProvider == null)
if (_routeInformationReportingTaskScheduled || widget.routeInformationProvider == null) {
return;
}
assert(_currentIntentionToReport != null);
_routeInformationReportingTaskScheduled = true;
SchedulerBinding.instance.addPostFrameCallback(_reportRouteInformation);
......@@ -609,8 +610,9 @@ class _RouterState<T> extends State<Router<T>> with RestorationMixin {
RouteInformation? _retrieveNewRouteInformation() {
final T? configuration = widget.routerDelegate.currentConfiguration;
if (configuration == null)
if (configuration == null) {
return null;
}
return widget.routeInformationParser?.restoreRouteInformation(configuration);
}
......@@ -848,8 +850,9 @@ class _CallbackHookProvider<T> {
@protected
@pragma('vm:notify-debugger-on-exception')
T invokeCallback(T defaultValue) {
if (_callbacks.isEmpty)
if (_callbacks.isEmpty) {
return defaultValue;
}
try {
return _callbacks.single();
} catch (exception, stack) {
......@@ -917,8 +920,9 @@ abstract class BackButtonDispatcher extends _CallbackHookProvider<Future<bool>>
Future<bool> notifyNextChild(bool result) {
// If the previous child handles the callback, we return the result.
if (result)
if (result) {
return SynchronousFuture<bool>(result);
}
// If the previous child did not handle the callback, we ask the next
// child to handle the it.
if (childIndex > 0) {
......@@ -1015,16 +1019,18 @@ class RootBackButtonDispatcher extends BackButtonDispatcher with WidgetsBindingO
@override
void addCallback(ValueGetter<Future<bool>> callback) {
if (!hasCallbacks)
if (!hasCallbacks) {
WidgetsBinding.instance.addObserver(this);
}
super.addCallback(callback);
}
@override
void removeCallback(ValueGetter<Future<bool>> callback) {
super.removeCallback(callback);
if (!hasCallbacks)
if (!hasCallbacks) {
WidgetsBinding.instance.removeObserver(this);
}
}
@override
......@@ -1080,8 +1086,9 @@ class ChildBackButtonDispatcher extends BackButtonDispatcher {
@override
void removeCallback(ValueGetter<Future<bool>> callback) {
super.removeCallback(callback);
if (!hasCallbacks)
if (!hasCallbacks) {
parent.forget(this);
}
}
}
......@@ -1448,8 +1455,9 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
RouteInformation _valueInEngine = RouteInformation(location: WidgetsBinding.instance.platformDispatcher.defaultRouteName);
void _platformReportsNewRouteInformation(RouteInformation routeInformation) {
if (_value == routeInformation)
if (_value == routeInformation) {
return;
}
_value = routeInformation;
_valueInEngine = routeInformation;
notifyListeners();
......@@ -1457,16 +1465,18 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
@override
void addListener(VoidCallback listener) {
if (!hasListeners)
if (!hasListeners) {
WidgetsBinding.instance.addObserver(this);
}
super.addListener(listener);
}
@override
void removeListener(VoidCallback listener) {
super.removeListener(listener);
if (!hasListeners)
if (!hasListeners) {
WidgetsBinding.instance.removeObserver(this);
}
}
@override
......@@ -1475,8 +1485,9 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
// will be added and removed in a coherent fashion such that when the object
// is no longer being used, there's no listener, and so it will get garbage
// collected.
if (hasListeners)
if (hasListeners) {
WidgetsBinding.instance.removeObserver(this);
}
super.dispose();
}
......@@ -1513,8 +1524,9 @@ mixin PopNavigatorRouterDelegateMixin<T> on RouterDelegate<T> {
@override
Future<bool> popRoute() {
final NavigatorState? navigator = navigatorKey?.currentState;
if (navigator == null)
if (navigator == null) {
return SynchronousFuture<bool>(false);
}
return navigator.maybePop();
}
}
......
......@@ -71,8 +71,9 @@ abstract class OverlayRoute<T> extends Route<T> {
bool didPop(T? result) {
final bool returnValue = super.didPop(result);
assert(returnValue);
if (finishedWhenPopped)
if (finishedWhenPopped) {
navigator!.finalizeRoute(this);
}
return returnValue;
}
......@@ -194,13 +195,15 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
void _handleStatusChanged(AnimationStatus status) {
switch (status) {
case AnimationStatus.completed:
if (overlayEntries.isNotEmpty)
if (overlayEntries.isNotEmpty) {
overlayEntries.first.opaque = opaque;
}
break;
case AnimationStatus.forward:
case AnimationStatus.reverse:
if (overlayEntries.isNotEmpty)
if (overlayEntries.isNotEmpty) {
overlayEntries.first.opaque = false;
}
break;
case AnimationStatus.dismissed:
// We might still be an active route if a subclass is controlling the
......@@ -249,8 +252,9 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
void didReplace(Route<dynamic>? oldRoute) {
assert(_controller != null, '$runtimeType.didReplace called before calling install() or after calling dispose().');
assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.');
if (oldRoute is TransitionRoute)
if (oldRoute is TransitionRoute) {
_controller!.value = oldRoute._controller!.value;
}
super.didReplace(oldRoute);
}
......@@ -633,8 +637,9 @@ mixin LocalHistoryRoute<T> on Route<T> {
internalStateChanged = _entriesImpliesAppBarDismissal == 0;
_entriesImpliesAppBarDismissal += 1;
}
if (wasEmpty || internalStateChanged)
if (wasEmpty || internalStateChanged) {
changedInternalState();
}
}
/// Remove a local history entry from this route.
......@@ -669,8 +674,9 @@ mixin LocalHistoryRoute<T> on Route<T> {
@override
Future<RoutePopDisposition> willPop() async {
if (willHandlePopInternally)
if (willHandlePopInternally) {
return RoutePopDisposition.pop;
}
return super.willPop();
}
......@@ -686,8 +692,9 @@ mixin LocalHistoryRoute<T> on Route<T> {
_entriesImpliesAppBarDismissal -= 1;
internalStateChanged = _entriesImpliesAppBarDismissal == 0;
}
if (_localHistory!.isEmpty || internalStateChanged)
if (_localHistory!.isEmpty || internalStateChanged) {
changedInternalState();
}
return false;
}
return super.didPop(result);
......@@ -1387,8 +1394,9 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
bool get offstage => _offstage;
bool _offstage = false;
set offstage(bool value) {
if (_offstage == value)
if (_offstage == value) {
return;
}
setState(() {
_offstage = value;
});
......@@ -1433,8 +1441,9 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
final _ModalScopeState<T>? scope = _scopeKey.currentState;
assert(scope != null);
for (final WillPopCallback callback in List<WillPopCallback>.of(_willPopCallbacks)) {
if (await callback() != true)
if (await callback() != true) {
return RoutePopDisposition.doNotPop;
}
}
return super.willPop();
}
......@@ -1575,8 +1584,9 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
void changedExternalState() {
super.changedExternalState();
_modalBarrier.markNeedsBuild();
if (_scopeKey.currentState != null)
if (_scopeKey.currentState != null) {
_scopeKey.currentState!._forceRebuildPage();
}
}
/// Whether this route can be popped.
......@@ -1975,6 +1985,7 @@ class RawDialogRoute<T> extends PopupRoute<T> {
@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
if (_transitionBuilder == null) {
// Some default transition.
return FadeTransition(
opacity: CurvedAnimation(
parent: animation,
......@@ -1982,7 +1993,7 @@ class RawDialogRoute<T> extends PopupRoute<T> {
),
child: child,
);
} // Some default transition
}
return _transitionBuilder!(context, animation, secondaryAnimation, child);
}
}
......@@ -2138,8 +2149,9 @@ class FocusTrap extends SingleChildRenderObjectWidget {
@override
void updateRenderObject(BuildContext context, RenderObject renderObject) {
if (renderObject is _RenderFocusTrap)
if (renderObject is _RenderFocusTrap) {
renderObject.focusScopeNode = focusScopeNode;
}
}
}
......@@ -2170,8 +2182,9 @@ class FocusTrapArea extends SingleChildRenderObjectWidget {
@override
void updateRenderObject(BuildContext context, RenderObject renderObject) {
if (renderObject is _RenderFocusTrapArea)
if (renderObject is _RenderFocusTrapArea) {
renderObject.focusNode = focusNode;
}
}
}
......@@ -2191,8 +2204,9 @@ class _RenderFocusTrap extends RenderProxyBoxWithHitTestBehavior {
FocusNode? _previousFocus;
FocusScopeNode get focusScopeNode => _focusScopeNode;
set focusScopeNode(FocusScopeNode value) {
if (focusScopeNode == value)
if (focusScopeNode == value) {
return;
}
_focusScopeNode = value;
}
......@@ -2249,12 +2263,14 @@ class _RenderFocusTrap extends RenderProxyBoxWithHitTestBehavior {
}
final BoxHitTestResult? result = cachedResults[entry];
final FocusNode? focusNode = _focusScopeNode.focusedChild;
if (focusNode == null || result == null)
if (focusNode == null || result == null) {
return;
}
final RenderObject? renderObject = focusNode.context?.findRenderObject();
if (renderObject == null)
if (renderObject == null) {
return;
}
bool hitCurrentFocus = false;
for (final HitTestEntry entry in result.path) {
......
......@@ -96,8 +96,9 @@ class SafeArea extends StatelessWidget {
final MediaQueryData data = MediaQuery.of(context);
EdgeInsets padding = data.padding;
// Bottom padding has been consumed - i.e. by the keyboard
if (maintainBottomViewPadding)
if (maintainBottomViewPadding) {
padding = padding.copyWith(bottom: data.viewPadding.bottom);
}
return Padding(
padding: EdgeInsets.only(
......
......@@ -382,8 +382,9 @@ class ScrollDragController implements Drag {
if (offset == 0.0) {
return;
}
if (_reversed) // e.g. an AxisDirection.up scrollable
if (_reversed) {
offset = -offset;
}
delegate.applyUserOffset(offset);
}
......@@ -394,8 +395,9 @@ class ScrollDragController implements Drag {
// the scroll has to move upwards. It's the same reason that update()
// above negates the delta before applying it to the scroll offset.
double velocity = -details.primaryVelocity!;
if (_reversed) // e.g. an AxisDirection.up scrollable
if (_reversed) {
velocity = -velocity;
}
_lastDetails = details;
if (_retainMomentum) {
......@@ -549,8 +551,9 @@ class BallisticScrollActivity extends ScrollActivity {
}
void _tick() {
if (!applyMoveTo(_controller.value))
if (!applyMoveTo(_controller.value)) {
delegate.goIdle();
}
}
/// Move the position to the given location.
......@@ -643,8 +646,9 @@ class DrivenScrollActivity extends ScrollActivity {
Future<void> get done => _completer.future;
void _tick() {
if (delegate.setPixels(_controller.value) != 0.0)
if (delegate.setPixels(_controller.value) != 0.0) {
delegate.goIdle();
}
}
void _end() {
......
......@@ -295,15 +295,17 @@ class _WrappedScrollBehavior implements ScrollBehavior {
@override
Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
if (overscroll)
if (overscroll) {
return delegate.buildOverscrollIndicator(context, child, details);
}
return child;
}
@override
Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
if (scrollbars)
if (scrollbars) {
return delegate.buildScrollbar(context, child, details);
}
return child;
}
......
......@@ -168,8 +168,9 @@ class ScrollController extends ChangeNotifier {
/// value was out of range.
void jumpTo(double value) {
assert(_positions.isNotEmpty, 'ScrollController not attached to any scroll views.');
for (final ScrollPosition position in List<ScrollPosition>.of(_positions))
for (final ScrollPosition position in List<ScrollPosition>.of(_positions)) {
position.jumpTo(value);
}
}
/// Register the given position with this controller.
......@@ -194,8 +195,9 @@ class ScrollController extends ChangeNotifier {
@override
void dispose() {
for (final ScrollPosition position in _positions)
for (final ScrollPosition position in _positions) {
position.removeListener(notifyListeners);
}
super.dispose();
}
......@@ -258,10 +260,12 @@ class ScrollController extends ChangeNotifier {
/// method, as in `super.debugFillDescription(description)`.
@mustCallSuper
void debugFillDescription(List<String> description) {
if (debugLabel != null)
if (debugLabel != null) {
description.add(debugLabel!);
if (initialScrollOffset != 0.0)
}
if (initialScrollOffset != 0.0) {
description.add('initialScrollOffset: ${initialScrollOffset.toStringAsFixed(1)}, ');
}
if (_positions.isEmpty) {
description.add('no clients');
} else if (_positions.length == 1) {
......@@ -357,10 +361,12 @@ class TrackingScrollController extends ScrollController {
assert(_positionToListener.containsKey(position));
position.removeListener(_positionToListener[position]!);
_positionToListener.remove(position);
if (_lastUpdated == position)
if (_lastUpdated == position) {
_lastUpdated = null;
if (_positionToListener.isEmpty)
}
if (_positionToListener.isEmpty) {
_lastUpdatedOffset = null;
}
}
@override
......
......@@ -132,8 +132,9 @@ class ScrollStartNotification extends ScrollNotification {
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
if (dragDetails != null)
if (dragDetails != null) {
description.add('$dragDetails');
}
}
}
......@@ -173,8 +174,9 @@ class ScrollUpdateNotification extends ScrollNotification {
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('scrollDelta: $scrollDelta');
if (dragDetails != null)
if (dragDetails != null) {
description.add('$dragDetails');
}
}
}
......@@ -226,8 +228,9 @@ class OverscrollNotification extends ScrollNotification {
super.debugFillDescription(description);
description.add('overscroll: ${overscroll.toStringAsFixed(1)}');
description.add('velocity: ${velocity.toStringAsFixed(1)}');
if (dragDetails != null)
if (dragDetails != null) {
description.add('$dragDetails');
}
}
}
......@@ -261,8 +264,9 @@ class ScrollEndNotification extends ScrollNotification {
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
if (dragDetails != null)
if (dragDetails != null) {
description.add('$dragDetails');
}
}
}
......
......@@ -124,14 +124,16 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
void _notifyListeners(ScrollNotification notification) {
assert(_debugAssertNotDisposed());
if (_listeners!.isEmpty)
if (_listeners!.isEmpty) {
return;
}
final List<_ListenerEntry> localListeners = List<_ListenerEntry>.of(_listeners!);
for (final _ListenerEntry entry in localListeners) {
try {
if (entry.list != null)
if (entry.list != null) {
entry.listener(notification);
}
} catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
......
......@@ -158,8 +158,9 @@ class ScrollPhysics {
/// reference to it to use later, as the values may update, may not update, or
/// may update to reflect an entirely unrelated scrollable.
double applyPhysicsToUserOffset(ScrollMetrics position, double offset) {
if (parent == null)
if (parent == null) {
return offset;
}
return parent!.applyPhysicsToUserOffset(position, offset);
}
......@@ -173,8 +174,9 @@ class ScrollPhysics {
/// reference to it to use later, as the values may update, may not update, or
/// may update to reflect an entirely unrelated scrollable.
bool shouldAcceptUserOffset(ScrollMetrics position) {
if (parent == null)
if (parent == null) {
return position.pixels != 0.0 || position.minScrollExtent != position.maxScrollExtent;
}
return parent!.shouldAcceptUserOffset(position);
}
......@@ -265,8 +267,9 @@ class ScrollPhysics {
/// scrolling back from being overscrolled, if for some reason the position
/// ends up overscrolled.
double applyBoundaryConditions(ScrollMetrics position, double value) {
if (parent == null)
if (parent == null) {
return 0.0;
}
return parent!.applyBoundaryConditions(position, value);
}
......@@ -320,8 +323,9 @@ class ScrollPhysics {
required bool isScrolling,
required double velocity,
}) {
if (parent == null)
if (parent == null) {
return newPosition.pixels;
}
return parent!.adjustPositionForNewDimensions(oldPosition: oldPosition, newPosition: newPosition, isScrolling: isScrolling, velocity: velocity);
}
......@@ -338,8 +342,9 @@ class ScrollPhysics {
/// reference to it to use later, as the values may update, may not update, or
/// may update to reflect an entirely unrelated scrollable.
Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) {
if (parent == null)
if (parent == null) {
return null;
}
return parent!.createBallisticSimulation(position, velocity);
}
......@@ -397,8 +402,9 @@ class ScrollPhysics {
///
/// By default, physics for platforms other than iOS doesn't carry momentum.
double carriedMomentum(double existingVelocity) {
if (parent == null)
if (parent == null) {
return 0.0;
}
return parent!.carriedMomentum(existingVelocity);
}
......@@ -419,8 +425,9 @@ class ScrollPhysics {
@override
String toString() {
if (parent == null)
if (parent == null) {
return objectRuntimeType(this, 'ScrollPhysics');
}
return '${objectRuntimeType(this, 'ScrollPhysics')} -> $parent';
}
}
......@@ -609,8 +616,9 @@ class BouncingScrollPhysics extends ScrollPhysics {
assert(offset != 0.0);
assert(position.minScrollExtent <= position.maxScrollExtent);
if (!position.outOfRange)
if (!position.outOfRange) {
return offset;
}
final double overscrollPastStart = math.max(position.minScrollExtent - position.pixels, 0.0);
final double overscrollPastEnd = math.max(position.pixels - position.maxScrollExtent, 0.0);
......@@ -632,8 +640,9 @@ class BouncingScrollPhysics extends ScrollPhysics {
double total = 0.0;
if (extentOutside > 0) {
final double deltaToLimit = extentOutside / gamma;
if (absDelta < deltaToLimit)
if (absDelta < deltaToLimit) {
return absDelta * gamma;
}
total += extentOutside;
absDelta -= deltaToLimit;
}
......@@ -734,14 +743,22 @@ class ClampingScrollPhysics extends ScrollPhysics {
}
return true;
}());
if (value < position.pixels && position.pixels <= position.minScrollExtent) // underscroll
if (value < position.pixels && position.pixels <= position.minScrollExtent) {
// Underscroll.
return value - position.pixels;
if (position.maxScrollExtent <= position.pixels && position.pixels < value) // overscroll
}
if (position.maxScrollExtent <= position.pixels && position.pixels < value) {
// Overscroll.
return value - position.pixels;
if (value < position.minScrollExtent && position.minScrollExtent < position.pixels) // hit top edge
}
if (value < position.minScrollExtent && position.minScrollExtent < position.pixels) {
// Hit top edge.
return value - position.minScrollExtent;
if (position.pixels < position.maxScrollExtent && position.maxScrollExtent < value) // hit bottom edge
}
if (position.pixels < position.maxScrollExtent && position.maxScrollExtent < value) {
// Hit bottom edge.
return value - position.maxScrollExtent;
}
return 0.0;
}
......@@ -750,10 +767,12 @@ class ClampingScrollPhysics extends ScrollPhysics {
final Tolerance tolerance = this.tolerance;
if (position.outOfRange) {
double? end;
if (position.pixels > position.maxScrollExtent)
if (position.pixels > position.maxScrollExtent) {
end = position.maxScrollExtent;
if (position.pixels < position.minScrollExtent)
}
if (position.pixels < position.minScrollExtent) {
end = position.minScrollExtent;
}
assert(end != null);
return ScrollSpringSimulation(
spring,
......@@ -763,12 +782,15 @@ class ClampingScrollPhysics extends ScrollPhysics {
tolerance: tolerance,
);
}
if (velocity.abs() < tolerance.velocity)
if (velocity.abs() < tolerance.velocity) {
return null;
if (velocity > 0.0 && position.pixels >= position.maxScrollExtent)
}
if (velocity > 0.0 && position.pixels >= position.maxScrollExtent) {
return null;
if (velocity < 0.0 && position.pixels <= position.minScrollExtent)
}
if (velocity < 0.0 && position.pixels <= position.minScrollExtent) {
return null;
}
return ClampingScrollSimulation(
position: position.pixels,
velocity: velocity,
......
......@@ -102,10 +102,12 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
assert(context != null),
assert(context.vsync != null),
assert(keepScrollOffset != null) {
if (oldPosition != null)
if (oldPosition != null) {
absorb(oldPosition);
if (keepScrollOffset)
}
if (keepScrollOffset) {
restoreScrollOffset();
}
}
/// How the scroll position should respond to user input.
......@@ -233,8 +235,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
assert(other.activity != null);
_activity = other.activity;
other._activity = null;
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
activity!.resetActivity();
}
context.setIgnorePointer(activity!.shouldIgnorePointer);
isScrollingNotifier.value = activity!.isScrolling;
}
......@@ -422,8 +425,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
void restoreScrollOffset() {
if (!hasPixels) {
final double? value = PageStorage.of(context.storageContext)?.readState(context.storageContext) as double?;
if (value != null)
if (value != null) {
correctPixels(value);
}
}
}
......@@ -661,13 +665,16 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
}
final Set<SemanticsAction> actions = <SemanticsAction>{};
if (pixels > minScrollExtent)
if (pixels > minScrollExtent) {
actions.add(backward);
if (pixels < maxScrollExtent)
}
if (pixels < maxScrollExtent) {
actions.add(forward);
}
if (setEquals<SemanticsAction>(actions, _semanticActions))
if (setEquals<SemanticsAction>(actions, _semanticActions)) {
return;
}
_semanticActions = actions;
context.setSemanticsActions(_semanticActions!);
......@@ -726,8 +733,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
break;
}
if (target == pixels)
if (target == pixels) {
return Future<void>.value();
}
if (duration == Duration.zero) {
jumpTo(target);
......@@ -823,8 +831,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
assert(to != null);
assert(clamp != null);
if (clamp!)
if (clamp!) {
to = clampDouble(to, minScrollExtent, maxScrollExtent);
}
return super.moveTo(to, duration: duration, curve: curve);
}
......@@ -866,25 +875,30 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
/// method might return null, since it means the caller does not have to
/// explicitly null-check the argument.
void beginActivity(ScrollActivity? newActivity) {
if (newActivity == null)
if (newActivity == null) {
return;
}
bool wasScrolling, oldIgnorePointer;
if (_activity != null) {
oldIgnorePointer = _activity!.shouldIgnorePointer;
wasScrolling = _activity!.isScrolling;
if (wasScrolling && !newActivity.isScrolling)
didEndScroll(); // notifies and then saves the scroll offset
if (wasScrolling && !newActivity.isScrolling) {
// Notifies and then saves the scroll offset.
didEndScroll();
}
_activity!.dispose();
} else {
oldIgnorePointer = false;
wasScrolling = false;
}
_activity = newActivity;
if (oldIgnorePointer != activity!.shouldIgnorePointer)
if (oldIgnorePointer != activity!.shouldIgnorePointer) {
context.setIgnorePointer(activity!.shouldIgnorePointer);
}
isScrollingNotifier.value = activity!.isScrolling;
if (!wasScrolling && _activity!.isScrolling)
if (!wasScrolling && _activity!.isScrolling) {
didStartScroll();
}
}
......@@ -906,8 +920,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
void didEndScroll() {
activity!.dispatchScrollEndNotification(copyWith(), context.notificationContext!);
saveOffset();
if (keepScrollOffset)
if (keepScrollOffset) {
saveScrollOffset();
}
}
/// Called by [setPixels] to report overscroll when an attempt is made to
......@@ -930,8 +945,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
assert(SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks);
assert(_haveScheduledUpdateNotification);
_haveScheduledUpdateNotification = false;
if (context.notificationContext != null)
if (context.notificationContext != null) {
ScrollMetricsNotification(metrics: copyWith(), context: context.notificationContext!).dispatch(context.notificationContext);
}
}
/// Provides a heuristic to determine if expensive frame-bound tasks should be
......@@ -971,8 +987,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
@override
void debugFillDescription(List<String> description) {
if (debugLabel != null)
if (debugLabel != null) {
description.add(debugLabel!);
}
super.debugFillDescription(description);
description.add('range: ${_minScrollExtent?.toStringAsFixed(1)}..${_maxScrollExtent?.toStringAsFixed(1)}');
description.add('viewport: ${_viewportDimension?.toStringAsFixed(1)}');
......
......@@ -56,10 +56,12 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
}) {
// If oldPosition is not null, the superclass will first call absorb(),
// which may set _pixels and _activity.
if (!hasPixels && initialPixels != null)
if (!hasPixels && initialPixels != null) {
correctPixels(initialPixels);
if (activity == null)
}
if (activity == null) {
goIdle();
}
assert(activity != null);
}
......@@ -102,14 +104,16 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
@override
void beginActivity(ScrollActivity? newActivity) {
_heldPreviousVelocity = 0.0;
if (newActivity == null)
if (newActivity == null) {
return;
}
assert(newActivity.delegate == this);
super.beginActivity(newActivity);
_currentDrag?.dispose();
_currentDrag = null;
if (!activity!.isScrolling)
if (!activity!.isScrolling) {
updateUserScrollDirection(ScrollDirection.idle);
}
}
@override
......@@ -154,8 +158,9 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
@visibleForTesting
void updateUserScrollDirection(ScrollDirection value) {
assert(value != null);
if (userScrollDirection == value)
if (userScrollDirection == value) {
return;
}
_userScrollDirection = value;
didUpdateScrollDirection(value);
}
......
......@@ -656,8 +656,9 @@ abstract class BoxScrollView extends ScrollView {
}
}
if (effectivePadding != null)
if (effectivePadding != null) {
sliver = SliverPadding(padding: effectivePadding, sliver: sliver);
}
return <Widget>[ sliver ];
}
......
......@@ -107,8 +107,9 @@ class _SelectionContainerState extends State<SelectionContainer> with Selectable
super.initState();
if (!widget._disabled) {
widget.delegate!._selectionContainerContext = context;
if (widget.registrar != null)
if (widget.registrar != null) {
registrar = widget.registrar;
}
}
}
......@@ -180,8 +181,9 @@ class _SelectionContainerState extends State<SelectionContainer> with Selectable
@override
SelectionGeometry get value {
if (widget._disabled)
if (widget._disabled) {
return _disabledGeometry;
}
return widget.delegate!.value;
}
......
......@@ -122,8 +122,9 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
void _handlePanEnd(DragEndDetails details) {
final double vx = details.velocity.pixelsPerSecond.dx;
final double vy = details.velocity.pixelsPerSecond.dy;
if (vx.abs() == vy.abs())
if (vx.abs() == vy.abs()) {
return;
}
if (vx.abs() > vy.abs()) {
if (vx.sign < 0) {
_performAction(_lastPointerDownLocation!, SemanticsAction.decrease);
......@@ -133,10 +134,11 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
_performAction(_lastPointerDownLocation!, SemanticsAction.scrollRight);
}
} else {
if (vy.sign < 0)
if (vy.sign < 0) {
_performAction(_lastPointerDownLocation!, SemanticsAction.scrollUp);
else
} else {
_performAction(_lastPointerDownLocation!, SemanticsAction.scrollDown);
}
}
setState(() {
_lastPointerDownLocation = null;
......@@ -222,8 +224,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
final SemanticsNode? rootNode = _rootSemanticsNode;
canvas.save();
canvas.scale(1.0 / devicePixelRatio, 1.0 / devicePixelRatio);
if (rootNode != null)
if (rootNode != null) {
_paint(canvas, rootNode, _findDepth(rootNode));
}
if (pointerPosition != null) {
final Paint paint = Paint();
paint.color = const Color(0x7F0090FF);
......@@ -255,15 +258,18 @@ class _SemanticsDebuggerPainter extends CustomPainter {
}
if (data.hasAction(SemanticsAction.tap)) {
if (!wantsTap)
if (!wantsTap) {
annotations.add('button');
}
} else {
if (wantsTap)
if (wantsTap) {
annotations.add('disabled');
}
}
if (data.hasAction(SemanticsAction.longPress))
if (data.hasAction(SemanticsAction.longPress)) {
annotations.add('long-pressable');
}
final bool isScrollable = data.hasAction(SemanticsAction.scrollLeft)
|| data.hasAction(SemanticsAction.scrollRight)
......@@ -273,11 +279,13 @@ class _SemanticsDebuggerPainter extends CustomPainter {
final bool isAdjustable = data.hasAction(SemanticsAction.increase)
|| data.hasAction(SemanticsAction.decrease);
if (isScrollable)
if (isScrollable) {
annotations.add('scrollable');
}
if (isAdjustable)
if (isAdjustable) {
annotations.add('adjustable');
}
assert(data.attributedLabel != null);
final String message;
......@@ -316,8 +324,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
void _paintMessage(Canvas canvas, SemanticsNode node) {
final String message = getMessage(node);
if (message.isEmpty)
if (message.isEmpty) {
return;
}
final Rect rect = node.rect;
canvas.save();
canvas.clipRect(rect);
......@@ -335,8 +344,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
}
int _findDepth(SemanticsNode node) {
if (!node.hasChildren || node.mergeAllDescendantsIntoThisNode)
if (!node.hasChildren || node.mergeAllDescendantsIntoThisNode) {
return 1;
}
int childrenDepth = 0;
node.visitChildren((SemanticsNode child) {
childrenDepth = math.max(childrenDepth, _findDepth(child));
......@@ -347,8 +357,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
void _paint(Canvas canvas, SemanticsNode node, int rank) {
canvas.save();
if (node.transform != null)
if (node.transform != null) {
canvas.transform(node.transform!.storage);
}
final Rect rect = node.rect;
if (!rect.isEmpty) {
final Color lineColor = Color(0xFF000000 + math.Random(node.id).nextInt(0xFFFFFF));
......
......@@ -285,8 +285,9 @@ class LogicalKeySet extends KeySet<LogicalKeyboardKey> with Diagnosticable
@override
bool accepts(RawKeyEvent event, RawKeyboard state) {
if (event is! RawKeyDownEvent)
if (event is! RawKeyDownEvent) {
return false;
}
final Set<LogicalKeyboardKey> collapsedRequired = LogicalKeyboardKey.collapseSynonyms(keys);
final Set<LogicalKeyboardKey> collapsedPressed = LogicalKeyboardKey.collapseSynonyms(state.keysPressed);
final bool keysEqual = collapsedRequired.difference(collapsedPressed).isEmpty
......
......@@ -91,8 +91,9 @@ class _RenderSizeChangedWithCallback extends RenderProxyBox {
super.performLayout();
// Don't send the initial notification, or this will be SizeObserver all
// over again!
if (_oldSize != null && size != _oldSize)
if (_oldSize != null && size != _oldSize) {
onLayoutChangedCallback();
}
_oldSize = size;
}
}
......@@ -67,8 +67,9 @@ class _RenderSliverLayoutBuilder extends RenderSliver with RenderObjectWithChild
@override
void paint(PaintingContext context, Offset offset) {
// This renderObject does not introduce additional offset to child's position.
if (child?.geometry?.visible ?? false)
if (child?.geometry?.visible ?? false) {
context.paintChild(child!, offset);
}
}
@override
......
This diff is collapsed.
......@@ -539,10 +539,12 @@ class Text extends StatelessWidget {
Widget build(BuildContext context) {
final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
TextStyle? effectiveTextStyle = style;
if (style == null || style!.inherit)
if (style == null || style!.inherit) {
effectiveTextStyle = defaultTextStyle.style.merge(style);
if (MediaQuery.boldTextOverride(context))
}
if (MediaQuery.boldTextOverride(context)) {
effectiveTextStyle = effectiveTextStyle!.merge(const TextStyle(fontWeight: FontWeight.bold));
}
final SelectionRegistrar? registrar = SelectionContainer.maybeOf(context);
Widget result = RichText(
textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
......
......@@ -56,8 +56,9 @@ List<Widget> generateList(Widget child, { required bool impliedMode }) {
key: GlobalObjectKey<_LeafState>(index),
child: child,
);
if (impliedMode)
if (impliedMode) {
return result;
}
return AutomaticKeepAlive(child: result);
},
growable: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment