这个页面是我的PhotoPreviewScreen,单击下面代码中的按钮后,我将来自相机屏幕的照片发送到主页。
我得到了一些有趣的错误,我以前没有见过,在文档中很少,在屏幕截图中。以前有没有人见过这些?我该怎么纠正呢?
import 'package:flutter/material.dart';
import 'dart:io';
class PhotoPreviewScreen extends StatelessWidget {
Function setData;
PhotoPreviewScreen({Key key, this.setData}) : super(key: key);
}
class _PhotoPreviewScreenState extends State<PhotoPreviewScreen> {
final String imagePath;
var image;
Future _openGallery() async {}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => Navigator.pop(
context), // Go back to the camera to take the picture again
child: Icon(Icons.camera_alt),
),
appBar: AppBar(title: Text('Photo Preview')),
body: Column(children: [
Expanded(child: Image.file(File(imagePath))),
const SizedBox(height: 16.0),
OutlineButton(
onPressed: () {
_openGallery();
Navigator.pop(context);
},
child: Text('Okay'),
borderSide: BorderSide(
color: Color(
0xff33333D)),
),
]),
);
}
}错误

发布于 2021-04-03 23:24:51
class PhotoPreviewScreen extends StatefulWidget {Function setData; PhotoPreviewScreen({Key key, this.setData}) : super(key: key); }我想应该是"StatefulWidget“而不是"StatelesWidget”。
发布于 2021-04-04 01:17:12
试试下面的代码片段:
import 'package:flutter/material.dart';
import 'dart:io';
class PhotoPreviewScreen extends StatefulWidget {
Function setData;
PhotoPreviewScreen({Key key, this.setData}) : super(key: key);
_PhotoPreviewScreenState createState() => _PhotoPreviewScreenState();
}
class _PhotoPreviewScreenState extends State<PhotoPreviewScreen> {
final String imagePath = ' ';
var image;
Future _openGallery() async {}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => Navigator.pop(
context), // Go back to the camera to take the picture again
child: Icon(Icons.camera_alt),
),
appBar: AppBar(title: Text('Photo Preview')),
body: Column(children: [
Expanded(child: Image.file(File(imagePath))),
const SizedBox(height: 16.0),
OutlineButton(
onPressed: () {
_openGallery();
Navigator.pop(context);
},
child: Text('Okay'),
borderSide: BorderSide(
color: Color(
0xff33333D)),
),
]),
);
}
}https://stackoverflow.com/questions/66932716
复制相似问题