我有 Scaffold
,它包含一个具有渲染不同组件的条件的主体。我添加了 onRefreshIndicator()
。但是当 Text
被渲染时它不起作用,而当列表 NamesList
被渲染时它工作得很好。
我试过在不同的文件中分离两个组件,但它也不起作用。
`body: Container(
child: RefreshIndicator(
child: fetched && names.length == 0
? Text('Not able to fetch')
: NamesList(names, widget.value, widget.header),
onRefresh: () => getJSONdata(widget.value),
),
)`
我希望 onRefreshIndicator()
在这两种情况下都能正常工作。
最佳答案
将您的 Container
小部件设置为具有最大可用高度,并将您的 Text
小部件放入 SingleChildScrollView
中,并使用 AlwaysScrollableScrollPhysics
.
Container(
height: double.infinity,
child: RefreshIndicator(
child: fetched && names.length == 0
? SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Text("Not able to fetch"))
: NamesList(names, widget.value, widget.header),
onRefresh: () => getJSONdata(widget.value),
))
关于dart - Onrefresh 指示器在条件语句中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54290988/