How to get Nearby WIFI Networks

Fidélitas University 🟡🔵

Costa Rica 🇨🇷

Professor Ariel Ramos

// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:wifi_iot/wifi_iot.dart';
import 'package:wifi_info_flutter/wifi_info_flutter.dart';

Future showWIFI(BuildContext context) async {
  // Consult and display nearby WIFI networks with the press of a button
// First, we need to check if the device has WIFI enabled
  bool isWifiEnabled = await WiFiForIoTPlugin.isEnabled();
  if (!isWifiEnabled) {
    // If WIFI is not enabled, we can prompt the user to enable it
    await WiFiForIoTPlugin.setEnabled(true);
  }

  // Next, we can use the wifi_info_flutter package to get information about the current WIFI network
  final wifiInfo = await WifiInfo().getWifiBSSID();

  // We can then use the wifi_iot package to scan for nearby WIFI networks
  final List<WifiNetwork> wifiList = await WiFiForIoTPlugin.loadWifiList();

  // We can display the list of nearby WIFI networks in a dialog box
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text('Nearby WIFI Networks'),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text('Current Network: ${wifiInfo}'),
            SizedBox(height: 16),
            Expanded(
              child: ListView.builder(
                shrinkWrap: true,
                itemCount: wifiList.length,
                itemBuilder: (BuildContext context, int index) {
                  final wifi = wifiList[index];
                  return ListTile(
                    title: Text('${wifi.ssid}'),
                    subtitle: Text('Signal Strength: ${wifi.level}'),
                  );
                },
              ),
            ),
          ],
        ),
        actions: [
          TextButton(
            child: Text('Close'),
            onPressed: () => Navigator.of(context).pop(),
          ),
        ],
      );
    },
  );
}
7