Open steve28100 opened 4 years ago
Any update for this issue?
There needs to be some more refactoring to the widget but in this case I don't think it'd help anyways - when you push a new route on top of the old one, it doesn't automatically dispose the routes under it. By using replacementNamed, you're actually disposing the old routes. Also, if you're just pushing a new route on top every time that is a bit of an issue with your code - you should eventually be letting the old routes go away. Instead of pushReplacementNamed, look into Navigator.pushAndRemoveUntil(
for when you return to the home screen.
If that doesn't help, at some point I'm going to try to separate the UI from the plugin a bit more which will allow this to be fixed more easily, but for now you could simply use a stateful widget with a bool "showCamera" or something and only show the QrCamera if showCamera
is true. As soon as the QrCamera isn't in the widget tree, it should dispose itself fully.
Hello,
Behind, what i'm using to Restart Camera, when return to screen, on build method of my Statefull widget :
Create key for QrCamera Widget (Ex: GlobalKey camKey = GlobalKey())
class _CamAppBarState extends State<CamAppBar> {
final bool showCam = true;
GlobalKey camKey = GlobalKey();
@override
Widget build(BuildContext context) {
if (showCam && qrCam == null) {
qrCam = QrCamera(
key: camKey,
onError: (context, error) => Text(
error.toString(),
style: TextStyle(color: Colors.red),
),
qrCodeCallback: (code) => camCallBack(code),
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
color: Colors.black, width: 1.0, style: BorderStyle.solid),
),
),
);
} else if (qrCam != null && // Restart de la camera
(camKey.currentState as QrCameraState).onScreen &&
QrMobileVision.channelReader.qrCodeHandler == null) {
Future.delayed(Duration(milliseconds: 200),
() => (camKey.currentState as QrCameraState).restart());
}
}
It seem to be OK after testing.
But new to Flutter and i don't know if it is the right way...
Here is a minimal reproducible code with the Flutter's intended way to detect and manage route.
Hello, the camera is works fine but doesn't work when come back to the same screen again. Example: Home menu -> Barcode menu (works fine) -> Some Screens -> Home menu -> Barcode menu (doesn't work).
However if using Navigator pushReplacementNamed the camera is loaded again. But I can't do that because I still need previous routes.
Maybe the problem is because the camera is not fully disposed in dispose method so the camera is not loaded when using pushNamed method. Is there any solution for this?