title: Flutter - Take a photo
body: <p>When I tap on a GestureDetector it opens a dialog where I am able to select, if I want to take the picture from the gallery or to make a photo on my own (<a href="https://pub.dartlang.org/packages/image_picker" rel="nofollow noreferrer">the plugin</a>). But my problem is when I click on one of the buttons on the dialog, the dialog pops up again and only after that, it's possible to take a picture from the camera or the gallery.
  It would be great, if someone could help me with this problem.</p>
  
  <p>This is the <strong>GestureDetector</strong>:</p>
  
  <pre><code>GestureDetector(
                child: Container(
                  child: (_image == null
                    ? CircleAvatar(child: Icon(Icons.photo))
                    : FileImage(_image)
                  )
                ),
                onTap: () async{
                  switch(await dialogs.takePhoto(context)){
                    case "take":
                      getImage(ImageSource.camera);
                      break;
                    case "pick":
                      getImage(ImageSource.gallery);
                      break;
                  }
                },
              )
  </code></pre>
  
  <p>The call <code>dialogs.takePhoto(context)</code> ends here:</p>
  
  <pre><code>takePhoto(BuildContext context){
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext ctxt){
          return AlertDialog(
            title: Text("Change Photo"),
            content: Container(
              child: Column(
                children: &lt;Widget&gt;[
                  InkWell(
                    child: Text("Take photo"),
                    onTap: ()=&gt; Navigator.pop(ctxt, "take"),
                  ),
                  InkWell(
                    child: Text("Pick photo"),
                    onTap: ()=&gt; Navigator.pop(ctxt, "pick"),
                  ),
  
                ],
              ),
            ),
            actions: &lt;Widget&gt;[
              FlatButton(
                  child: Text(
                    "Abort"
                  ),
                  onPressed: ()=&gt;Navigator.pop(ctxt),
              )
            ],
          );
        }
    );
  }
  </code></pre>
  
  <p>This is an example:<a href="https://i.stack.imgur.com/F5Y6l.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F5Y6l.gif" alt="This is an example"></a></p>
  
  <p>Thanks in advance !</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Found the solution exactly the moment where I clicked on the submit button. The problem was that I called the function to pick the image twice XD.</p>