r_get_ip 0.1.3 copy "r_get_ip: ^0.1.3" to clipboard
r_get_ip: ^0.1.3 copied to clipboard

About get ip address.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:r_get_ip/r_get_ip.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('External IP Address'),
              FutureBuilder(
                builder: _buildIpWidget,
                future: RGetIp.externalIP,
              ),
              SizedBox(
                height: 16,
              ),
              Text('internal IP Address'),
              FutureBuilder(
                builder: _buildIpWidget,
                future: RGetIp.internalIP,
              ),
              SizedBox(
                height: 16,
              ),
              Text('Network Type'),
              FutureBuilder(
                builder: _buildIpWidget,
                future: RGetIp.networkType,
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {});
          },
          child: Icon(Icons.refresh),
        ),
      ),
    );
  }

  Widget _buildIpWidget(BuildContext context, AsyncSnapshot<String?> snapshot) {
    return Text(
      '${snapshot.hasData ? snapshot.data : "0.0.0.0"}',
      style: TextStyle(
        color: Theme.of(context).primaryColor,
        fontSize: 26,
        fontWeight: FontWeight.bold,
      ),
    );
  }
}
17
likes
140
points
660
downloads

Publisher

verified publisherrhyme95.cn

Weekly Downloads

About get ip address.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on r_get_ip