I created a placeholder for an image in my app, on clicking which I want to be able to open camera, and show the image clicked in the placeholder. I used the image_picker package for this. I wrapped my placeholder container with GestureDetector, however nothing happens on tapping on the container. How do i resolve this ?
In my main file containing Stateless widget, i added my Stateful widget addImage()
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
addImage(), // my stateful widget
TextField(
)
),
Row(
//other implementation here
],
)
]
)
My addImage stateful widget looks like this
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class addImage extends StatefulWidget{
@override
_addImageState createState() => _addImageState();
}
class _addImageState extends State<addImage> {
File _image;
Future getImagefromCamera() async{
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: getImagefromCamera,
child: _image == null ? Container(decoration: BoxDecoration(color: Colors.red[50],border: Border.all(color: Colors.red[200], width: 1.0),borderRadius: BorderRadius.circular(10.0)),
child: Column(
children: <Widget>[
SizedBox(height:30.0),
Icon(Icons.camera_alt, color: Colors.red),
SizedBox(height: 10.0),
Text('Take Image of the Item', style: TextStyle(color: Colors.red)),
SizedBox(height: 30.0)
],
)) : Image.file(_image),
);
}
}
I even added the dependency in pubspec.yaml , however still doesnt work
image_picker: ^0.4.5
