从构建器返回容器时,CupertinoSliverRefreshControl有时会闪烁

时间:2019-01-22 10:13:42

标签: dart flutter pull-to-refresh

在我的应用中,我需要在其中一个屏幕上提供拉动刷新功能。我选择了CupertinoSliverRefreshControl。应用程序的原色是红色,因此导航栏和搜索栏都用它着色。并且刷新控件也需要用红色着色。但是,当我从CupertinoSliverRefreshControl的方法返回带有颜色的Container时,在onRefresh完成后到达零位置时,整个控件都会闪烁白色条纹。

小部件结构如下:

import 'package:flutter/cupertino.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      home: CupertinoPageScaffold(
        child: CustomScrollView(
          slivers: <Widget>[
            /// navbar
            CupertinoSliverNavigationBar(
              backgroundColor: Color(0xffe30613),
              largeTitle: Text(
                'App',
                style: TextStyle(
                  color: Color(0xffffffff),
                ),
              ),
            ),

            /// pull to refresh control
            CupertinoSliverRefreshControl(
              onRefresh: () => Future.delayed(Duration(milliseconds: 1000)),
              builder: (_, __, ___, ____, _____) {
                return Container(
                  color: Color(0xffe30613),
                  child: Center(
                    child: const CupertinoActivityIndicator(
                      radius: 12.0,
                    ),
                  ),
                );
              },
            ),

            /// searchbar
            SliverToBoxAdapter(
              child: Container(
                height: 56.0,
                padding: const EdgeInsets.symmetric(
                  horizontal: 8.0,
                  vertical: 10.0,
                ),
                color: Color(0xffe30613),
                child: Container(
                  color: Color(0xffffffff),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

这是问题的证明:

demonstration

更新:

参考我在flutter的仓库中创建的issue,问题出在CupertinoSliverRefreshControl本身。实际上,这不是问题,而是预期的行为。当Control的refreshState到达inactive时,build方法将返回一个空的Container,默认为控件高度的10%。在上面的gif上可以看到确切的Container

我创建了Pull Request,它添加了参数来控制这种Container颜色,现在等待它被合并。

0 个答案:

没有答案