我正在尝试将文件imageFile从父对象传递给子窗口小部件以使用裁切器功能,但无法让孩子识别它,我错过了一步吗?
class ProfileHome extends StatefulWidget {
@override
_ProfileHomeState createState() => _ProfileHomeState();
}
class _ProfileHomeState extends State<ProfileHome> {
File imageFile;
Future<void> _pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
setState(() {
imageFile = selected;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
ProfilePhoto(
imageFile: imageFile,)
儿童小工具
class ProfilePhoto extends StatefulWidget {
File imageFile;
ProfilePhoto({this.imageFile});
@override
_ProfilePhotoState createState() => _ProfilePhotoState();
}
class _ProfilePhotoState extends State<ProfilePhoto> {
Future<void> _cropImage() async {
File cropped = await ImageCropper.cropImage(sourcePath: imageFile.path);
setState(() {
imageFile = cropped ?? imageFile;
});
}