From 206cd1244c07db360c37d1dee472d702cb87ebb2 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 2 Oct 2022 03:34:55 +0800 Subject: [PATCH] feat: launch built-in maps --- lib/screens/gh_user.dart | 4 ++-- linux/flutter/generated_plugin_registrant.cc | 4 ++++ linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + windows/flutter/generated_plugin_registrant.cc | 3 +++ windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/screens/gh_user.dart b/lib/screens/gh_user.dart index 782fdb8..ea9453c 100644 --- a/lib/screens/gh_user.dart +++ b/lib/screens/gh_user.dart @@ -18,6 +18,7 @@ import 'package:git_touch/widgets/user_header.dart'; import 'package:go_router/go_router.dart'; import 'package:gql_github/user.data.gql.dart'; import 'package:gql_github/user.req.gql.dart'; +import 'package:maps_launcher/maps_launcher.dart'; import 'package:provider/provider.dart'; class _Repos extends StatelessWidget { @@ -126,8 +127,7 @@ class _User extends StatelessWidget { prefix: const Icon(Octicons.location), child: Text(p.location!), onClick: () { - launchStringUrl( - 'https://www.google.com/maps/place/${p.location!.replaceAll(RegExp(r'\s+'), '')}'); + MapsLauncher.launchQuery(p.location!); }, ), if (isNotNullOrEmpty(p.email)) diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 25e690a..6646d0e 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,14 @@ #include "generated_plugin_registrant.h" +#include #include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) maps_launcher_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "MapsLauncherPlugin"); + maps_launcher_plugin_register_with_registrar(maps_launcher_registrar); g_autoptr(FlPluginRegistrar) sentry_flutter_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin"); sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2f5154f..e6e90d8 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + maps_launcher sentry_flutter url_launcher_linux ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 2ebb991..c9da429 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,7 @@ import FlutterMacOS import Foundation +import maps_launcher import package_info_plus_macos import path_provider_macos import sentry_flutter @@ -13,6 +14,7 @@ import shared_preferences_macos import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + MapsLauncherPlugin.register(with: registry.registrar(forPlugin: "MapsLauncherPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin")) diff --git a/pubspec.lock b/pubspec.lock index e23d6e9..6b70b2a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -511,6 +511,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + maps_launcher: + dependency: "direct main" + description: + name: maps_launcher + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" markdown: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ebee9dd..3653767 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,6 +72,7 @@ dependencies: google_fonts: go_router: from_css_color: + maps_launcher: antd_mobile: path: ../ant-design-mobile-flutter diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 2272406..c6993f7 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,10 +6,13 @@ #include "generated_plugin_registrant.h" +#include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + MapsLauncherPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("MapsLauncherPlugin")); SentryFlutterPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("SentryFlutterPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 33f774d..61ba726 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + maps_launcher sentry_flutter url_launcher_windows )