Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix:avoid calling setState() when mounted is false.
It is an error to call [setState] unless [mounted] is true.
  • Loading branch information
Notzuonotdied authored Dec 6, 2019
commit 60bb2d3e3b0ab343e12cf86c0fb83c777626c235
2 changes: 2 additions & 0 deletions packages/sensors/example/lib/snake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ class SnakeState extends State<Snake> {
void initState() {
super.initState();
accelerometerEvents.listen((AccelerometerEvent event) {
if (!mounted) return;
setState(() {
acceleration = event;
});
});

Timer.periodic(const Duration(milliseconds: 200), (_) {
if (!mounted) return;
setState(() {
_step();
});
Expand Down