Refresh indicator without scrollview

后端 未结 8 1052
失恋的感觉
失恋的感觉 2020-12-14 15:52

I know with a ListView or SingleChildScrollView RefreshIndicator just works natively but I want to use a RefreshIndicator

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 16:26

    Most of the other answers will work but they all have some downsides. Using a SingleChildScrollView without adjusting the height will cause the "scrolling glowing effect" to be not at the bottom of the page. Setting the height to the maximum height of the current view (by using MediaQuery or a LayoutBuilder) will solve this problem, but there will be a render overflow when your content's height is bigger than the height of the available space.

    At the end, the following solution worked perfectly for me without any problems:

    LayoutBuilder(
      builder: (context, constraints) => RefreshIndicator(
        onRefresh: _refresh,
        child: SingleChildScrollView(
          physics: AlwaysScrollableScrollPhysics(),
          child: ConstrainedBox(
            constraints: BoxConstraints(
              minHeight: constraints.maxHeight
            ),
            child: Text("Your Widget")
          )
        )
      ),
    )
    

提交回复
热议问题