title: My new android app crash when running image_picker (base on flutter dart)
body: <p>I am developing an application for shopping using flutter, so I am stacking somewhere and I need help.</p>
  
  <p>I use image_picker code provided on pub.dev (<a href="https://pub.dev/packages/image_picker#-readme-tab-" rel="nofollow noreferrer">https://pub.dev/packages/image_picker#-readme-tab-</a>) then I developed a page for adding products on my app, so when I click on the camera icon or gallery icon to pick image the app crashes and opens the camera screen/gallery screen. </p>
  
  <p>my big problem is; it works fine with the emulator but on a real phone, it crushes.</p>
  
  <p>I tried to use retrieveLostData() as shown on pub.dev, but I didn't know where to use it. </p>
  
  <p>Bellow is my code</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'dart:io';
  import 'package:flutter/widgets.dart';
  
  import 'package:image_cropper/image_cropper.dart';
  import 'package:image_picker/image_picker.dart';
  import 'package:firebase_storage/firebase_storage.dart';
  
  //my imports
  import 'package:myshop/main.dart';
  
  class ImageCapture extends StatefulWidget {
    @override
    _ImageCaptureState createState() =&gt; _ImageCaptureState();
  }
  
  class _ImageCaptureState extends State&lt;ImageCapture&gt; {
    File _imageFile;
  
    Future&lt;void&gt; _cropImage() async {
      File cropped = await ImageCropper.cropImage(
          sourcePath: _imageFile.path,);
  
      setState(() {
        _imageFile = cropped ?? _imageFile;
      });
    }
   // pick image from galery or camera
    Future&lt;void&gt; _pickImage(ImageSource source) async {
      File selected = await ImagePicker.pickImage(source: source);
  
      setState(() {
        _imageFile = selected;
      });
    }
     //remove image
    void _clear() {
      setState(() =&gt; _imageFile = null);
    }
  
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          elevation: 0.0,
          backgroundColor: Colors.orange[700],
          title: Text(
            'Image Capture',
            style: TextStyle(fontFamily: 'Exo', fontSize: 13.0),
          ),
          actions: &lt;Widget&gt;[
            IconButton(
              icon: Icon(
                Icons.search,
                color: Colors.white,
                size: 23.0,
              ),
              onPressed: () {},
            ),
            IconButton(
                icon: Icon(
                  Icons.home,
                  size: 18,
                  color: Colors.white,
                ),
                onPressed: () =&gt; Navigator.of(context)
                    .push(MaterialPageRoute(builder: (context) =&gt; Home())))
          ],
        ),
  
        //pick image from camera or gallery
        bottomNavigationBar: BottomAppBar(
          color: Colors.cyan[900],
          child: Container( margin: EdgeInsets.fromLTRB(30, 0, 30, 0),
            child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: &lt;Widget&gt;[
  
                IconButton(
                  icon: Icon(Icons.photo_camera, color: Colors.orange, size: 18,),
                  onPressed: () =&gt; _pickImage(ImageSource.camera),
                ),
                IconButton(
                  icon: Icon(Icons.photo_library, color: Colors.orange, size: 18,),
                  onPressed: () =&gt; _pickImage(ImageSource.gallery),
                ),
              ],
            ),
          ),
        ),
  
        body: ListView(
          children: &lt;Widget&gt;[
            if (_imageFile != null) ...[
              Image.file(_imageFile),
              Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: &lt;Widget&gt;[
                  FlatButton(
                    child: Icon(Icons.crop, size: 18,),
                    onPressed: _cropImage,
                  ),
                  FlatButton(
                    child: Icon(Icons.refresh,size: 18,),
                    onPressed: _clear,
                  ),
                ],
              ),
            ], if (_imageFile==null)...[
              Center(
                child: Text('No Image Captured', style: TextStyle(color: Colors.black54),),
              )
            ]
          ],
        ),
      );
    }
  }
  </code></pre>