internet_permission 1.0.0 copy "internet_permission: ^1.0.0" to clipboard
internet_permission: ^1.0.0 copied to clipboard

A Flutter plugin for managing internet permissions and checking network connectivity. Automatically adds INTERNET permission for Android and iOS.

internet_permission #

A Flutter plugin that automatically adds internet permissions for Android and iOS, and provides methods to check network connectivity.

Features #

✅ Automatically adds INTERNET permission for Android
✅ Automatically configured for iOS
✅ Check if device is connected to internet
✅ Get connection type (WiFi, Mobile, Ethernet, VPN)
✅ Simple and easy to use API
✅ Cross-platform support (Android & iOS)

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  internet_permission: ^1.0.0

Then run:

flutter pub get

Platform Setup #

Android #

The plugin automatically adds the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

No additional setup required!

iOS #

iOS allows internet access by default. No additional configuration needed.

Usage #

Import the package #

import 'package:internet_permission/internet_permission.dart';

Check if connected to internet #

final internetPermission = InternetPermission();

bool isConnected = await internetPermission.isConnected();

if (isConnected) {
  print('Connected to internet');
} else {
  print('No internet connection');
}

Get connection type #

String connectionType = await internetPermission.getConnectionType();

print('Connection type: $connectionType');
// Output: wifi, mobile, ethernet, vpn, or none

Complete Example #

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

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  final _internetPermission = InternetPermission();
  String _status = 'Checking...';
  String _connectionType = 'Unknown';

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

  Future<void> _checkConnection() async {
    try {
      bool isConnected = await _internetPermission.isConnected();
      String type = await _internetPermission.getConnectionType();

      setState(() {
        _status = isConnected ? 'Connected ✅' : 'Disconnected ❌';
        _connectionType = type;
      });
    } catch (e) {
      setState(() {
        _status = 'Error: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Internet Permission Demo'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Status: $_status',
                style: TextStyle(fontSize: 20),
              ),
              SizedBox(height: 20),
              Text(
                'Connection Type: $_connectionType',
                style: TextStyle(fontSize: 18),
              ),
              SizedBox(height: 40),
              ElevatedButton(
                onPressed: _checkConnection,
                child: Text('Refresh'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

API Reference #

InternetPermission #

Main class for checking internet connectivity.

Methods

Future<bool> isConnected()

Checks if the device is connected to the internet.

Returns: true if connected, false otherwise.

bool connected = await internetPermission.isConnected();
Future<String> getConnectionType()

Gets the current connection type.

Returns: One of: 'wifi', 'mobile', 'ethernet', 'vpn', 'none', or 'unknown'.

String type = await internetPermission.getConnectionType();
Future<bool> hasInternetPermission()

Checks if internet permission is granted (always returns true on both platforms as it's handled at manifest level).

bool hasPermission = await internetPermission.hasInternetPermission();
Future<String?> getPlatformVersion()

Gets the platform version (for debugging purposes).

String? version = await internetPermission.getPlatformVersion();
// Returns: "Android 13" or "iOS 16.0"

How it works #

Android #

The plugin adds internet permissions to your app's AndroidManifest.xml automatically. It uses Android's ConnectivityManager to check network status and connection types.

iOS #

iOS apps have internet access by default. The plugin uses SystemConfiguration framework to check network reachability and connection status.

Common Use Cases #

Show offline message #

bool isConnected = await internetPermission.isConnected();

if (!isConnected) {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(content: Text('No internet connection')),
  );
  return;
}

// Proceed with network request

Check connection before API call #

Future<void> fetchData() async {
  if (!await internetPermission.isConnected()) {
    throw Exception('No internet connection');
  }
  
  // Make API call
  final response = await http.get(Uri.parse('https://api.example.com'));
  // ...
}

Show different UI based on connection type #

String type = await internetPermission.getConnectionType();

if (type == 'mobile') {
  // Show lower quality images to save data
} else if (type == 'wifi') {
  // Show high quality images
}

Requirements #

  • Flutter: >=3.3.0
  • Dart: >=3.0.0
  • Android: minSdkVersion 21 (Android 5.0)
  • iOS: 11.0+

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Issues #

If you encounter any issues, please file them on the issue tracker.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

If you find this package useful, please give it a ⭐ on GitHub!

4
likes
0
points
378
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for managing internet permissions and checking network connectivity. Automatically adds INTERNET permission for Android and iOS.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on internet_permission

Packages that implement internet_permission