перезапуск приложения флаттера при выборе изображения с камеры в хроме (мобильный браузер)

Я использую image_picker pub_link для захвата изображений с камеры. иногда мое приложение перезагружается во время захвата изображений с камеры. это происходит случайно не всегда. также, когда я запускаю на устройстве Android, он отлично работает только в мобильном веб-браузере. Проблема возникает.
Пожалуйста, помогите с этой проблемой. Заранее спасибо. вот мой код

      class NewSurveyScreen1 extends StatefulWidget {
const NewSurveyScreen1({Key? key}) : super(key: key);
@override
State<NewSurveyScreen1> createState() => _NewSurveyScreen1State();
}

class _NewSurveyScreen1State extends State<NewSurveyScreen1> {
File? _image;

 Future<void> getImage()async {
 XFile? image = await ImagePicker().pickImage(source: ImageSource.camera);
if(image==null) {
  return;
}
File imageTeam = File(image.path);
setState(() {
  _image = imageTeam;
});
}


@override
void initState() {
log.info("init called in screen1");
// TODO: implement initState
setValueToNA();
super.initState();
}

@override
 Widget build(BuildContext context) {
return WillPopScope(
  onWillPop: () async {
    log.info("will pop scope screen 1");
    setValueToNA();
    return true;
  },
  child: Scaffold(
    backgroundColor: Colors.white,
    appBar: AppBar(
      title: const Text(
        "Survey",
        style: TextStyle(color: Colors.black),
      ),
      backgroundColor: Colors.white,
      leading: InkWell(
        onTap: () {
          setValueToNA();
          context.vxNav.pop();
          // Navigator.pop(context);
        },
        child: Container(
            margin: const EdgeInsets.all(12),
            decoration: const BoxDecoration(
              shape: BoxShape.circle,
              color: AppColors.primaryColor,
            ),
            child: const Icon(Icons.arrow_back_outlined)),
      ),
    ),
    body: SingleChildScrollView(
      child: Container(
        padding: const EdgeInsets.all(15),
        child: Column(
          children: [

            Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(12),
              ),
              width: 100,
              height: 100,
              child: InkWell(
                onTap: () {
                  getImage();
                },
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(12),
                  child: _image==null?Image.asset(
                    "images/sampel_camera.png",
                    width: 100,
                    height: 100,
                  ):Image.network(
                    _image!.path,
                    width: 100,
                    height: 100,
                  ),
                ),
              ),
            )

          ],
        ),
      ),
    ),
  ),
);
}


}

0 ответов

Другие вопросы по тегам