Я пытаюсь передать файл 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;
});
}