If you run an app made with Flutter and go to the home screen for a while, the following message appears continuously

292

Solution 1

Firstly, dispose your camera when the app is not in foreground, and re-create camera things when it goes foreground again. (You can use this to detect) Since the error seems to be caused by an active camera-related thing when app in background.

Secondly, if you are curious about the warning, it may be caused by:

the main reason is you have put a message on a queue which has not looper to loop. ref

do not worry if you have no android background and do no understand what is a looper ;) Anyway, that sounds like not a huge problem, i.e. the app will not crash. But I suspect whether there will be some memory leak or CPU wasting etc. Anyway, follow the "firstly" part above, and you should not see warning anymore.

Solution 2

What version of the camera package are you using?

This specific issue has cropped up several times in the past year and there have been several patches for it based on the GitHub issues and PRs. So, with that in mind, I would start by updating the camera dependency to the latest and then retest.

The latest issue I could find was from 18 Nov, 2021 and once the original reporter upgraded the camera dependency the issue was resolved: https://github.com/flutter/flutter/issues/93888

The reason I would suggest you to test this prior to following @ch271828n suggestion is because technically speaking this should be handled by the package itself and if they've patched this issue then you can avoid writing boilerplate code.

As an aside, looking at the recent changelog for the plugin, they've patched this error twice:

Flutter Camera Package Changelog: v0.9.4+5

Flutter Camera Package Changelog: 0.9.4+1

Solution 3

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

Change this to ->

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

Your Problem Will be solved

Share:
292
eno2
Author by

eno2

Updated on January 01, 2023

Comments

  • eno2
    eno2 over 1 year

    I am very afraid. is this an error? If you run it and go to the home screen, this message keeps appearing. The same goes for returning to the app.

    Below is part of my code.

    This page supports both YouTube video and camera functions.

    List<CameraDescription> cameras = List.empty(growable: true); 
    
    class Home extends StatefulWidget {
      @override
      const Home({Key? key}) : super(key: key);
      _Home createState() => _Home();
    }
    
    class _Home extends State<Home>{
      CameraController controller =
      CameraController(cameras[1], ResolutionPreset.max);
      //final VideoHomeController controller= Get.put(VideoHomeController());
      late final YoutubePlayerController _controller;
    
      @override
      void initState() {
        super.initState();
        controller.initialize().then((_) {
          if (!mounted) {
            return;
          }
          setState(() {});
        });
        _controller = YoutubePlayerController(
          initialVideoId: '',
          flags: YoutubePlayerFlags(
            autoPlay: false,
            loop: false,
            hideThumbnail: false,
            //isLive: true,
    
            controlsVisibleAtStart: false,
    
            useHybridComposition: false,
          ),
        );
    
      }
    
    
      @override
    
      @override
      void dispose() {
        _controller.pause();
        controller.dispose();
        super.dispose();
      }
    
    
      @override
      Widget build(BuildContext context){
    
        //Get.find<YoutubeDetailController>();
        var height2 = AppBar().preferredSize.height;
        if (!controller.value.isInitialized) {
          return Container();
        }
    
        return SafeArea(
    
    ...
    
      body: Stack(
    
                children: [
                  CameraPreview(controller),
                  //상단 슬라이드
              Column(
    ...
    

    This is logs in console

    W/MessageQueue(20594):  at android.os.Handler.sendMessageDelayed(Handler.java:697)
    W/MessageQueue(20594):  at android.os.Handler.post(Handler.java:427)
    W/MessageQueue(20594):  at android.hardware.camera2.impl.CameraDeviceImpl$CameraHandlerExecutor.execute(CameraDeviceImpl.java:2163)
    W/MessageQueue(20594):  at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onResultReceived(CameraDeviceImpl.java:2071)
    W/MessageQueue(20594):  at android.hardware.camera2.ICameraDeviceCallbacks$Stub.onTransact(ICameraDeviceCallbacks.java:182)
    W/MessageQueue(20594):  at android.os.Binder.execTransactInternal(Binder.java:1195)
    W/MessageQueue(20594):  at android.os.Binder.execTransact(Binder.java:1159)
    W/MessageQueue(20594): Handler (android.os.Handler) {277b89c} sending message to a Handler on a dead thread
    W/MessageQueue(20594): java.lang.IllegalStateException: Handler (android.os.Handler) {277b89c} sending message to a Handler on a dead thread