Code Monkey home page Code Monkey logo

vpn-check's Introduction

VPN LOCATION CHECK

A Flutter project using trust_location package, to check if the user are using a VPN to change your current location

Explaining

First, we need to add dependency trust_location to pubspec.yaml file:

dependencies:
 trust_location: ^2.0.13

Next, we need to add permission_handler dependency

dependencies:
 permission_handler: ^10.2.0

Now in the main.dart file, declare the variables to check location and if these location is real or mock

  String? _latitude;
  String? _longitude;
  bool? _isMockLocation;

On sequency, we need to request access to location of device using permission_handler package

  void requestLocationPermission() async {
    PermissionStatus permission = await Permission.location.request();
    print('permissions: $permission');
  }

And here is the method that can check location

 Future<void> getLocation() async {
    try {
      TrustLocation.onChange.listen((event) => setState(() {
            _latitude = event.latitude;
            _longitude = event.longitude;
            _isMockLocation = event.isMockLocation;
            print(event);
          }));
    } on PlatformException catch (e) {
      print('PlatformException $e');
    }
  }

On initState method, call both previously methods to start checking

  @override
  void initState() {
    super.initState();
    requestLocationPermission();
    getLocation();
  }

And for finish, call the method start on trust_location package to set the timing of checks

  @override
  void initState() {
    super.initState();
    requestLocationPermission();
    getLocation();
    TrustLocation.start(5);
  }

On screen you can show if the _isMockLocation is true or not and the current location

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Trust Location Plugin')),
      body: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Center(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Mock Location: $_isMockLocation'),
            Text('Latitude: $_latitude, Longitude: $_longitude'),
          ],
        )),
      ),
    );
  }
}

vpn-check's People

Contributors

limanathan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.