Commit d05d3610 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Enforce didUpdateWidget() @mustCallSuper (#9421)

parent 2480c4d4
...@@ -49,6 +49,7 @@ class _CupertinoActivityIndicatorState extends State<CupertinoActivityIndicator> ...@@ -49,6 +49,7 @@ class _CupertinoActivityIndicatorState extends State<CupertinoActivityIndicator>
@override @override
void didUpdateWidget(CupertinoActivityIndicator oldWidget) { void didUpdateWidget(CupertinoActivityIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.animating != oldWidget.animating) { if (widget.animating != oldWidget.animating) {
if (widget.animating) if (widget.animating)
_controller.repeat(); _controller.repeat();
......
...@@ -291,6 +291,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -291,6 +291,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
@override @override
void didUpdateWidget(BottomNavigationBar oldWidget) { void didUpdateWidget(BottomNavigationBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.currentIndex != oldWidget.currentIndex) { if (widget.currentIndex != oldWidget.currentIndex) {
if (widget.type == BottomNavigationBarType.shifting) if (widget.type == BottomNavigationBarType.shifting)
_pushCircle(widget.currentIndex); _pushCircle(widget.currentIndex);
......
...@@ -372,6 +372,7 @@ class _MonthPickerState extends State<MonthPicker> { ...@@ -372,6 +372,7 @@ class _MonthPickerState extends State<MonthPicker> {
@override @override
void didUpdateWidget(MonthPicker oldWidget) { void didUpdateWidget(MonthPicker oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.selectedDate != oldWidget.selectedDate) { if (widget.selectedDate != oldWidget.selectedDate) {
_dayPickerController = new PageController(initialPage: _monthDelta(widget.firstDate, widget.selectedDate)); _dayPickerController = new PageController(initialPage: _monthDelta(widget.firstDate, widget.selectedDate));
_currentDisplayedMonthDate = _currentDisplayedMonthDate =
......
...@@ -480,6 +480,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> { ...@@ -480,6 +480,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> {
@override @override
void didUpdateWidget(DropdownButton<T> oldWidget) { void didUpdateWidget(DropdownButton<T> oldWidget) {
super.didUpdateWidget(oldWidget);
_updateSelectedIndex(); _updateSelectedIndex();
} }
......
...@@ -84,6 +84,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM ...@@ -84,6 +84,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
@override @override
void didUpdateWidget(ExpandIcon oldWidget) { void didUpdateWidget(ExpandIcon oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isExpanded != oldWidget.isExpanded) { if (widget.isExpanded != oldWidget.isExpanded) {
if (widget.isExpanded) { if (widget.isExpanded) {
_controller.forward(); _controller.forward();
......
...@@ -196,6 +196,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr ...@@ -196,6 +196,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
@override @override
void didUpdateWidget(_FloatingActionButtonTransition oldWidget) { void didUpdateWidget(_FloatingActionButtonTransition oldWidget) {
super.didUpdateWidget(oldWidget);
final bool oldChildIsNull = oldWidget.child == null; final bool oldChildIsNull = oldWidget.child == null;
final bool newChildIsNull = widget.child == null; final bool newChildIsNull = widget.child == null;
if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key) if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key)
......
...@@ -183,6 +183,7 @@ class _TextFieldState extends State<TextField> { ...@@ -183,6 +183,7 @@ class _TextFieldState extends State<TextField> {
@override @override
void didUpdateWidget(TextField oldWidget) { void didUpdateWidget(TextField oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller == null && oldWidget.controller != null) if (widget.controller == null && oldWidget.controller != null)
_controller == new TextEditingController.fromValue(oldWidget.controller.value); _controller == new TextEditingController.fromValue(oldWidget.controller.value);
else if (widget.controller != null && oldWidget.controller == null) else if (widget.controller != null && oldWidget.controller == null)
......
...@@ -479,6 +479,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -479,6 +479,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
@override @override
void didUpdateWidget(_Dial oldWidget) { void didUpdateWidget(_Dial oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.mode != oldWidget.mode && !_dragging) if (widget.mode != oldWidget.mode && !_dragging)
_animateTo(_getThetaForTime(widget.selectedTime)); _animateTo(_getThetaForTime(widget.selectedTime));
} }
......
...@@ -107,6 +107,7 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> { ...@@ -107,6 +107,7 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> {
@override @override
void didUpdateWidget(StreamBuilderBase<T, S> oldWidget) { void didUpdateWidget(StreamBuilderBase<T, S> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.stream != widget.stream) { if (oldWidget.stream != widget.stream) {
if (_subscription != null) { if (_subscription != null) {
_unsubscribe(); _unsubscribe();
...@@ -419,6 +420,7 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> { ...@@ -419,6 +420,7 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
@override @override
void didUpdateWidget(FutureBuilder<T> oldWidget) { void didUpdateWidget(FutureBuilder<T> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.future != widget.future) { if (oldWidget.future != widget.future) {
if (_activeCallbackIdentity != null) { if (_activeCallbackIdentity != null) {
_unsubscribe(); _unsubscribe();
......
...@@ -236,6 +236,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient { ...@@ -236,6 +236,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
@override @override
void didUpdateWidget(EditableText oldWidget) { void didUpdateWidget(EditableText oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller != oldWidget.controller) { if (widget.controller != oldWidget.controller) {
oldWidget.controller.removeListener(_didChangeTextEditingValue); oldWidget.controller.removeListener(_didChangeTextEditingValue);
widget.controller.addListener(_didChangeTextEditingValue); widget.controller.addListener(_didChangeTextEditingValue);
......
...@@ -831,7 +831,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -831,7 +831,7 @@ abstract class State<T extends StatefulWidget> {
/// ///
/// If you override this, make sure your method starts with a call to /// If you override this, make sure your method starts with a call to
/// super.didUpdateWidget(oldWidget). /// super.didUpdateWidget(oldWidget).
// TODO(abarth): Add @mustCallSuper. @mustCallSuper
@protected @protected
void didUpdateWidget(covariant T oldWidget) { } void didUpdateWidget(covariant T oldWidget) { }
......
...@@ -368,6 +368,7 @@ class RawGestureDetectorState extends State<RawGestureDetector> { ...@@ -368,6 +368,7 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
@override @override
void didUpdateWidget(RawGestureDetector oldWidget) { void didUpdateWidget(RawGestureDetector oldWidget) {
super.didUpdateWidget(oldWidget);
_syncAll(widget.gestures); _syncAll(widget.gestures);
} }
......
...@@ -244,6 +244,7 @@ class _ImageState extends State<Image> { ...@@ -244,6 +244,7 @@ class _ImageState extends State<Image> {
@override @override
void didUpdateWidget(Image oldWidget) { void didUpdateWidget(Image oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.image != oldWidget.image) if (widget.image != oldWidget.image)
_resolveImage(); _resolveImage();
} }
......
...@@ -148,6 +148,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten ...@@ -148,6 +148,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
@override @override
void didUpdateWidget(T oldWidget) { void didUpdateWidget(T oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.curve != oldWidget.curve) if (widget.curve != oldWidget.curve)
_updateCurve(); _updateCurve();
_controller.duration = widget.duration; _controller.duration = widget.duration;
...@@ -229,11 +230,11 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten ...@@ -229,11 +230,11 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
/// The [AnimatedContainer] will automatically animate between the old and /// The [AnimatedContainer] will automatically animate between the old and
/// new values of properties when they change using the provided curve and /// new values of properties when they change using the provided curve and
/// duration. Properties that are null are not animated. /// duration. Properties that are null are not animated.
/// ///
/// This class is useful for generating simple implicit transitions between /// This class is useful for generating simple implicit transitions between
/// different parameters to [Container] with its internal /// different parameters to [Container] with its internal
/// [AnimationController]. For more complex animations, you'll likely want to /// [AnimationController]. For more complex animations, you'll likely want to
/// use a subclass of [Transition] such as the [DecoratedBoxTransition] or use /// use a subclass of [Transition] such as the [DecoratedBoxTransition] or use
/// your own [AnimationController]. /// your own [AnimationController].
class AnimatedContainer extends ImplicitlyAnimatedWidget { class AnimatedContainer extends ImplicitlyAnimatedWidget {
/// Creates a container that animates its parameters implicitly. /// Creates a container that animates its parameters implicitly.
......
...@@ -716,6 +716,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { ...@@ -716,6 +716,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
@override @override
void didUpdateWidget(Navigator oldWidget) { void didUpdateWidget(Navigator oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.observers != widget.observers) { if (oldWidget.observers != widget.observers) {
for (NavigatorObserver observer in oldWidget.observers) for (NavigatorObserver observer in oldWidget.observers)
observer._navigator = null; observer._navigator = null;
......
...@@ -122,6 +122,7 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator> ...@@ -122,6 +122,7 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
@override @override
void didUpdateWidget(GlowingOverscrollIndicator oldWidget) { void didUpdateWidget(GlowingOverscrollIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.color != widget.color || oldWidget.axis != widget.axis) { if (oldWidget.color != widget.color || oldWidget.axis != widget.axis) {
_leadingController.color = widget.color; _leadingController.color = widget.color;
_leadingController.axis = widget.axis; _leadingController.axis = widget.axis;
......
...@@ -60,6 +60,7 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> { ...@@ -60,6 +60,7 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
@override @override
void didUpdateWidget(RawKeyboardListener oldWidget) { void didUpdateWidget(RawKeyboardListener oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.focusNode != oldWidget.focusNode) { if (widget.focusNode != oldWidget.focusNode) {
oldWidget.focusNode.removeListener(_handleFocusChanged); oldWidget.focusNode.removeListener(_handleFocusChanged);
widget.focusNode.addListener(_handleFocusChanged); widget.focusNode.addListener(_handleFocusChanged);
......
...@@ -442,6 +442,7 @@ class _ModalScopeState extends State<_ModalScope> { ...@@ -442,6 +442,7 @@ class _ModalScopeState extends State<_ModalScope> {
@override @override
void didUpdateWidget(_ModalScope oldWidget) { void didUpdateWidget(_ModalScope oldWidget) {
super.didUpdateWidget(oldWidget);
assert(widget.route == oldWidget.route); assert(widget.route == oldWidget.route);
} }
......
...@@ -39,6 +39,7 @@ class _StatusTransitionState extends State<StatusTransitionWidget> { ...@@ -39,6 +39,7 @@ class _StatusTransitionState extends State<StatusTransitionWidget> {
@override @override
void didUpdateWidget(StatusTransitionWidget oldWidget) { void didUpdateWidget(StatusTransitionWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.animation != oldWidget.animation) { if (widget.animation != oldWidget.animation) {
oldWidget.animation.removeStatusListener(_animationStatusChanged); oldWidget.animation.removeStatusListener(_animationStatusChanged);
widget.animation.addStatusListener(_animationStatusChanged); widget.animation.addStatusListener(_animationStatusChanged);
......
...@@ -74,6 +74,7 @@ class _AnimatedState extends State<AnimatedWidget> { ...@@ -74,6 +74,7 @@ class _AnimatedState extends State<AnimatedWidget> {
@override @override
void didUpdateWidget(AnimatedWidget oldWidget) { void didUpdateWidget(AnimatedWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.listenable != oldWidget.listenable) { if (widget.listenable != oldWidget.listenable) {
oldWidget.listenable.removeListener(_handleChange); oldWidget.listenable.removeListener(_handleChange);
widget.listenable.addListener(_handleChange); widget.listenable.addListener(_handleChange);
...@@ -391,20 +392,20 @@ class RelativePositionedTransition extends AnimatedWidget { ...@@ -391,20 +392,20 @@ class RelativePositionedTransition extends AnimatedWidget {
/// Animated version of a [DecoratedBox] that animates the different properties /// Animated version of a [DecoratedBox] that animates the different properties
/// of its [Decoration]. /// of its [Decoration].
/// ///
/// See also: /// See also:
/// ///
/// * [DecoratedBox], which also draws a [Decoration] but is not animated. /// * [DecoratedBox], which also draws a [Decoration] but is not animated.
/// * [AnimatedContainer], a more full-featured container that also animates on /// * [AnimatedContainer], a more full-featured container that also animates on
/// decoration using an internal animation. /// decoration using an internal animation.
class DecoratedBoxTransition extends AnimatedWidget { class DecoratedBoxTransition extends AnimatedWidget {
/// Creates an animated [DecorationBox] whose [Decoration] animation updates /// Creates an animated [DecorationBox] whose [Decoration] animation updates
/// the widget. /// the widget.
/// ///
/// The [decoration] and [position] cannot be null. /// The [decoration] and [position] cannot be null.
/// ///
/// See also: /// See also:
/// ///
/// * [new DecoratedBox]. /// * [new DecoratedBox].
DecoratedBoxTransition({ DecoratedBoxTransition({
Key key, Key key,
......
...@@ -55,6 +55,7 @@ class _WillPopScopeState extends State<WillPopScope> { ...@@ -55,6 +55,7 @@ class _WillPopScopeState extends State<WillPopScope> {
@override @override
void didUpdateWidget(WillPopScope oldWidget) { void didUpdateWidget(WillPopScope oldWidget) {
super.didUpdateWidget(oldWidget);
assert(_route == ModalRoute.of(context)); assert(_route == ModalRoute.of(context));
if (widget.onWillPop != oldWidget.onWillPop && _route != null) { if (widget.onWillPop != oldWidget.onWillPop && _route != null) {
if (oldWidget.onWillPop != null) if (oldWidget.onWillPop != null)
......
...@@ -23,6 +23,7 @@ class ProbeWidgetState extends State<ProbeWidget> { ...@@ -23,6 +23,7 @@ class ProbeWidgetState extends State<ProbeWidget> {
@override @override
void didUpdateWidget(ProbeWidget oldWidget) { void didUpdateWidget(ProbeWidget oldWidget) {
super.didUpdateWidget(oldWidget);
setState(() {}); setState(() {});
} }
......
...@@ -78,6 +78,7 @@ class TriggerableState extends State<TriggerableWidget> { ...@@ -78,6 +78,7 @@ class TriggerableState extends State<TriggerableWidget> {
@override @override
void didUpdateWidget(TriggerableWidget oldWidget) { void didUpdateWidget(TriggerableWidget oldWidget) {
super.didUpdateWidget(oldWidget);
widget.trigger.callback = fire; widget.trigger.callback = fire;
} }
......
...@@ -30,6 +30,7 @@ class TestWidgetState extends State<TestWidget> { ...@@ -30,6 +30,7 @@ class TestWidgetState extends State<TestWidget> {
@override @override
void didUpdateWidget(TestWidget oldWidget) { void didUpdateWidget(TestWidget oldWidget) {
super.didUpdateWidget(oldWidget);
syncedState = widget.syncedState; syncedState = widget.syncedState;
// we explicitly do NOT sync the persistentState from the new instance // we explicitly do NOT sync the persistentState from the new instance
// because we're using that to track whether we got recreated // because we're using that to track whether we got recreated
......
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