/ViewRootImpl@58c7336[MainActivity](11826): WindowStopped on com.isoftinc.the_town_table/com.example.thetowentabe.MainActivity set to true

D/SurfaceView@174a961(11826): updateSurface: surface is not valid

I/SurfaceView@174a961(11826): releaseSurfaces: viewRoot = ViewRootImpl@58c7336[MainActivity]

I/SurfaceView@174a961(11826): applyTransactionOnVriDraw: vri = ViewRootImpl@58c7336[MainActivity] fRS = true t = 0xb400006edd143b00 android.view.SurfaceView.releaseSurfaces:858 android.view.SurfaceView.updateSurface:998 android.view.SurfaceView.setVisibility:392

I/SurfaceView@174a961(11826): applyTransactionOnVriDraw: viewRoot.applyTransactionOnDrawFromReleaseSurfaces

I/ViewRootImpl@58c7336[MainActivity](11826): from releaseSurfaces t.apply t = 0xb400006edd143b00

I/MSHandlerLifeCycle(11826): removeMultiSplitHandler: no exist. decor=DecorView@7166055[MainActivity]

D/SurfaceView@174a961(11826): updateSurface: surface is not valid

I/SurfaceView@174a961(11826): releaseSurfaces: viewRoot = ViewRootImpl@58c7336[MainActivity]

I/SurfaceView@174a961(11826): applyTransactionOnVriDraw: vri = ViewRootImpl@58c7336[MainActivity] fRS = true t = 0xb400006edd143d00 android.view.SurfaceView.releaseSurfaces:858 android.view.SurfaceView.updateSurface:998 android.view.SurfaceView.lambda$new$0$android-view-SurfaceView:200

I/SurfaceView@174a961(11826): applyTransactionOnVriDraw: viewRoot.applyTransactionOnDrawFromReleaseSurfaces

I/ViewRootImpl@58c7336[MainActivity](11826): from releaseSurfaces t.apply t = 0xb400006edd143d00

D/OpenGLRenderer(11826): setSurface called with nullptr

D/OpenGLRenderer(11826): trimMemory(TRIM_MEMORY_COMPLETE)::destroyRenderingContext

D/OpenGLRenderer(11826): RenderThread::destroyRenderingContext()

D/OpenGLRenderer(11826): RenderThread::setGrContext()

D/InputTransport(11826): Input channel destroyed: 'ClientS', fd=147

Lost connection to device.

Exited (sigterm)

   List<File?> selectedItemsList = List.generate(3, (index) => null);
  int currentContainerIndex = 0;
  final picker = ImagePicker();
  
  
Future<void> checkAndRequestPermission(ImageSource img) async {
  if (Platform.isAndroid) {
    final isAndroid12OrAbove = await checkAndroidVersion();
    if (img == ImageSource.camera) {
      final status = await Permission.camera.request();
      if (status.isGranted) {
        // Permission granted, proceed to camera
        final pickedFile = await picker.pickImage(source: img);
        if (pickedFile != null) {
          setState(() {
            if (currentContainerIndex >= 0 &&
                currentContainerIndex < selectedItemsList.length) {
              selectedItemsList[currentContainerIndex] =
                  File(pickedFile.path);
              // Increment the currentContainerIndex to move to the next index
              currentContainerIndex++;
            }
          });
        } else {
          ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(content: Text('Nothing is selected')),
          );
        }
      } else if (status.isDenied) {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Camera permission denied')),
        );
      }
    } else if (img == ImageSource.gallery) {
      final statusg = await Permission.storage.request();
      final statusg1 = await Permission.photos.request();
      if (statusg.isGranted | statusg1.isGranted) {
        final pickedFile = await picker.pickImage(source: img);
        if (pickedFile != null) {
          setState(() {
            if (currentContainerIndex >= 0 &&
                currentContainerIndex < selectedItemsList.length) {
              selectedItemsList[currentContainerIndex] =
                  File(pickedFile.path);
              // Increment the currentContainerIndex to move to the next index
              currentContainerIndex++;
            }
          });
        }
      } else if (statusg.isDenied) {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Gallery permission denied')),
        );
      }
    }
  } else {
    // Handle permissions for non-Android platforms (iOS, etc.) here if needed
  }
}

Future<bool> checkAndroidVersion() async {
  try {
    final status = await Permission.camera.status;
    final galleryStatus = await Permission.storage.status;
    final galleryStatus1 = await Permission.photos.status;
    if (status.isGranted || galleryStatus.isGranted || galleryStatus1.isGranted) {
      // Android 12 and above or granted gallery permission
      return true;
    } else {
      return false;
    }
  } catch (e) {
    return false; // Error occurred while checking Android version or permission status, handle accordingly
  }
}
0

There are 0 best solutions below