首页 > 解决方案 > 刷新指示器不适用于 NestedScrollView

问题描述

@override
  Widget build(BuildContext context) {
    super.build(context);

    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
      ),
      child: Scaffold(
     key: _scaffoldKeyProfilePage,

      body: DefaultTabController(
        length: 2,
 child:RefreshIndicator(
          onRefresh: _onRefresh,
        child: NestedScrollView(
          
            headerSliverBuilder: (context, _) {
              return [
                SliverList(
                delegate: SliverChildListDelegate(
                 [                 BuildMainProfile(
              ....//
                 ),
                 Padding(
                ...//another design 
                 ), 
                
              ];
            },
            // You tab view goes here
            body: Column(
              children: <Widget>[
                TabBar(
              tabs: [
                Tab(text: 'A'),
                Tab(text: 'B'),
              ],
                ),
                Expanded(
              child: TabBarView(
                children: [
                  BuildPost(,

                  ),
                 BuildWings()
                ],
              ),
                ),
              ],
            ),
          ),),
      ),

  }

刷新指示器不适用于 NestedScrollView,有什么方法可以实现 RefreshIndictor?我尝试在堆栈中添加一个空的 ListView,刷新指示器开始显示,但因为我的 NestedScrollView 不滚动。

标签: flutterflutter-layout

解决方案


您是否尝试将NestedScrollView小部件设置physicsAlwaysScrollableScrollPhysics()

请参阅RefreshIndicator的文档。

刷新指示器不显示

如果它的可滚动后代可以过度滚动,即如果可滚动的内容大于其视口,则 RefreshIndicator 将出现。为了确保 RefreshIndicator 始终出现,即使可滚动的内容适合其视口,请将可滚动的 Scrollable.physics 属性设置为 AlwaysScrollableScrollPhysics

ListView(   
physics: const AlwaysScrollableScrollPhysics(),  
children: ... )

RefreshIndicator 只能用于垂直滚动视图。


推荐阅读