android_location_mocker 0.0.2 copy "android_location_mocker: ^0.0.2" to clipboard
android_location_mocker: ^0.0.2 copied to clipboard

android location mocker

example/lib/main.dart

import 'package:amap_core_fluttify/amap_core_fluttify.dart';
import 'package:amap_search_fluttify/amap_search_fluttify.dart';
import 'package:android_location_mocker/MockLocationBean.dart';
import 'package:android_location_mocker/android_location_mocker.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _androidLocationMockerPlugin = AndroidLocationMocker();

  var isUseGps = true;
  var isUseNetwork = true;

  var frequencyController = TextEditingController();

  var addressController = TextEditingController();

  List<Poi>? addr;

  LatLng? currentLatlng;
  @override
  void initState() {
    super.initState();
    frequencyController.text = "100";
    addressController.text = "中国华商金融中心";
    init();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(title: const Text('Plugin example app')),
            body: SingleChildScrollView(
              child: Column(children: [
                ElevatedButton(
                    onPressed: () async {
                      var res = await _androidLocationMockerPlugin.isReady();
                      Fluttertoast.showToast(msg: '$res');
                    },
                    child: const Text("是否就绪")),
                ElevatedButton(
                    onPressed: () async {
                      var res =
                          await _androidLocationMockerPlugin.isOpenDevMode();
                      Fluttertoast.showToast(msg: '$res');
                    },
                    child: const Text("是否开启开发者模式")),
                ElevatedButton(
                    onPressed: () async {
                      var res =
                          await _androidLocationMockerPlugin.openDevMode();
                      Fluttertoast.showToast(msg: '$res');
                    },
                    child: const Text("打开开发者模式")),
                Container(
                    margin: const EdgeInsets.symmetric(horizontal: 15),
                    decoration: BoxDecoration(color: Colors.white, boxShadow: [
                      BoxShadow(
                          color: Colors.grey.shade300,
                          spreadRadius: 5,
                          blurRadius: 5)
                    ]),
                    padding: const EdgeInsets.all(10),
                    child: Column(children: [
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            const Text("启用GPS"),
                            Switch(
                                value: isUseGps,
                                onChanged: (a) {
                                  setState(() {
                                    isUseGps = a;
                                  });
                                })
                          ]),
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            const Text("启用Network定位"),
                            Switch(
                                value: isUseNetwork,
                                onChanged: (a) {
                                  setState(() {
                                    isUseNetwork = a;
                                  });
                                })
                          ]),
                      Row(children: [
                        const Text("定位频率"),
                        Expanded(
                            child: TextField(
                                controller: frequencyController,
                                textAlign: TextAlign.end,
                                decoration: const InputDecoration(
                                    border: InputBorder.none,
                                    isCollapsed: true,
                                    isDense: true))),
                        const Text("毫秒")
                      ]),
                      Row(
                        children: [
                          Expanded(
                              child: TextField(
                            controller: addressController,
                          )),
                          ElevatedButton(
                              onPressed: () async {
                                List<Poi> res = await AmapSearch.instance
                                    .searchKeyword(addressController.text);
                                addr = res;
                                setState(() {});
                              },
                              child: const Text("搜索"))
                        ],
                      ),
                      addr != null
                          ? ListView.builder(
                              shrinkWrap: true,
                              physics: const NeverScrollableScrollPhysics(),
                              itemCount: addr!.length,
                              itemBuilder: (BuildContext context, int index) {
                                var bean = addr![index];
                                return InkWell(
                                  onTap: () {
                                    currentLatlng = bean.latLng;
                                    setState(() {});
                                    Fluttertoast.showToast(
                                        msg:
                                            "当前已选择:${currentLatlng?.latitude},${currentLatlng?.longitude}");
                                  },
                                  child: Container(
                                    padding: const EdgeInsets.all(10),
                                    margin: const EdgeInsets.symmetric(
                                        horizontal: 5, vertical: 5),
                                    decoration: BoxDecoration(
                                        color: Colors.grey.shade200),
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Text(
                                          "${bean.address}",
                                          style: const TextStyle(
                                              fontWeight: FontWeight.bold),
                                        ),
                                        Text(
                                            "latitude:${bean.latLng?.latitude}"),
                                        Text(
                                            "longitude:${bean.latLng?.longitude}"),
                                      ],
                                    ),
                                  ),
                                );
                              },
                            )
                          : Container(),
                    ])),
                ElevatedButton(
                    onPressed: () async {
                      var bean = MockLocationBean(
                          common: Common(
                              useGps: isUseGps,
                              useNetwork: isUseNetwork,
                              frequencyMs:
                                  int.tryParse(frequencyController.text) ??
                                      100),
                          mockLocation: MockLocation(
                              lat: currentLatlng?.latitude ?? 0,
                              lng: currentLatlng?.longitude ?? 0));
                      _androidLocationMockerPlugin.startMock(bean);
                    },
                    child: const Text("启动模拟")),
                ElevatedButton(
                    onPressed: () async {
                      var res = await _androidLocationMockerPlugin.stopMock();
                    },
                    child: const Text("停止模拟"))
              ]),
            )));
  }

  Future<void> init() async {
    AmapSearch.instance.updatePrivacyAgree(true);
    AmapSearch.instance.updatePrivacyShow(true);
    await AmapCore.init("");
  }
}
3
likes
0
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

android location mocker

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on android_location_mocker

Packages that implement android_location_mocker