繁体   English   中英

如何通过单击颤动中的按钮打开谷歌地图

[英]How to open google maps by clicking on a button in flutter

我是颤振的新手,我想通过使用颤振单击按钮来打开谷歌地图。 这是我的代码,在第 98 行的代码中,我想通过单击“共享您的位置”按钮打开谷歌地图,所以请给我一个建议,告诉我应该使用哪些依赖项(google-maps-flutter 或 google-urls ) 以及我应该在我的代码中进行哪些更改。

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'maps.dart';


class Intro extends StatefulWidget {
  const Intro({Key? key}) : super(key: key);

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

class _IntroState extends State<Intro> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('\t\t\t\t\t\t\t\t\t\tShree Food'),backgroundColor: Color(0xff01A0C7)),
        body: Column(
            children:[
              Container(
                child: Padding(
                  padding: const EdgeInsets.all(36.0),
                  child: Center(
                    child: Card(
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          const ListTile(
                            title: Text('Goal'),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: <Widget>[
                              TextButton(
                                child: const Text('>'),
                                onPressed: () {
                                  showAlertDialog(context);
                                },
                              ),
                              const SizedBox(width: 8),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              Container(
                child: Padding(
                  padding: const EdgeInsets.all(36.0),
                  child: Center(
                    child: Card(
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          const ListTile(
                            title: Text('Vision'),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: <Widget>[
                              TextButton(
                                child: const Text('>'),
                                onPressed: () {
                                  showAlertDialog1(context);
                                },
                              ),
                              const SizedBox(width: 8),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                  GridView.count(
                    primary: false,
                    padding: EdgeInsets.all(50),
                    shrinkWrap: true,
                    crossAxisCount: 2,
                    children: [
                    Column(
                    children : [
                      IconButton(
                        icon: Image.asset(
                          'images/maps.png',
                        ),
                      iconSize: 80,
                      onPressed: () {
                        **//I want to open google maps by clicking on this button**
                      },
                    ),
                    Text('Share Your Location')
                    ],
                    ),
                    Column(
                    children : [
                      IconButton(
                        icon: Image.asset(
                          'images/donate.jpg',
                        ),
                      iconSize: 80,
                      onPressed: () {
                      },
                      ),
                       Text('Donate Zone')
                    ],
                    ),
                  ],
                  ),
                ],
                ),
              )
            ]
        )
    );
  }
}

showAlertDialog(BuildContext context) {
  // Create button
  Widget okButton = FlatButton(
    child: Text("OK"),
    onPressed: () {
      Navigator.of(context).pop(MaterialPageRoute(builder: (context) => Intro()));
    },
  );

  // Create AlertDialog
  AlertDialog alert = AlertDialog(
    title: Text("Simple Alert"),
    content: Text("This is an alert message."),
    actions: [
      okButton,
    ],
  );

  // show the dialog
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return alert;
    },
  );
}

showAlertDialog1(BuildContext context) {
  // Create button
  Widget okButton = FlatButton(
    child: Text("OK"),
    onPressed: () {
      Navigator.of(context).pop(MaterialPageRoute(builder: (context) => Intro()));
    },
  );

  // Create AlertDialog
  AlertDialog alert = AlertDialog(
    title: Text("Simple Alert"),
    content: Text("This is an alert message."),
    actions: [
      okButton,
    ],
  );

  // show the dialog
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return alert;
    },
  );
}

如果我理解你的问题,你想在按下按钮时打开谷歌地图,如果是这种情况,你需要使用这个包:

map_launcher

试试看

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM