我有一个按钮,按下它会打开一个模态底页。该工作表有一个表单小部件,它需要很少的文本字段和一个图像(来自画廊/相机)。对于这个图像输入,我创建了另一个在上一个视图(模式表)中调用的有状态小部件。现在,通过用户接收到的图像文件被设置在子状态小部件中的变量中。我的问题是,如何在父小部件中访问此变量(子小部件中的 File 对象)?
请参考以下代码:
底页:(请参阅调用子小部件的注释。)
context: _scaffoldKey.currentContext,
builder: (BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0.0,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
title: Center(
child: _formTitleWidget(),
),
),
body: Container(
height: MediaQuery.of(context).size.height* 0.5,
margin: EdgeInsets.all(MediaQuery
.of(context)
.copyWith()
.size
.width * 0.05),
child: Form(
key: _addChildFormKey,
child: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height* 0.4,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// Calling the child widget here - where 'image' variable is set
AddChildView(),
Container(
height: MediaQuery.of(context).size.height* 0.4,
width: MediaQuery.of(context).size.width* 0.65,
child: Column(
children: [
_childNameInput(),
_childBirthDateInput(),
_childHeightInput(),
_childWeightInput(),
_addChildWithInfo()
],
),
)
],
),
),
),
),
)
);
}```