### CMake Project Setup Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum version, project name, and binary/application IDs. Configures installation paths and handles cross-compilation sysroot settings. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Configure build options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Installation Rules for Runtime Components Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/CMakeLists.txt Configures installation rules for the application executable, data files, libraries, and assets. Ensures that all necessary components are copied to the correct locations for runtime execution. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Run the Geolocator Example App Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Navigate to the example directory and run the Flutter Geolocator example application using the Flutter SDK. ```bash cd geolocator/example flutter run ``` -------------------------------- ### Installation Rules for Bundle Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/CMakeLists.txt Defines installation rules for creating a relocatable application bundle. It cleans the build directory, installs the executable, data files, libraries, and assets, conditionally installing the AOT library for non-debug builds. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Geolocation - Permission Handling Example Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Demonstrates the process of checking if location services are enabled and requesting necessary permissions before accessing device location. ```APIDOC ## POST /api/permissions/location ### Description Checks if location services are enabled and requests permission to access the device's position. ### Method POST ### Endpoint /api/permissions/location ### Parameters None ### Request Example ```dart import 'package:geolocator/geolocator.dart'; Future _determinePosition() async { bool serviceEnabled; LocationPermission permission; serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { return Future.error('Location services are disabled.'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { return Future.error('Location permissions are denied'); } } if (permission == LocationPermission.deniedForever) { return Future.error( 'Location permissions are permanently denied, we cannot request permissions.'); } return await Geolocator.getCurrentPosition(); } ``` ### Response #### Success Response (200) - **Future** - A future that resolves with the device's position if permissions are granted. #### Error Response (400) - **Future.error** - An error object if location services are disabled or permissions are denied. ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/CMakeLists.txt Initializes the CMake project, sets the minimum version, project name, and binary name. Configures build types for different build modes (Debug, Profile, Release). ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/CMakeLists.txt Initializes the CMake project, sets the minimum version, project name, and binary name. Configures build types for different configurations like Debug, Profile, and Release. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Configure CMake Project Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/runner/CMakeLists.txt Sets the minimum CMake version and project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) ``` -------------------------------- ### NuGet Package Fetching and CppWinRT Execution Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/windows/CMakeLists.txt Fetches the nuget.exe, installs the Microsoft.Windows.CppWinRT package, and then executes cppwinrt.exe to generate necessary header files. This is crucial for Windows-specific C++ development. ```cmake FetchContent_Declare(nuget URL "https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe" URL_HASH SHA256=04eb6c4fe4213907e2773e1be1bbbd730e9a655a3c9c58387ce8d4a714a5b9e1 DOWNLOAD_NO_EXTRACT true ) find_program(NUGET nuget) if (NOT NUGET) message("Nuget.exe not found, trying to download or use cached version.") FetchContent_MakeAvailable(nuget) set(NUGET ${nuget_SOURCE_DIR}/nuget.exe) endif() execute_process(COMMAND ${NUGET} install Microsoft.Windows.CppWinRT -Version ${CPPWINRT_VERSION} -OutputDirectory packages WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE ret) if (NOT ret EQUAL 0) message(FATAL_ERROR "Failed to install nuget package Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}") endif() set(CPPWINRT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}/bin/cppwinrt.exe) execute_process(COMMAND ${CPPWINRT} -input sdk -output include WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE ret) if (NOT ret EQUAL 0) message(FATAL_ERROR "Failed to run cppwinrt.exe") endif() ``` -------------------------------- ### Basic CMake Setup and Plugin Configuration Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/windows/CMakeLists.txt Configures the CMake version, project name, and includes standard settings for the plugin. It also defines the plugin's source files and sets C++ standard to C++20. ```cmake cmake_minimum_required(VERSION 3.15) set(PROJECT_NAME "geolocator_windows") cmake_policy(VERSION 3.15...3.24) set(CPPWINRT_VERSION "2.0.220418.1") project(${PROJECT_NAME} LANGUAGES CXX) include(FetchContent) set(PLUGIN_NAME "${PROJECT_NAME}_plugin") list(APPEND PLUGIN_SOURCES "geolocator_plugin.cpp" "geolocator_plugin.h" "geolocator_enums.h" ) include_directories(BEFORE SYSTEM ${CMAKE_BINARY_DIR}/include) add_library(${PLUGIN_NAME} SHARED "include/geolocator_windows/geolocator_windows.h" "geolocator_windows.cpp" ${PLUGIN_SOURCES} ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_features(${PLUGIN_NAME} PRIVATE cxx_std_20) target_compile_options(${PLUGIN_NAME} PRIVATE /await:strict) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Test Executable Setup with Google Test Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/windows/CMakeLists.txt Configures the test runner executable, including fetching Google Test, setting up its build options, and linking necessary libraries. It also ensures Flutter DLLs are copied for testing. ```cmake if (${include_${PROJECT_NAME}_tests}) set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() # TODO(stuartmorgan): Consider using a single shared, pre-checked-in googletest # instance rather than downloading for each plugin. This approach makes sense # for a template, but not for a monorepo with many plugins. include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/release-1.11.0.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) # The plugin's C API is not very useful for unit testing, so build the sources # directly into the test binary rather than using the DLL. add_executable(${TEST_RUNNER} test/geolocator_windows_test.cpp ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin) target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) # flutter_wrapper_plugin has link dependencies on the Flutter DLL. add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $ ) include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() ``` -------------------------------- ### Get Current Location with Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Queries the current location of the device with specified accuracy and distance filter. Requires importing the geolocator package. ```dart import 'package:geolocator/geolocator.dart'; final LocationSettings locationSettings = LocationSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, ); Position position = await Geolocator.getCurrentPosition(locationSettings: locationSettings); ``` -------------------------------- ### Calculate Distance Between Coordinates Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Calculates the distance in meters between two geographical coordinates. Requires latitude and longitude for both the start and end points. Ensure the geolocator package is imported. ```dart import 'package:geolocator/geolocator.dart'; double distanceInMeters = Geolocator.distanceBetween(52.2165157, 6.9437819, 52.3546274, 4.8285838); ``` -------------------------------- ### Calculate Bearing Between Coordinates Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Calculates the bearing (in degrees) between two geographical coordinates. Takes the latitude and longitude of both the start and end points as parameters. Ensure the geolocator package is imported. ```dart import 'package:geolocator/geolocator.dart'; double bearing = Geolocator.bearingBetween(52.2165157, 6.9437819, 52.3546274, 4.8285838); ``` -------------------------------- ### Get Last Known Location Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Retrieves the last known location stored on the device. This method can return null if no location details are available. Requires importing the geolocator package. ```dart import 'package:geolocator/geolocator.dart'; Position? position = await Geolocator.getLastKnownPosition(); ``` -------------------------------- ### Get Location Accuracy Status Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Query the current location accuracy setting (reduced or precise) on Android and iOS 14+. Returns 'reduced' by default if permissions are not yet granted. On iOS 13 and below, it always returns 'precise'. ```dart import 'package:geolocator/geolocator.dart'; var accuracy = await Geolocator.getLocationAccuracy(); ``` -------------------------------- ### Set up Flutter Library Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/flutter/CMakeLists.txt Configures the Flutter library and its associated headers and data files. This is essential for linking the Flutter engine into the Windows application. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Application Build Configuration Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/CMakeLists.txt Configures the main application executable, linking necessary libraries like Flutter and GTK, and setting runtime output directory to prevent accidental execution of unbundled copies. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Application build add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Configure Flutter library and dependencies in CMake Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/flutter/CMakeLists.txt This section sets up the Flutter library, including finding system dependencies like GTK, GLIB, and GIO using PkgConfig. It defines interface libraries and includes necessary header directories. ```cmake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # === Flutter Library === # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Bundled Libraries Configuration Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/windows/CMakeLists.txt Defines a list of libraries that should be bundled with the plugin. Currently, this list is empty. ```cmake # List of absolute paths to libraries that should be bundled with the plugin set(file_chooser_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Enable AndroidX and Jetifier Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add these lines to your 'gradle.properties' file to ensure compatibility with AndroidX and Jetifier. ```properties android.useAndroidX=true android.enableJetifier=true ``` -------------------------------- ### Implement GeolocatorPlatform Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_platform_interface/README.md Extend GeolocatorPlatform with your platform-specific implementation. Register your plugin by setting the default GeolocatorPlatform instance. ```dart GeolocationPlatform.instance = MyPlatformGeolocator(); ``` -------------------------------- ### Apply Standard Settings and Compile Definitions Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/runner/CMakeLists.txt Applies standard build settings and defines NOMINMAX for the executable. NOMINMAX is often used to prevent Windows.h from defining min/max macros that can conflict with standard library functions. ```cmake apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/runner/CMakeLists.txt Links the executable against the Flutter and flutter_wrapper_app libraries, and specifies include directories. This ensures the executable can find and use necessary Flutter framework components. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Open App and Location Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Provides methods to open either the application settings or the device's location settings. These are useful when permissions are denied or location services are disabled. Ensure the geolocator package is imported. ```dart import 'package:geolocator/geolocator.dart'; await Geolocator.openAppSettings(); await Geolocator.openLocationSettings(); ``` -------------------------------- ### Run Flutter Unit Tests Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Execute the unit tests for the Flutter Geolocator plugin using the `flutter test` command. Ensure all tests pass before committing. ```bash flutter test ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/flutter/CMakeLists.txt Sets up a custom command to invoke the Flutter tool backend. This command is designed to run every time by using a phony output file, ensuring build artifacts are generated when needed. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" windows-x64 $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Automate BYPASS_PERMISSION_LOCATION_ALWAYS Flag (iOS) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this post_install script to your 'ios/Podfile' to automatically set the 'BYPASS_PERMISSION_LOCATION_ALWAYS=1' flag for the 'geolocator_apple' target. ```ruby post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "geolocator_apple" target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1'] end end end end ``` -------------------------------- ### Request and Check Location Permissions Source: https://github.com/baseflow/flutter-geolocator/wiki/Breaking-changes-in-7.0.0 This code demonstrates the recommended flow for requesting and checking location permissions. It first verifies if location services are enabled, then checks the current permission status, and requests permission if necessary, handling cases where permissions are denied permanently or temporarily. ```dart bool serviceEnabled; LocationPermission permission; // Test if location services are enabled. serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { // Location services are not enabled don't continue // accessing the position and request users of the // App to enable the location services. return; } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.deniedForever) { // Permissions are denied forever, handle appropriately. return; } if (permission == LocationPermission.denied) { // Permissions are denied, next time you could try // requesting permissions again (this is also where // Android's shouldShowRequestPermissionRationale // returned true. According to Android guidelines // your App should show an explanatory UI now. return; } } // When we reach here, permissions are granted and we can // continue accessing the position of the device. _position = await Geolocator.getCurrentPosition(); ``` -------------------------------- ### Flutter Project Integration Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/CMakeLists.txt Includes the Flutter managed directory and generated plugin build rules. This integrates the Flutter library and tools into the native build process. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Fetch Latest Changes and Create Branch Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Fetch the latest code from the upstream repository and create a new branch for your contributions. This ensures your work is based on the most recent version. ```bash git fetch upstream git checkout upstream/develop -b ``` -------------------------------- ### Analyze Flutter Project Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Run static code analysis on your Flutter project using `flutter analyze`. This helps identify potential errors and code quality issues. ```bash flutter analyze ``` -------------------------------- ### Configure Plugin Wrapper Library Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/flutter/CMakeLists.txt Defines a static library for the C++ wrapper used by Flutter plugins. It includes core implementations and plugin-specific sources, linking against the Flutter library. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Configure Platform Specific Location Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Use AndroidSettings, AppleSettings, or WebSettings based on the target platform to configure location accuracy, distance filters, and other options. Ensure the correct platform-specific package is imported. ```dart import 'package:geolocator/geolocator.dart'; import 'package:geolocator_android/geolocator_android.dart'; import 'package:geolocator_android/geolocator_web.dart'; import 'package:geolocator_apple/geolocator_apple.dart'; late LocationSettings locationSettings; if (defaultTargetPlatform == TargetPlatform.android) { locationSettings = AndroidSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, forceLocationManager: true, intervalDuration: const Duration(seconds: 10), //(Optional) Set foreground notification config to keep the app alive //when going to the background foregroundNotificationConfig: const ForegroundNotificationConfig( notificationText: "Example app will continue to receive your location even when you aren't using it", notificationTitle: "Running in Background", enableWakeLock: true, ) ); } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) { locationSettings = AppleSettings( accuracy: LocationAccuracy.high, activityType: ActivityType.fitness, distanceFilter: 100, pauseLocationUpdatesAutomatically: true, // Only set to true if our app will be started up in the background. showBackgroundLocationIndicator: false, ); } else if (kIsWeb) { locationSettings = WebSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, maximumAge: Duration(minutes: 5), ); } else { locationSettings = LocationSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, ); } // supply location settings to getCurrentPosition Position position = await Geolocator.getCurrentPosition(locationSettings: locationSettings); // supply location settings to getPositionStream StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen( (Position? position) { print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}'); }); ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/CMakeLists.txt A CMake function to apply common compilation settings to a target, including C++ standard, warning levels, and preprocessor definitions. ```cmake # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Define Executable Target Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/runner/CMakeLists.txt Defines the main executable target for the Windows platform, listing all source files and resources. Ensure all listed files are present in the project directory. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### macOS: Location Usage Description Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this entry to your Info.plist on macOS to request location access. ```xml NSLocationUsageDescription This app needs access to location. ``` -------------------------------- ### Configure Application Runner Wrapper Library Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_windows/example/windows/flutter/CMakeLists.txt Defines a static library for the C++ wrapper used by the Flutter application runner. It includes core implementations and application-specific sources, linking against the Flutter library. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Commit Changes Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Commit your changes with an informative message. Use `git commit -am` for a concise commit. ```bash git commit -am "" ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/CMakeLists.txt A CMake function to apply common compilation features and options to a target. It enforces C++14, enables Wall/Werror, and applies optimization and NDEBUG definitions based on the build type. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/CMakeLists.txt A CMake function to apply standard compilation features, options, and definitions to a target. Ensures C++17 standard, sets warning levels, and handles exception handling and debug definitions. ```cmake # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Add Build Dependencies Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/example/windows/runner/CMakeLists.txt Specifies that the executable target depends on the flutter_assemble target. This ensures that the Flutter assets are built before the main executable. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Open App Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Redirects the user to the application-specific settings page where they can update location permissions. On iOS, this opens the main Settings app. This method should be called when permissions are permanently denied or location services are disabled. ```dart import 'package:geolocator/geolocator.dart'; await Geolocator.openAppSettings(); ``` -------------------------------- ### iOS Location Usage Description Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this key-value pair to your Info.plist file to describe why your app needs location access when in use. ```xml NSLocationWhenInUseUsageDescription This app needs access to location when open. ``` -------------------------------- ### Format Dart Code Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Format your Dart code according to the project's standards using the `dart format` command. This ensures consistent code style. ```bash dart format . ``` -------------------------------- ### Define Flutter tool backend custom command in CMake Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/flutter/CMakeLists.txt This command integrates with the Flutter tool backend to generate necessary build artifacts like the Flutter library and headers. It uses a phony target to ensure the command runs on every build. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Request Fine Location Permission (Android) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this permission to your AndroidManifest.xml to request precise location access. ```xml ``` -------------------------------- ### Push Changes to Fork Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Push your committed changes to your fork on GitHub. Replace `` with the actual name of your feature branch. ```bash git push origin ``` -------------------------------- ### Clone the Geolocator Repository Source: https://github.com/baseflow/flutter-geolocator/blob/main/CONTRIBUTING.md Clone your forked repository of the Flutter Geolocator plugin to your local development machine. Ensure you have configured SSH keys with GitHub. ```bash git clone git@github.com:/flutter-geolocator.git ``` -------------------------------- ### Add geolocator_linux Dependency Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/README.md To enable Linux support for the geolocator plugin, add geolocator_linux as a dependency in your pubspec.yaml file. Ensure you have the geolocator package also listed. ```yaml dependencies: ... geolocator: ^8.2.0 geolocator_linux: ^0.1.0 ``` -------------------------------- ### Request Background Location Permission (Android 10+) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Include this permission in AndroidManifest.xml if background location updates are needed on Android 10 and above. ```xml ``` -------------------------------- ### Bypass Background Location Permission (iOS) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this preprocessor macro in Xcode's Build Settings for the 'geolocator_apple' target to avoid requiring 'NSLocationAlwaysAndWhenInUseUsageDescription'. ```bash BYPASS_PERMISSION_LOCATION_ALWAYS=1 ``` -------------------------------- ### Open Location Settings Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Redirects the user to the device's location settings page where they can enable or disable location services. On iOS, this opens the main Settings app. This method should be called when location services are not enabled. ```dart import 'package:geolocator/geolocator.dart'; await Geolocator.openLocationSettings(); ``` -------------------------------- ### Request Location Permission Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Call this method to request permission from the user to access the device's location. The user will be presented with a permission dialog. Ensure the geolocator package is imported. ```dart import 'package:geolocator/geolocator.dart'; LocationPermission permission = await Geolocator.requestPermission(); ``` -------------------------------- ### Determine Device Position with Permissions Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Acquires the current device position after checking if location services are enabled and requesting necessary permissions. Returns an error if services are disabled or permissions are denied permanently. ```dart import 'package:geolocator/geolocator.dart'; /// Determine the current position of the device. /// /// When the location services are not enabled or permissions /// are denied the `Future` will return an error. Future _determinePosition() async { bool serviceEnabled; LocationPermission permission; // Test if location services are enabled. serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { // Location services are not enabled don't continue // accessing the position and request users of the // App to enable the location services. return Future.error('Location services are disabled.'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { // Permissions are denied, next time you could try // requesting permissions again (this is also where // Android's shouldShowRequestPermissionRationale // returned true. According to Android guidelines // your App should show an explanatory UI now. return Future.error('Location permissions are denied'); } } if (permission == LocationPermission.deniedForever) { // Permissions are denied forever, handle appropriately. return Future.error( 'Location permissions are permanently denied, we cannot request permissions.'); } // When we reach here, permissions are granted and we can // continue accessing the position of the device. return await Geolocator.getCurrentPosition(); } ``` -------------------------------- ### iOS: Request Temporary Full Accuracy Description Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this dictionary to your Info.plist when using requestTemporaryFullAccuracy. The key must match the purposeKey passed to the method. ```xml NSLocationTemporaryUsageDescriptionDictionary YourPurposeKey The example App requires temporary access to the device's precise location. ``` -------------------------------- ### Define list_prepend function in CMake Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator_linux/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a given list. It is used as a workaround for the missing list(TRANSFORM ... PREPEND ...) command in CMake version 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Request Coarse Location Permission (Android) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this permission to your AndroidManifest.xml to request approximate location access. ```xml ``` -------------------------------- ### Listen for Location Updates Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Subscribes to a stream of position updates with specified accuracy and distance filter. Prints the latitude and longitude of each update or 'Unknown' if the position is null. Requires importing the geolocator package. ```dart import 'package:geolocator/geolocator.dart'; final LocationSettings locationSettings = LocationSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, ); StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen( (Position? position) { print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}'); }); ``` -------------------------------- ### Check Location Permission Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Use this method to check if the user has already granted permissions to access the device's location. Ensure the geolocator package is imported. ```dart import 'package:geolocator/geolocator.dart'; LocationPermission permission = await Geolocator.checkPermission(); ``` -------------------------------- ### Set Android Compile SDK Version Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Update the 'compileSdkVersion' in your 'android/app/build.gradle' file to 35. ```gradle android { compileSdkVersion 35 ... } ``` -------------------------------- ### macOS: Personal Information Location Entitlement Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this entry to DebugProfile.entitlements and Release.entitlements on macOS to declare usage of location services. ```xml com.apple.security.personal-information.location ``` -------------------------------- ### Geolocation - Listen to Location Updates Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Provides a stream of location updates as the device moves. Allows configuration of accuracy, distance filter, and time limits for updates. ```APIDOC ## GET /api/location/stream ### Description Listens for location changes and receives position updates via a stream. ### Method GET ### Endpoint /api/location/stream ### Parameters #### Query Parameters - **accuracy** (LocationAccuracy) - Optional - The desired accuracy of the location data. - **distanceFilter** (double) - Optional - The minimum distance in meters a device must move horizontally before an update event is generated. - **timeLimit** (Duration) - Optional - The maximum amount of time allowed between location updates. A TimeoutException will be thrown if the limit is passed. ### Request Example ```dart import 'package:geolocator/geolocator.dart'; final LocationSettings locationSettings = LocationSettings( accuracy: LocationAccuracy.high, distanceFilter: 100, ); StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen( (Position? position) { print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}'); }); ``` ### Response #### Success Response (200) - **Stream** - A stream that emits Position objects or null values representing location updates. #### Response Example ```dart // Example of receiving updates in the stream listener print('Latitude: ${position.latitude}, Longitude: ${position.longitude}'); ``` ``` -------------------------------- ### Listen for Location Service Status Changes Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Obtain a stream that emits the current status of location services, allowing you to react to changes in real-time. ```dart import 'package:geolocator/geolocator.dart'; StreamSubscription serviceStatusStream = Geolocator.getServiceStatusStream().listen( (ServiceStatus status) { print(status); }); ``` -------------------------------- ### Request Foreground Service Location Permission (Android 14+) Source: https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md Add this permission to your AndroidManifest.xml for foreground location services on Android 14 and above. ```xml ```