我刚刚开始学习颤振,为了练习,我试图重现iOS联系人应用程序。在此应用程序中,当您点击应用程序标题中的Edit
按钮时,左侧的Clear
按钮将可见。这是我重拍的两个屏幕截图:
红色箭头显示新按钮可用的位置。
现在,当有一个新按钮可用时,“所有/缺少”窗口小部件将向右移动,因为它需要为新窗口小部件释放一些空间。蓝色箭头显示发生位移的位置。
这是包含这些控件的Container子级的内容:
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Visibility(
visible: _listState == ListState.EDITING,
child: InkWell(
child: Text("Clear",
style: kAppleActionButtonTextStyle),
onTap: () {
print("You pressed clear and eveything will be deleted");
},
),
),
CupertinoSegmentedControl(
groupValue: _allOrMissedControlGroupValue,
onValueChanged: (key) {
print(key);
if (key == kAllCalls) {
setState(() {
_showMissingOnly = false;
_allOrMissedControlGroupValue = kAllCalls;
});
} else {
setState(() {
_showMissingOnly = true;
_allOrMissedControlGroupValue = kMissedCalls;
});
}
},
children: {
kAllCalls: Padding(
child: Text(kAllCalls),
padding: EdgeInsets.symmetric(horizontal: 10),
),
kMissedCalls: Padding(
child: Text(kMissedCalls),
padding: EdgeInsets.symmetric(horizontal: 10),
),
},
),
InkWell(
child:
Text(_editButtonText, style: kAppleActionButtonTextStyle),
onTap: () {
setState(() {
if (_listState == ListState.VIEWING) {
_listState = ListState.EDITING;
} else {
_listState = ListState.VIEWING;
}
_editButtonText = editButtonText[_listState];
getListOfCalls(_showMissingOnly, _listState);
});
},
)
],
),
如何避免这种情况发生?
答案 0 :(得分:1)
您有一些选择:
1-向Visibility
小部件中添加其他属性。
Visibility(
maintainSize: true,
maintainAnimation: true,
maintainState: true,
visible: _listState == ListState.EDITING,
child: InkWell(
child: Text("Clear", style: kAppleActionButtonTextStyle),
onTap: () {
print("You pressed clear and eveything will be deleted");
},
),
),
2-使用Opacity
小部件。
Opacity(
opacity: _listState == ListState.EDITING ? 1.0 : 0.0,
child: InkWell(
child: Text("Clear", style: kAppleActionButtonTextStyle),
onTap: onTap: _listState == ListState.EDITING
? () {
print(
"You pressed clear and eveything will be deleted");
}
: null
),
),