列表.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class List extends StatefulWidget {
@override
ListState createState() {
return new ListState();
}
}
class ListState extends State<List> {
static const double lat = 2.813812, long = 101.503413;
static const String map_api= "API_KEY";
@override
Widget build(BuildContext context) {
//method to launch maps
void launchMap() async{
const url = "https://maps.google.com/maps/search/?api=$map_api&query=$lat,$long";
if (await canLaunch(url)) {
print("Can launch");
void initState(){
super.initState();
canLaunch( "https://maps.google.com/maps/search/?api=$map_api&query=$lat,$long");
}
await launch(url);
} else {
print("Could not launch");
throw 'Could not launch Maps';
} …Run Code Online (Sandbox Code Playgroud)