当我按下仿真器中的floatActionButton来获取图片时,在运行窗口中仅显示错误消息,而在仿真器屏幕上没有任何更改。
我在dart.file中的[import'dart:io';]下面输入了带有floatActionButton的[import'dart:async';],并在应用程序的build.gradle中更改了SdkVersion。
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class CreatePage extends StatefulWidget {
@override
_CreatePageState createState() => _CreatePageState();
}
class _CreatePageState extends State<CreatePage> {
final textEditingController = TextEditingController();
File _image;
@override
void dispose() {
textEditingController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppBar(),
body: _buildBody(),
floatingActionButton: FloatingActionButton(onPressed: _getImage,
child: Icon(Icons.add_a_photo),),
);
}
Widget _buildAppBar() {
return AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.send), onPressed: () {},
)
],
);
}
Widget _buildBody() {
return Column(
children: <Widget>[
_image == null ? Text('No Image') : Image.file(_image),
TextField(
decoration: InputDecoration(hintText: 'Write down'),
controller: textEditingController,
)
],
);
}
Future _getImage() async {
File image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
});
}
}
错误消息的第一行:E / flutter(8665):ERROR:flutter / lib / ui / ui_dart_state.cc(148)]未处理的异常:MissingPluginException(未找到方法的实现 频道plugins.flutter.io/image_picker上的pickImage)