这个问题在这里已有答案:
我是一名初级(或不到1个月的学习者)dart / flutter开发人员 . 我尝试创建一个示例proflie应用程序 - 在主屏幕上显示用户的配置文件图像 . - 用户可以使用应用程序内相机拍照或从相册中选择并显示为 Profiles 照片 .
我创建了2个主viewController .
- main.dart
void main() {
runApp(new MaterialApp(
home: new MyApp(),
routes: <String, WidgetBuilder>{
'/screen1': (BuildContext context) => new MyApp(),
'/screen3': (BuildContext context) => new UploadAvatarButton()
},
));
}
class MyApp extends StatefulWidget {
final String _images = "";
MyApp(String _images, {Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return new MyHomePage();
}
}
class MyHomePage extends State<MyApp> {
@override
Widget build(BuildContext context) {
Widget myPhoto = new Container(
//Attribute
child: new FlatButton(
child: new Container(
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.cover, image: new AssetImage('images/sample.jpg')),
),
),
onPressed: _showPersBottomSheetCallBack,
),
);
return new MaterialApp(
home: new Scaffold(
//Header
body: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new Container(child: myPhoto),
和2. cameraView.dart
class UploadAvatarButton extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new MakeUploadAvatarButtonState();
}
class MakeUploadAvatarButtonState extends State<UploadAvatarButton> {
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
//Try to send data or image back to main screen
List<int> imageBytes = image.readAsBytesSync();
String base64Image = BASE64.encode(imageBytes);
//send data back
Navigator.push(context, new MaterialPageRoute(builder: (_) =>
new MyApp(_image.)));
});
}
如您所见,我使用方法从相机发回图像
List<int> imageBytes = image.readAsBytesSync();
String base64Image = BASE64.encode(imageBytes);
Navigator.push(context, new MaterialPageRoute(builder: (_) =>
new MyApp(_image.)));
在主要
final String _images = "";
MyApp(String _images, {Key key}) : super(key: key);
但是,我收到了错误
[dart] The constructor returns type 'dynamic' that isn't of expected type 'Widget'.
你能告诉我吗?
祝您好运
1 回答
将构造函数修改为
访问MyHomePage类中的图像