Skip to content

TrainHoppingAnimation Calls notifyListeners() on Status Change Instead of notifyStatusListeners() #178336

@swrenn

Description

@swrenn

In its animation status listener, TrainHoppingAnimation calls notifyListeners() on status change when it should call notifyStatusListeners().

AnimationStatus? _lastStatus;
void _statusChangeHandler(AnimationStatus status) {
assert(_currentTrain != null);
if (status != _lastStatus) {
notifyListeners();
_lastStatus = status;
}
assert(_lastStatus != null);
}

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Screen(),
    );
  }
}

class Screen extends StatefulWidget {
  const Screen({super.key});

  @override
  State<Screen> createState() => _ScreenState();
}

class _ScreenState extends State<Screen> with SingleTickerProviderStateMixin {
  late final _controller = AnimationController(
    vsync: this,
    duration: const Duration(seconds: 3),
  );

  late final _animation = TrainHoppingAnimation(
    Tween<double>(begin: 1, end: 0).animate(_controller),
    Tween<double>(begin: 0, end: 1).animate(_controller),
  );

  @override
  void initState() {
    super.initState();
    _controller.addStatusListener((status) {
      print('controller: $status');
    });
    _animation.addStatusListener((status) {
      print('animation: $status');
    });
    _controller.forward();
  }

  @override
  void dispose() {
    _animation.dispose();
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ScaleTransition(
        scale: _animation,
        child: Container(
          color: Colors.red,
          height: 200,
          width: 200,
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

a: animationAnimation APIsframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions