A Flutter Package to Get The Ip Address Of The Current Device

get_ip_address 

A flutter package to get the system ip address

Getting Started 

Add the dependency in your pubspec.yaml file

ip_address: <version>

Then run,

flutter pub get or pub get.

How to use? 

Add

var ipAddress = IpAddress(type: RequestType.json);

type is optional, default value is RequestType.text.

Now, to get the IpAddress

dynamic data = await ipAddress.getIpAddress();

So, depending on type the ipAddress will be given.

If any error occurred it will throw IpAddressException.

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add get_ip_address

With Flutter:

 $ flutter pub add get_ip_address

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  get_ip_address: ^0.0.6

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:get_ip_address/get_ip_address.dart';

example/example.dart

import 'package:get_ip_address/get_ip_address.dart';

void main() async {
  try {
    /// Initialize Ip Address
    var ipAddress = IpAddress(type: RequestType.json);

    /// Get the IpAddress based on requestType.
    dynamic data = await ipAddress.getIpAddress();
    print(data.toString());
  } on IpAddressException catch (exception) {
    /// Handle the exception.
    print(exception.message);
  }
}

Download details:

Author: pradyotprksh

Source: https://github.com/pradyotprksh/development_learning/tree/main/dart/ip_address

#flutter #android #ios

A Flutter Package to Get The Ip Address Of The Current Device
4.15 GEEK