FlatList当状态messages改变时,我试图滚动到我的末尾。目前我this.refs.flatList.scrollToEnd();在等待一段时间后正在使用,它工作正常。我想要做的是向messages状态添加一个事件侦听器,这样当列表以任何方式更改时,它都会滚动到列表的末尾。我试过
componentDidMount(){
this.state.messages.addEventListener('change', this._handleNewMessage);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。有谁知道我可以实现这一目标的方法?
这种情况以前没有发生过,但现在在我的所有下拉按钮和下拉多项选择中的应用程序中都发生了。仅当字段聚焦时才会显示灰色背景颜色。我不确定它是如何发生的,因为我已经有一段时间没有更改这些小部件的代码了。我认为这是一个主题问题,但检查了我的应用程序并找不到任何内容。是什么原因导致这种灰色背景颜色?下图。
用法:
AVSODropdownButtonString(
hint: ConstantsStringNames.DROPDOWN_HINT_REGION,
width: 80,
value: editedShopInfo?.region != null
? getLabel(_regions, editedShopInfo.region)
: null,
items: _regions.map<DropdownMenuItem<String>>(
(DropdownContent value) {
return DropdownMenuItem<String>(
value: value.optionLabel,
child: Text(
value.optionLabel,
style: ConstantsAvsoStyle.INFO_TABLE_VALUE,
),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
editedShopInfo.region =
getValue(_regions, newValue);
});
},
),
Run Code Online (Sandbox Code Playgroud)
自定义小部件:
class AVSODropdownButtonString extends StatelessWidget {
const AVSODropdownButtonString({
Key key,
this.width,
this.onTap,
@required this.onChanged,
@required this.value,
@required this.items,
this.hint,
}) : super(key: key);
final double width;
final Function onChanged;
final String value;
final List<DropdownMenuItem<String>> …Run Code Online (Sandbox Code Playgroud)