A flutter package to get the system ip address
Add the dependency in your pubspec.yaml
file
ip_address: <version>
Then run,
flutter pub get
or pub get
.
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
.
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.
Now in your Dart code, you can use:
import 'package:get_ip_address/get_ip_address.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