khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
97 stars 56 forks source link

used build context asynchronously without checking mounted #149

Closed frankmer closed 1 week ago

frankmer commented 3 months ago

This error always occurs when I pop the screen before its initialized.

To fix this you just need to check if the widget is still mounted. You can find the setState in the file "flutter_zxing/src/ui/reader_widget.dart" in line 200, if it is true what the stacktrace says.

Error: setState() called after dispose(): _ReaderWidgetState#c4ea6(lifecycle state: defunct, not mounted)

StackTrace:

State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1167:9)
State.setState (package:flutter/src/widgets/framework.dart:1202:6)
_ReaderWidgetState.initStateAsync.<anonymous closure> (package:flutter_zxing/src/ui/reader_widget.dart:200:7)
_rootRunUnary (dart:async/zone.dart:1407:47)
_CustomZone.runUnary (dart:async/zone.dart:1308:19)
Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:847:45)
Future._propagateToListeners (dart:async/future_impl.dart:876:13)
Future._completeWithValue (dart:async/future_impl.dart:652:5)