在发布模式下构建时,地图显示空白屏幕

时间:2019-07-10 13:50:43

标签: ios google-maps dictionary flutter apple-maps

我正在构建一个需要使用Flutter映射的应用程序,所有功能均按预期工作,但是,如果我通过Jankins进行发布模式构建,则出于某种原因,iOS上的地图将显示空白。我有另一页,其中同一小部件​​已在整页中打开,并且可以正常工作。我的想法是将Google地图放在SingleChildScrolView中会导致此问题。在下面的代码中,我将SingleChildScrolView替换为列表视图,其中所有小部件都作为子代传递,但效果相同,地图以调试模式显示,但通过Jankins构建时,地图为空白,但在另一个页面的地图小部件正在按预期工作。 我在努力奋战几个小时后,将不胜感激。

致谢

class DashboardPage extends StatefulWidget {
  final Model _model;

  DashboardPage(this._model);

  @override
  _DashboardPageState createState() => _DashboardPageState();
}

class _DashboardPageState extends State<DashboardPage> {
  List<Dossier> _dossiers = List();

  _DashboardPageState();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(shrinkWrap: true, children: <Widget>[
        _header(StringResources.dashboardTitle),
        _mapWidget(),
        _header(StringResources.myFiles),
        _listWidgets()
      ],),
      );
  }

  Widget _mapWidget() {
    return Container(
      height: 300,
      child: DossierMap(
        compassEnabled: false,
        model: widget._model,
        onDossierMapViewCreated: _onMapWidgetCreated,
        onDossierInfoWindowTap: _selectedMarker,
      ),
    );
  }

  Widget _listWidgets() {
    return StreamBuilder<List<Dossier>>(
        initialData: [],
        stream: widget._model.dossierService
            .loadDossiers(widget._model.loginService.token)
            .catchError((e) {
          if (widget._model.loggedIn) {
            widget._model.forcedServerLogout();
            Navigator.of(context).pushReplacement(MaterialPageRoute(
              builder: (context) {
                return LoginPage(
                  model: widget._model,
                  errorText: "",
                  onLoggedInCallback: (context) => Navigator.of(context)
                      .pushReplacement(MaterialPageRoute(
                          builder: (context) => DossiersPage(widget._model))),
                );
              },
            ));
          }
        }).asStream(),
        builder: (_context, snapshot) {
          if (snapshot.hasData) {
            _dossiers = snapshot.data;
            return snapshot.data.length != 0
                ? _buildList(snapshot.data)
                : _noDossierContentWidget();
          } else if (snapshot.hasError) {
            return _progressIndicator();
          } else {
            return _progressIndicator();
          }
        });
  }

  Widget _header(String text) {
    return new Container(
      decoration: new BoxDecoration(color: Color(ColorResources.darkGray)),
      child: Padding(
        padding: const EdgeInsets.fromLTRB(20, 12, 0, 12),
        child: Align(
            alignment: Alignment.centerLeft,
            child: Text(text,
                overflow: TextOverflow.ellipsis,
                style: new TextStyle(
                    fontWeight: FontWeight.w500,
                    fontSize: 17,
                    color: Colors.white))),
      ),
   );
  }

  void _onMapWidgetCreated(dynamic controller) {
    controller.setMarkers(_dossiers);
  }

  Widget _buildList(List<Dossier> dossierList) {
    return Container(
        color: Color(ColorResources.dividerColor),
        height: 400,
        child: ListView.separated(
            padding: EdgeInsets.all(0.0),
            separatorBuilder: (context, index) =>
                Divider(color: Colors.grey.shade300, height: 1.5),
            itemCount: dossierList != null ? dossierList.length : 0,
            shrinkWrap: true,
            physics: ScrollPhysics(),
            itemBuilder: (BuildContext context, int index) =>  DossierListItem(
                  dossier: dossierList[index],
                  fromSearch: true,
                  widget: Icon(
                    Icons.keyboard_arrow_right,
                    size: 30,
                    color: Color(ColorResources.gray),
                  ),
                  onListItemClickListener: () =>
                      onListItemClicked(dossierList[index]),
                )));
  }

  void onListItemClicked(Dossier dossier) {
    _selectedDossier(dossier);
  }

  Widget _progressIndicator() {
    return Center(child: CircularProgressIndicator());
  }

  Widget _noDossierContentWidget() {
    return Container(
        color: Theme.of(context).cardColor,
        child: ListTile(
          title: Text(
            StringResources.noOwnedFiles,
            softWrap: true,
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
            style: Theme.of(context).primaryTextTheme.caption,
          ),
        ));
  }

  void _selectedMarker(DossierCluster cluster) async {
    if (cluster.isCluster) {
      Dossier selected = await showDialog(
          context: context,
          builder: (context) {
            return AlertDialog(
              contentPadding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 24.0),
              title: Center(child: Text(StringResources.selectFile)),
              content: SingleChildScrollView(
                physics: const AlwaysScrollableScrollPhysics(),
                child: Column(
                  children:
                      dossiersFromCluster(cluster, onDossierListMarkerClick),
                ),
              ),
              actions: <Widget>[
                FlatButton(
                  child: Text(StringResources.cancel),
                  onPressed: () => Navigator.pop(context),
                )
              ],
            );
          });
      if (selected != null) _selectedDossier(selected);
    } else {
      _selectedDossier(cluster.getFirst);
    }
   }

  List<Widget> dossiersFromCluster(
      DossierCluster cluster, Function onDossierListMarkerClick) {
    List<Widget> widgets = List();
    for (int i = 0; i < cluster.size; i++) {
     Dossier dossier = cluster.get(i);
      widgets.add(DossierListItem(
        dossier: dossier,
        fromSearch: false,
        widget: Container(),
        onListItemClickListener: () => onDossierListMarkerClick(dossier),
      ));
    }
    return widgets;
  }

  void _selectedDossier(Dossier dossier) {
     widget._model.setDossier(dossier);
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => DossierDetailsPage(widget._model)),
    );
  }

  void _openFullSize() {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => FullScreenMapPage(widget._model, _dossiers),
      ),
    );
  }

  void onDossierListMarkerClick(Dossier dossier) {
    widget._model.setDossier(dossier);
    Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => DossierDetailsPage(widget._model)));
  }
}

0 个答案:

没有答案