每次我在tabnavigator中更改页面时,flutter googlemaps都会重新加载

时间:2018-12-15 13:59:21

标签: flutter

Map loads everytime I go back to MapPage

您好,我正在尝试在应用程序中使用Flutter和新的googlemaps插件。我的问题是,每次我更改Tabnav中的页面时,都会重新加载googlemaps小部件。我尝试使用AutomaticKeepAliveClientMixin,但这没有帮助。我将继续尝试解决此问题,但会受到帮助,或者有人知道我做错了什么?谢谢!

这是我的代码:

client, err = mongo.NewClient("mongodb://my_first_mongodb:27017")

MapPage:

import 'package:flutter/material.dart';
import 'package:restapoints/pages/pages.dart';

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My Flutter App',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  final List<Widget> _children = [
    MapPage(),
    QrPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My Flutter App'),
      ),
      body: _children[_currentIndex], // new
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped, // new
        currentIndex: _currentIndex, // new
        items: [
          new BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
          ),
          new BottomNavigationBarItem(
            icon: Icon(Icons.mail),
            title: Text('Messages'),
          ),
          new BottomNavigationBarItem(
              icon: Icon(Icons.person), title: Text('Profile'))
        ],
      ),
    );
  }

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}

0 个答案:

没有答案