From c1a92764f2c5ec8de60e3a567c55c0867459a45b Mon Sep 17 00:00:00 2001 From: FaizHashmiCS22 Date: Tue, 25 Jul 2023 16:32:25 +0300 Subject: [PATCH] Made the IP Address Dynamic --- lib/home/home_screen.dart | 45 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 8992ef1..e45d985 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -1,4 +1,5 @@ import 'dart:developer'; +import 'dart:io'; import 'package:connectivity/connectivity.dart'; import 'package:flutter/material.dart'; @@ -43,10 +44,24 @@ class _MyHomePageState extends State { super.dispose(); } + Future printIps() async { + for (var interface in await NetworkInterface.list(type: InternetAddressType.IPv4)) { + print("interface: ${interface.name}"); + + if (interface.name == "eth0") { + for (var address in interface.addresses) { + DEVICE_IP = address.address; + log('${address.address} ${address.type.name}'); + log(DEVICE_IP); + } + } + } + } + @override void initState() { listenNetworkConnectivity(); - + printIps(); if (!signalRHelper.getConnectionState()) { signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect); } @@ -84,30 +99,10 @@ class _MyHomePageState extends State { ), ], ), - // Row( - // children: [ - // const SizedBox(width: 60), - // SizedBox( - // width: 200, - // child: TextField( - // controller: controller, - // )), - // const SizedBox(width: 30), - // isLoading - // ? const CircularProgressIndicator() - // : ElevatedButton( - // onPressed: onUpdateIPPressed, - // child: const Text( - // "Update IP", - // style: TextStyle(color: Colors.white), - // ), - // style: ElevatedButton.styleFrom(backgroundColor: AppGlobal.appRedColor), - // ), - // const SizedBox(width: 30), - // Text("IP: $DEVICE_IP", style: const TextStyle(fontWeight: FontWeight.w600)), - // const SizedBox(width: 20), - // ], - // ), + Padding( + padding: const EdgeInsets.only(right: 20), + child: Text(DEVICE_IP, style: TextStyle(fontWeight: FontWeight.w500, fontSize: SizeConfig.getWidthMultiplier() *2.6)), + ), ], ), ),