Enforce didUpdateWidget() @mustCallSuper (#9421)

This commit is contained in:
Hans Muller 2017-04-17 10:35:00 -07:00 committed by GitHub
parent 2480c4d448
commit d05d36101a
24 changed files with 34 additions and 10 deletions

View file

@ -49,6 +49,7 @@ class _CupertinoActivityIndicatorState extends State<CupertinoActivityIndicator>
@override
void didUpdateWidget(CupertinoActivityIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.animating != oldWidget.animating) {
if (widget.animating)
_controller.repeat();

View file

@ -291,6 +291,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
@override
void didUpdateWidget(BottomNavigationBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.currentIndex != oldWidget.currentIndex) {
if (widget.type == BottomNavigationBarType.shifting)
_pushCircle(widget.currentIndex);

View file

@ -372,6 +372,7 @@ class _MonthPickerState extends State<MonthPicker> {
@override
void didUpdateWidget(MonthPicker oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.selectedDate != oldWidget.selectedDate) {
_dayPickerController = new PageController(initialPage: _monthDelta(widget.firstDate, widget.selectedDate));
_currentDisplayedMonthDate =

View file

@ -480,6 +480,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> {
@override
void didUpdateWidget(DropdownButton<T> oldWidget) {
super.didUpdateWidget(oldWidget);
_updateSelectedIndex();
}

View file

@ -84,6 +84,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
@override
void didUpdateWidget(ExpandIcon oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isExpanded != oldWidget.isExpanded) {
if (widget.isExpanded) {
_controller.forward();

View file

@ -196,6 +196,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
@override
void didUpdateWidget(_FloatingActionButtonTransition oldWidget) {
super.didUpdateWidget(oldWidget);
final bool oldChildIsNull = oldWidget.child == null;
final bool newChildIsNull = widget.child == null;
if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key)

View file

@ -183,6 +183,7 @@ class _TextFieldState extends State<TextField> {
@override
void didUpdateWidget(TextField oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller == null && oldWidget.controller != null)
_controller == new TextEditingController.fromValue(oldWidget.controller.value);
else if (widget.controller != null && oldWidget.controller == null)

View file

@ -479,6 +479,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
@override
void didUpdateWidget(_Dial oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.mode != oldWidget.mode && !_dragging)
_animateTo(_getThetaForTime(widget.selectedTime));
}

View file

@ -107,6 +107,7 @@ class _StreamBuilderBaseState<T, S> extends State<StreamBuilderBase<T, S>> {
@override
void didUpdateWidget(StreamBuilderBase<T, S> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.stream != widget.stream) {
if (_subscription != null) {
_unsubscribe();
@ -419,6 +420,7 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
@override
void didUpdateWidget(FutureBuilder<T> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.future != widget.future) {
if (_activeCallbackIdentity != null) {
_unsubscribe();

View file

@ -236,6 +236,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
@override
void didUpdateWidget(EditableText oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.controller != oldWidget.controller) {
oldWidget.controller.removeListener(_didChangeTextEditingValue);
widget.controller.addListener(_didChangeTextEditingValue);

View file

@ -831,7 +831,7 @@ abstract class State<T extends StatefulWidget> {
///
/// If you override this, make sure your method starts with a call to
/// super.didUpdateWidget(oldWidget).
// TODO(abarth): Add @mustCallSuper.
@mustCallSuper
@protected
void didUpdateWidget(covariant T oldWidget) { }

View file

@ -368,6 +368,7 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
@override
void didUpdateWidget(RawGestureDetector oldWidget) {
super.didUpdateWidget(oldWidget);
_syncAll(widget.gestures);
}

View file

@ -244,6 +244,7 @@ class _ImageState extends State<Image> {
@override
void didUpdateWidget(Image oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.image != oldWidget.image)
_resolveImage();
}

View file

@ -148,6 +148,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
@override
void didUpdateWidget(T oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.curve != oldWidget.curve)
_updateCurve();
_controller.duration = widget.duration;
@ -229,11 +230,11 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
/// The [AnimatedContainer] will automatically animate between the old and
/// new values of properties when they change using the provided curve and
/// duration. Properties that are null are not animated.
///
///
/// This class is useful for generating simple implicit transitions between
/// different parameters to [Container] with its internal
/// [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].
class AnimatedContainer extends ImplicitlyAnimatedWidget {
/// Creates a container that animates its parameters implicitly.

View file

@ -716,6 +716,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
@override
void didUpdateWidget(Navigator oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.observers != widget.observers) {
for (NavigatorObserver observer in oldWidget.observers)
observer._navigator = null;

View file

@ -122,6 +122,7 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
@override
void didUpdateWidget(GlowingOverscrollIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.color != widget.color || oldWidget.axis != widget.axis) {
_leadingController.color = widget.color;
_leadingController.axis = widget.axis;

View file

@ -60,6 +60,7 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
@override
void didUpdateWidget(RawKeyboardListener oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.focusNode != oldWidget.focusNode) {
oldWidget.focusNode.removeListener(_handleFocusChanged);
widget.focusNode.addListener(_handleFocusChanged);

View file

@ -442,6 +442,7 @@ class _ModalScopeState extends State<_ModalScope> {
@override
void didUpdateWidget(_ModalScope oldWidget) {
super.didUpdateWidget(oldWidget);
assert(widget.route == oldWidget.route);
}

View file

@ -39,6 +39,7 @@ class _StatusTransitionState extends State<StatusTransitionWidget> {
@override
void didUpdateWidget(StatusTransitionWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.animation != oldWidget.animation) {
oldWidget.animation.removeStatusListener(_animationStatusChanged);
widget.animation.addStatusListener(_animationStatusChanged);

View file

@ -74,6 +74,7 @@ class _AnimatedState extends State<AnimatedWidget> {
@override
void didUpdateWidget(AnimatedWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.listenable != oldWidget.listenable) {
oldWidget.listenable.removeListener(_handleChange);
widget.listenable.addListener(_handleChange);
@ -391,20 +392,20 @@ class RelativePositionedTransition extends AnimatedWidget {
/// Animated version of a [DecoratedBox] that animates the different properties
/// of its [Decoration].
///
///
/// See also:
///
/// * [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.
class DecoratedBoxTransition extends AnimatedWidget {
/// Creates an animated [DecorationBox] whose [Decoration] animation updates
/// the widget.
///
/// The [decoration] and [position] cannot be null.
///
/// the widget.
///
/// The [decoration] and [position] cannot be null.
///
/// See also:
///
///
/// * [new DecoratedBox].
DecoratedBoxTransition({
Key key,

View file

@ -55,6 +55,7 @@ class _WillPopScopeState extends State<WillPopScope> {
@override
void didUpdateWidget(WillPopScope oldWidget) {
super.didUpdateWidget(oldWidget);
assert(_route == ModalRoute.of(context));
if (widget.onWillPop != oldWidget.onWillPop && _route != null) {
if (oldWidget.onWillPop != null)

View file

@ -23,6 +23,7 @@ class ProbeWidgetState extends State<ProbeWidget> {
@override
void didUpdateWidget(ProbeWidget oldWidget) {
super.didUpdateWidget(oldWidget);
setState(() {});
}

View file

@ -78,6 +78,7 @@ class TriggerableState extends State<TriggerableWidget> {
@override
void didUpdateWidget(TriggerableWidget oldWidget) {
super.didUpdateWidget(oldWidget);
widget.trigger.callback = fire;
}

View file

@ -30,6 +30,7 @@ class TestWidgetState extends State<TestWidget> {
@override
void didUpdateWidget(TestWidget oldWidget) {
super.didUpdateWidget(oldWidget);
syncedState = widget.syncedState;
// we explicitly do NOT sync the persistentState from the new instance
// because we're using that to track whether we got recreated