-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Closed
flutter/plugins
#3044Labels
d: examplesSample code and demosSample code and demosgood first issueRelatively approachable for first-time contributorsRelatively approachable for first-time contributorsp: image_pickerThe Image Picker plugin.The Image Picker plugin.packageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
Description
This bug is easy to reproduce. This run this code that is listed as example code in the Readme for this package. Then, click the floating action button to open the camera on the emulator, but do not take or accept a picture. Instead, click the back button to return to the previous screen. Flutter will then crash with the following error:
**Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null.
E/flutter (12402): Receiver: null
E/flutter (12402): Tried calling: path
E/flutter (12402): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)**
Here is the sample code I ran -- an exact copy/paste from the readme of this package. I am running Flutter 1.20.2 on the stable channel. Also, the sample code provided with package requires importing the dart.io package, so I added that.
import 'package:image_picker/image_picker.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
_image = File(pickedFile.path);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Picker Example'),
),
body: Center(
child: _image == null
? Text('No image selected.')
: Image.file(_image),
),
floatingActionButton: FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: Icon(Icons.add_a_photo),
),
);
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
d: examplesSample code and demosSample code and demosgood first issueRelatively approachable for first-time contributorsRelatively approachable for first-time contributorsp: image_pickerThe Image Picker plugin.The Image Picker plugin.packageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.