### Example pubspec.yaml Dependency Entry Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.7.0/install This is an example of how the flutter_baidu_mapapi_search package will be listed under the dependencies section in your project's pubspec.yaml file after installation. ```yaml dependencies: flutter_baidu_mapapi_search: ^3.7.0 ``` -------------------------------- ### Flutter App Structure with Baidu Map Search Demo (Dart) Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.9.2/example This Dart code snippet shows the basic structure of a Flutter application using the BMFMapSearchDemo widget. It sets up the MaterialApp, Scaffold, and a custom AppBar (BMFAppBar) to display the map search interface. This is part of an example demonstrating the flutter_baidu_mapapi_search component. ```dart import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_search_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_baidu_mapapi_search_example/flutter_mapsearch_demo.dart'; class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: 'Baidu Map flutter plugin search component Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Basic Flutter App Structure with Baidu Map Search Demo - Dart Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.9.7/example This Dart code sets up a basic Flutter application structure, including a main app widget and a scaffold with a custom AppBar. It integrates the BMFMapSearchDemo widget, likely provided by the flutter_baidu_mapapi_search package, to display map search functionalities. This example assumes the necessary Baidu Map SDK initialization has already occurred. ```dart import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_search_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_baidu_mapapi_search_example/flutter_mapsearch_demo.dart'; void main() async { // ... (SDK initialization code from previous snippet) runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Add flutter_baidu_mapapi_search Dependency Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.3.0/install This command adds the flutter_baidu_mapapi_search package as a dependency to your Flutter project. It automatically updates your pubspec.yaml file and runs 'flutter pub get'. Ensure you have Flutter SDK installed. ```bash flutter pub add flutter_baidu_mapapi_search ``` -------------------------------- ### Initialize Baidu Map SDK and Set API Key - Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.9.7/example This code snippet demonstrates the initialization of the Baidu Map SDK in a Flutter application. It handles platform-specific API key setup for iOS and coordinate type settings for both platforms. It also retrieves the native search version for iOS. Dependencies include 'flutter', 'flutter_baidu_mapapi_base', and 'flutter_baidu_mapapi_search'. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); /// 设置用户是否同意SDK隐私协议 BMFMapSDK.setAgreePrivacy(true); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType('请输入您的AK', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapSearchVersion.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } ``` -------------------------------- ### Initialize Baidu Map SDK in Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/example Initializes the Baidu Map SDK for Flutter applications. It handles setting the API key and coordinate type, agreeing to privacy policies, and retrieving SDK version information. This setup is crucial for map functionality, with platform-specific configurations for Android and iOS. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; import 'package:flutter_baidu_mapapi_search_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_baidu_mapapi_search_example/flutter_mapsearch_demo.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); /// 设置用户是否同意SDK隐私协议 BMFMapSDK.setAgreePrivacy(true); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType('请输入您的AK', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapSearchVersion.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Initialize Baidu Map SDK and Set API Key in Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.1.0/example This Flutter code snippet demonstrates how to initialize the Baidu Map SDK, set the API key for iOS, and configure the coordinate type. It handles platform-specific initialization for Android and iOS. Dependencies include 'dart:io', 'package:flutter/material.dart', 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart', and 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; import 'package:flutter_baidu_mapapi_search_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_baidu_mapapi_search_example/flutter_mapsearch_demo.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); /// 设置用户是否同意SDK隐私协议 BMFMapSDK.setAgreePrivacy(true); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType( 'yFDD3IlfSk2xTdQ0G41MjRnzd5gUVG1C', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapAPI_Search.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Initialize Baidu Map SDK and Search Services in Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.0.0/example Initializes the Baidu Map SDK with an API key and coordinate type, and retrieves the native search version. This is crucial for setting up map functionalities. It handles platform-specific initialization for iOS and Android, with Android requiring API key configuration in the main project's Manifest file. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_bmfsearch_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_bmfsearch_example/flutter_mapsearch_demo.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType( 'yFDD3IlfSk2xTdQ0G41MjRnzd5gUVG1C', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapAPI_Search.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Initialize Baidu Map SDK and Set API Key (Flutter) Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.9.2/example This snippet demonstrates how to initialize the Baidu Map SDK in a Flutter application. It includes setting the API key and coordinate type for iOS, and setting the coordinate type for Android. It also handles checking the SDK privacy agreement. Dependencies include flutter, flutter_baidu_mapapi_base, and flutter_baidu_mapapi_search. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); // Set whether the user agrees to the SDK privacy protocol BMFMapSDK.setAgreePrivacy(true); // Baidu Map SDK initialization authentication if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType('请输入您的AK', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapSearchVersion.nativeSearchVersion; print('Get native map version number: $map'); } else if (Platform.isAndroid) { // Android currently does not support setting Apikey through interfaces. // Please set it in the main project's Manifest file. For detailed configuration methods, please refer to the official website (https://lbsyun.baidu.com/) demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } ``` -------------------------------- ### Initialize Baidu Map SDK and Set API Key (Dart) Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/2.0.1/example Initializes the Baidu Map SDK and sets the API key and coordinate type. This function is platform-dependent, with specific configurations for iOS and Android. It also retrieves the native search version. Dependencies include 'flutter', 'flutter_baidu_mapapi_base', and 'flutter_baidu_mapapi_search'. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_bmfsearch_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_bmfsearch_example/flutter_mapsearch_demo.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType( 'yFDD3IlfSk2xTdQ0G41MjRnzd5gUVG1C', BMF_COORD_TYPE.BD09LL); Map map = await BMFMapAPI_Search.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Add flutter_baidu_mapapi_search Dependency with Dart Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.7.0/install This command adds the flutter_baidu_mapapi_search package as a dependency to your Dart project. It ensures the package is downloaded and linked for use in your project. ```bash $ dart pub add flutter_baidu_mapapi_search ``` -------------------------------- ### Initialize Baidu Map SDK and Set API Key in Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.3.0/example This Dart code snippet demonstrates the initialization of the Baidu Map SDK within a Flutter application. It handles platform-specific API key configuration for iOS and sets the coordinate type. It also retrieves the native search version number on iOS. Dependencies include 'flutter', 'flutter_baidu_mapapi_base', and 'flutter_baidu_mapapi_search'. ```dart import 'dart:io' show Platform; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; import 'package:flutter_baidu_mapapi_search_example/CustomWidgets/map_appbar.dart'; import 'package:flutter_baidu_mapapi_search_example/flutter_mapsearch_demo.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); /// 设置用户是否同意SDK隐私协议 BMFMapSDK.setAgreePrivacy(true); // 百度地图sdk初始化鉴权 if (Platform.isIOS) { BMFMapSDK.setApiKeyAndCoordType('请输入您的AK', BMF_COORD_TYPE.BD09LL); Map? map = await BMFMapSearchVersion.nativeSearchVersion; print('获取原生地图版本号:$map'); } else if (Platform.isAndroid) { // Android 目前不支持接口设置Apikey, // 请在主工程的Manifest文件里设置,详细配置方法请参考官网(https://lbsyun.baidu.com/)demo BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); } runApp(new MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: BMFAppBar( title: '百度地图flutter插件searh组件Demo', isBack: false, ), body: BMFMapSearchDemo()), ); } } ``` -------------------------------- ### Add flutter_baidu_mapapi_search Dependency (Dart) Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.6.0/install This command adds the flutter_baidu_mapapi_search package as a dependency to your Dart project. It ensures the package is available for use in your application's development. ```bash dart pub add flutter_baidu_mapapi_search ``` -------------------------------- ### Add flutter_baidu_mapapi_search Dependency with Flutter Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.7.0/install This command adds the flutter_baidu_mapapi_search package as a dependency to your Flutter project. It automatically updates your pubspec.yaml file and fetches the package. ```bash $ flutter pub add flutter_baidu_mapapi_search ``` -------------------------------- ### Import flutter_baidu_mapapi_search in Dart Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.3.0/install This import statement allows you to use the functionalities provided by the flutter_baidu_mapapi_search package in your Dart code. Make sure the package is correctly added as a dependency. ```dart import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; ``` -------------------------------- ### Declare flutter_baidu_mapapi_search in pubspec.yaml Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.6.0/install This snippet shows how the flutter_baidu_mapapi_search dependency is declared in the pubspec.yaml file. It specifies the package name and the version constraint, ensuring the correct version is used. ```yaml dependencies: flutter_baidu_mapapi_search: ^3.6.0 ``` -------------------------------- ### Declare flutter_baidu_mapapi_search in pubspec.yaml Source: https://pub.dev/packages/flutter_baidu_mapapi_search/versions/3.3.0/install This snippet shows how the flutter_baidu_mapapi_search dependency is declared in your project's pubspec.yaml file. It specifies the package name and the version constraint. This is typically added automatically by `flutter pub add`. ```yaml dependencies: flutter_baidu_mapapi_search: ^3.3.0 ```