signal_strength 0.0.5 copy "signal_strength: ^0.0.5" to clipboard
signal_strength: ^0.0.5 copied to clipboard

PlatformAndroid

Get your phones current signal strengths. Currently only works on android.

example/lib/main.dart

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

import 'package:signal_strength/signal_strength.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _signalStrengthPlugin = SignalStrength();

  NetworkStats? _stats;
  Timer? _timer;

  @override
  void initState() {
    super.initState();
    _timer = Timer(const Duration(seconds: 1), _getNetworkStats);
  }

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

  void _getNetworkStats() async {
    _timer?.cancel();
    var stats = NetworkStats(
        await _signalStrengthPlugin.isOnCellular(),
        await _signalStrengthPlugin.isOnWifi(),
        await _signalStrengthPlugin.getWifiSignalStrength(),
        await _signalStrengthPlugin.getCellularSignalStrength());
    setState(() {
      _stats = stats;
    });
    _timer = Timer(const Duration(seconds: 1), _getNetworkStats);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              if (_stats != null) ...[
                Text('Cell strength: ${_stats?.cellularSignalStrength}'),
                Text('Wifi strength: ${_stats?.wifiSignalStrength}'),
                Text('On cellular: ${_stats?.hasCellular}'),
                Text('On wifi: ${_stats?.hasWifi}'),
              ] else ...[
                const Text('No stats available')
              ],
            ],
          ),
        ),
      ),
    );
  }
}

class NetworkStats {
  NetworkStats(this.hasCellular, this.hasWifi, this.wifiSignalStrength,
      this.cellularSignalStrength);
  bool hasCellular;
  bool hasWifi;
  int? wifiSignalStrength;
  List<int>? cellularSignalStrength;
}
7
likes
160
pub points
87%
popularity

Publisher

unverified uploader

Get your phones current signal strengths. Currently only works on android.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on signal_strength