Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 它们是在颤振中禁用延迟加载的一种方法吗_Flutter_Dart - Fatal编程技术网

Flutter 它们是在颤振中禁用延迟加载的一种方法吗

Flutter 它们是在颤振中禁用延迟加载的一种方法吗,flutter,dart,Flutter,Dart,我目前有一个问题与懒惰加载 我在页面视图中有多个项目,我想跟踪页面视图中的小部件。所以我可以改变它的颜色,这取决于它在屏幕上的位置 但当小部件离开屏幕时,我发现了这个问题: The method 'findRenderObject' was called on null. Receiver: null Tried calling: findRenderObject() 我希望有人能帮我。我想这是因为flatters延迟加载,我以为我只在listview.builder中启用了,但似乎我错了 下

我目前有一个问题与懒惰加载

我在
页面视图中有多个项目,我想跟踪页面视图中的小部件。所以我可以改变它的颜色,这取决于它在屏幕上的位置

但当小部件离开屏幕时,我发现了这个问题:

The method 'findRenderObject' was called on null.
Receiver: null
Tried calling: findRenderObject()
我希望有人能帮我。我想这是因为flatters延迟加载,我以为我只在listview.builder中启用了,但似乎我错了

下面是一些代码,供您查看我在做什么:

页面控制器:

final _controller = PageController(
initialPage: 0,
viewportFraction: 0.25,
);
页面浏览:

PageView(
                controller: _controller,
                scrollDirection: Axis.vertical,
                onPageChanged: (int) {
                  setState(() {});
                },
                children: [
                  _container(width, key1,the_times[0]), // i want to keep track of this widget
                  _container(width, key2,the_times[1]),
                  _container(width, key3,the_times[2]),
                  _container(width, key4,the_times[3]),
                  _container(width, key5,the_times[4]),
                  _container(width, key6,the_times[5]),
                  _container(width, key7,the_times[6]),
                  _container(width, key8,the_times[7]),
                  _container(width, key9,the_times[8]),
                  _container(width, key10,the_times[9]),
                  _container(width, key11,the_times[10]),
                  _container(width, key12,the_times[11]),
                  _container(width, key13,the_times[12]),
                ],
              ),
我如何找到小部件:

Color color_function(GlobalKey key) {
RenderBox box = key1.currentContext.findRenderObject();
Offset position = box.localToGlobal(Offset.zero);
double y = position.dy;
if (y > 160 && y < 240) {
  return Colors.white;
} else {
  Colors.black;
} }
我使用
second\u time==true?
来避免启动我的应用程序时出现错误消息,默认情况下为false,并且在构建所有小部件时将其更改为true

但是就像我说的,我遇到了上面描述的错误,当带有key1的小部件离开屏幕时,在那之前一切正常

Widget _container(double width, GlobalKey key, String title) {
return Container(
  key: key,
  height: 100,
  width: width,
  decoration: BoxDecoration(
    color: Colors.transparent,
    borderRadius: BorderRadius.circular(10),
  ),
  child: Center(
    child: AutoSizeText(
      title,
      style: GoogleFonts.montserrat(
        color: second_time == true ? color_function(key) : Colors.white,
      ),
    ),
  ),
);}