仅在一次PageView中构建Flutter GoogleMap [英] Flutter GoogleMap in a PageView build only ONCE

查看:53
本文介绍了仅在一次PageView中构建Flutter GoogleMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PageView .builder和3个 GoogleMap -s.

I have a PageView.builder and 3 GoogleMap-s in it.

我只需要第一次创建3个小部件,并且我不想再次重建它们.现在,当我只更改页面时,它会在加载之前闪烁一次,这很烦人.而且慢.

I had to create the 3 widgets only the first time, and I do not want to rebuild them again. Now it is annoying when I just change the page it is flashing once before load. And slow.

有什么方法可以在该小部件上建立FIXED状态?

Any way to build a FIXED state on that widget?

我尝试过:

AutomaticKeepAliveClientMixin

@overridebool get wantKeepAlive => true;

但没有用.

推荐答案

也许您忘记了在构建方法中调用 super.build(context); .

maybe you forget to call super.build(context); in build method.

赞:

class TestInnerPage extends StatefulWidget {
  @override
  _TestInnerPageState createState() => _TestInnerPageState();
}

class _TestInnerPageState extends State<TestInnerPage>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    /// Dont't forget this
    super.build(context);

    return Container();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}

这篇关于仅在一次PageView中构建Flutter GoogleMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆