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

android location mocker

example/lib/main.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 latController = TextEditingController();
  var lngController = TextEditingController();
  @override
  void initState() {
    super.initState();
    frequencyController.text = "200";
    latController.text = "43.932344";
    lngController.text = "87.339119";
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          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: [
                        const Text("lng"),
                        Expanded(
                          child: TextField(
                            controller: lngController,
                            textAlign: TextAlign.end,
                            decoration: const InputDecoration(
                                border: InputBorder.none,
                                isCollapsed: true,
                                isDense: true),
                          ),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        const Text("lat"),
                        Expanded(
                          child: TextField(
                            controller: latController,
                            textAlign: TextAlign.end,
                            decoration: const InputDecoration(
                                border: InputBorder.none,
                                isCollapsed: true,
                                isDense: true),
                          ),
                        )
                      ],
                    ),
                  ],
                ),
              ),
              ElevatedButton(
                  onPressed: () async {
                    var bean = MockLocationBean(
                        common: Common(
                            useGps: isUseGps,
                            useNetwork: isUseNetwork,
                            frequencyMs:
                                int.tryParse(frequencyController.text) ?? 200),
                        mockLocation: MockLocation(
                            lat: double.tryParse(latController.text) ??
                                43.932344,
                            lng: double.tryParse(lngController.text) ??
                                87.339119));
                    _androidLocationMockerPlugin.startMock(bean);
                  },
                  child: const Text("启动模拟")),
              ElevatedButton(
                  onPressed: () async {
                    var res = await _androidLocationMockerPlugin.stopMock();
                  },
                  child: const Text("停止模拟")),
            ],
          ),
        ),
      ),
    );
  }
}
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