Unhandled Exception: setState() called after dispose(): _EmojiPickerState
Closed this issue · 5 comments
yokoboko commented
Hi,
want to report a bug.
How to reproduce:
Open a page with EmojiPicker in it and go back(pop) to previous one before emoji picker loads.
E/flutter (15896): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] #Unhandled Exception: setState() called after dispose(): _EmojiPickerState#02fa2(lifecycle state: defunct, not mounted)
E/flutter (15896): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (15896): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (15896): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
�[38;5;244mE/flutter (15896): #0 State.setState.<anonymous closure>�[39;49m
�[38;5;244mE/flutter (15896): #1 State.setState�[39;49m
�[38;5;248mE/flutter (15896): #2 _EmojiPickerState.updateEmojis.<anonymous closure>�[39;49m
�[38;5;244mE/flutter (15896): #3 _rootRunUnary (dart:async/zone.dart:1141:38)�[39;49m
�[38;5;244mE/flutter (15896): #4 _CustomZone.runUnary (dart:async/zone.dart:1034:19)�[39;49m
�[38;5;244mE/flutter (15896): #5 _FutureListener.handleValue (dart:async/future_impl.dart:140:18)�[39;49m
�[38;5;244mE/flutter (15896): #6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:681:45)�[39;49m
�[38;5;244mE/flutter (15896): #7 Future._propagateToListeners (dart:async/future_impl.dart:710:32)�[39;49m
�[38;5;244mE/flutter (15896): #8 Future._completeWithValue (dart:async/future_impl.dart:525:5)�[39;49m
�[38;5;244mE/flutter (15896): #9 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:34:15)�[39;49m
�[38;5;244mE/flutter (15896): #10 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)�[39;49m
E/flutter (15896): #11 _EmojiPickerState.getRecentEmojis (package:emoji_picker/emoji_picker.dart)
E/flutter (15896): <asynchronous suspension>
�[38;5;248mE/flutter (15896): #12 _EmojiPickerState.updateEmojis�[39;49m
E/flutter (15896): <asynchronous suspension>
�[38;5;248mE/flutter (15896): #13 _EmojiPickerState.initState�[39;49m
�[38;5;244mE/flutter (15896): #14 StatefulElement._firstBuild�[39;49m
�[38;5;244mE/flutter (15896): #15 ComponentElement.mount�[39;49m
�[38;5;244mE/flutter (15896): #16 Element.inflateWidget�[39;49m
�[38;5;244mE/flutter (15896): #17 MultiChildRenderObjectElement.mount�[39;49m
�[38;5;244mE/flutter (15896): #18 Element.inflateWidget�[39;49m
�[38;5;244mE/flutter (15896): #19 Element.updateChild�[39;49m
�[38;5;244mE/flutter (15896): #20 ComponentElement.performRebuild�[39;49m
�[38;5;244mE/flutter (15896): #21 Element.rebuild�[39;49m
�[38;5;244mE/flutter (15896): #22 ComponentElement._firstBuild�[39;49m
�[38;5;244mE/flutter (15896): #23 ComponentElement.mount�[39;49m
�[38;5;244mE/flutter (15896): #24 Element.inflateWidget�[39;49m
�[38;5;244mE/flutter (15896): #25 Element.updateChild�[39;49m
�[38;5;244mE/flutter (15896): #26 ComponentElement.performRebuild�[39;49m
�[38;5;244mE/flutter (15896): #27 Element.rebuild�[39;49m
�[38;5;244mE/flutter (15896): #28 ComponentElement._firstBuild�[39;49m
�[38;5;244mE/flutter (15896): #29 ComponentElement.mount�[39;49m
�[38;5;244mE/flutter (15896): #30 Element.inflateWidget�[39;49m
�[38;5;244mE/flutter (15896): #31 Element.updateChild�[39;49m
�[38;5;244mE/flutter (15896): #32 ComponentElement.performRebuild�[39;49m
�[38;5;244mE/flutter (15896): #33 Element.rebuild�[39;49m
�[38;5;244mE/flutter (15896): #34 ComponentElement._firstBuild�[39;49m
�[38;5;244mE/flutter (15896): #35 ComponentElement.mount�[39;49m
�[38;5;244mE/flutter (15896): #36 Element.inflateWidget (�[39;49m
Example code:
import 'package:flutter/material.dart';
import 'package:emoji_picker/emoji_picker.dart';
void main() => runApp(MainApp());
class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Emoji Picker Example",
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Emoji Picker Home"),
),
body: Center(
child: FlatButton(
color: Colors.greenAccent,
child: Text('Show emoji screen'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EmojiPage()),
);
},
),
),
);
}
}
class EmojiPage extends StatefulWidget {
@override
EmojiPageState createState() => new EmojiPageState();
}
class EmojiPageState extends State<EmojiPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Emoji Picker Example"),
),
body: Column(
children: <Widget>[
Container(
width: double.maxFinite,
height: 240,
color: Colors.greenAccent,
child: FlatButton(
child: Text('BACK'),
onPressed: () {
Navigator.pop(context);
},
),
),
EmojiPicker(
rows: 3,
columns: 7,
recommendKeywords: ["racing", "horse"],
numRecommended: 10,
onEmojiSelected: (emoji, category) {
print(emoji);
},
),
],
),
);
}
}
bazinga-web commented
Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.---- That's works for me.
yokoboko commented
@bazinga-web I'm not calling setState(), the emoji_picker does. I think this should be fixed.
paulkastel commented
Yes, this is happening and is annoying!
yokoboko commented
Yes, this is happening and is annoying!
Are you sure that you are using the latest version? That has been fixed.
paulkastel commented
@yokoboko yes, version 0.1.0 from pub.dev