我的页面有两个有状态的小部件(例如A和B)。单击A时,我希望B消失,然后A占据屏幕的整个宽度。我不知道如何使B消失。
A会按预期扩展,但是B的存在会导致溢出。我尝试使用ValueListenableBuilder传递一个变量,该变量将触发B的可见性变为false,但无法实现。
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter layout demo',
home: Scaffold(
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[HeadCardApp("Society", 'assets/houses.png', 1), //Widget A
HeadCardApp("Community",'assets/discuss.png', 2)], //Widget B
),
),
);}
}
}
class HeadCardApp extends StatefulWidget {
final String heading;
final String imgLink;
final int stateNo;
HeadCardApp(this.heading, this.imgLink, this.stateNo);
@override
HeadCard createState() => HeadCard(heading, imgLink, stateNo);
}
class HeadCard extends State<HeadCardApp> {
String heading;
String imgLink;
double _width = 380;
double _height = 180;
int stateNo;
HeadCard(this.heading, this.imgLink, this.stateNo);
@override
Widget build(BuildContext context) {
return new GestureDetector(
onTap: (){
if(stateNo == 1){
//Space to make changes
}
else
{
}
setState(() {
_width = MediaQuery.of(context).size.width;
_height = MediaQuery.of(context).size.height;
});
},
child: AnimatedContainer(
width: _width,
height: _height,
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
),
));
}
}```
答案 0 :(得分:0)
您可以将MaterialApp的Column部分放在StatfulWidget中,这样就可以通过在新StatfulWiget中调用setState来更改可见性来更改可见性。