fphonelocation 0.0.3 copy "fphonelocation: ^0.0.3" to clipboard
fphonelocation: ^0.0.3 copied to clipboard

a flutter phone location plugin.

example/lib/main.dart

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


void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver{

  double? latitude;
  double? longitude;

  @override
  void initState() {
    Fphonelocation.init(isSingle: false);
    Fphonelocation.setLocationCall(locationCall: (double latitude,double longitude){
      print('--->setLocationCall,latitude=$latitude,longitude=$longitude');
      this.latitude = latitude;
      this.longitude = longitude;
      setState(() {});
    });
    WidgetsBinding.instance.addObserver(this);
    super.initState();
  }

  @override
  void dispose() {
    Fphonelocation.stopLocation();
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch(state){
      case AppLifecycleState.inactive:
      //inactive:用户可见,但不可响应用户操作
        break;
      case AppLifecycleState.paused:
      //paused:已经暂停了,用户不可见、不可操作
        Fphonelocation.stopLocation();
        break;
      case AppLifecycleState.resumed:
        //从后台返回到前台,重新赋值,表示需要司机从新选择任务
        Fphonelocation.startLocation();
        break;
      case AppLifecycleState.detached:
      //detached:当前页面即将退出
        break;
      case AppLifecycleState.hidden:
      // TODO: Handle this case.
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('原生传过来的经纬度为:${latitude},${longitude}'),
        ),
      ),
    );
  }
}
1
likes
105
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

a flutter phone location plugin.

Repository

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fphonelocation