Flutter 如何在flatter中更改窗口小部件内部的值
我有一个返回showModalBottomSheet的小部件,它位于void内部。我称之为initState类内部。但当我使用setState更改showModalBottomSheet内部的值时,即使值发生更改,它也不会显示 initState() showModalBottomSheet空隙Flutter 如何在flatter中更改窗口小部件内部的值,flutter,state-management,Flutter,State Management,我有一个返回showModalBottomSheet的小部件,它位于void内部。我称之为initState类内部。但当我使用setState更改showModalBottomSheet内部的值时,即使值发生更改,它也不会显示 initState() showModalBottomSheet空隙 void showModal() { showModalBottomSheet<void>( isDismissible: false, cont
void showModal() {
showModalBottomSheet<void>(
isDismissible: false,
context: context,
builder: (BuildContext context) {
return SingleChildScrollView(
initState()内的ModalSheet听起来不是一个好的做法,您能解释一下用例吗?当我按下父窗口小部件内的按钮时,我希望显示showModalBottomSheet。但由于这个小部件足够大,我决定将它移动到另一个小部件中。无需在initState中编写它。InitState的存在还有其他原因。但是如何在没有任何其他操作的情况下调用它呢?正如您所说,在父类中有一个按钮,按下该按钮将显示工作表。所以只要按一下按钮就可以调用showModalSheet
void showModal() {
showModalBottomSheet<void>(
isDismissible: false,
context: context,
builder: (BuildContext context) {
return SingleChildScrollView(
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: color,
borderRadius: BorderRadius.circular(50.0),
),
height: MediaQuery.of(context).size.width / 10,
width: MediaQuery.of(context).size.width / 10,
),
onTap: () => showModalBottomSheet(
context: context,
builder: (_) {
return Container(
height: 300,
child: ColorPickerWidget(this.callbackColor),
);
}),
),
void callbackColor(Color color) {
setState(() {
this.color = color;
});
}