diff options
-rw-r--r-- | lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart | 198 |
1 files changed, 110 insertions, 88 deletions
diff --git a/lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart b/lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart index 35225b8..1d2e679 100644 --- a/lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart +++ b/lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'package:flutter_ics_homescreen/core/utils/helpers.dart'; import 'package:flutter_ics_homescreen/export.dart'; import 'package:get_ip_address/get_ip_address.dart'; @@ -19,15 +20,44 @@ class WiredScreen extends StatefulWidget { State<WiredScreen> createState() => _WiredScreenState(); } +class Interface { + final String deviceName; + final String? deviceIP; + + const Interface({required this.deviceName, required this.deviceIP}); +} + class _WiredScreenState extends State<WiredScreen> { - String deviceIP = "192.168.234.120"; + String publicIP = "N/A"; + List<Interface> interfaces = List<Interface>.empty(); + @override void initState() { super.initState(); - getIPAddress(); + getDeviceInfo(); } - getIPAddress() async { + getDeviceInfo() async { + final list = await NetworkInterface.list(type: InternetAddressType.IPv4); + final newInterfaces = list.map((interface) { + String? deviceIP; + for (var address in interface.addresses) { + if (!address.isLinkLocal && !address.isLoopback && !address.isMulticast) { + deviceIP = address.address; + break; + } + } + return Interface( + deviceName: interface.name, + deviceIP: deviceIP, + ); + }).toList(growable: false); + setState(() { + interfaces = newInterfaces; + }); + } + + getPublicIPAddress() async { try { /// Initialize Ip Address var ipAddress = IpAddress(type: RequestType.text); @@ -35,7 +65,7 @@ class _WiredScreenState extends State<WiredScreen> { /// Get the IpAddress based on requestType. dynamic data = await ipAddress.getIpAddress(); setState(() { - deviceIP = data.toString(); + publicIP = data.toString(); }); } on IpAddressException catch (exception) { /// Handle the exception. @@ -54,95 +84,87 @@ class _WiredScreenState extends State<WiredScreen> { context.flow<AppState>().update((state) => AppState.settings); }, ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 120, vertical: 40), - padding: const EdgeInsets.symmetric(vertical: 17, horizontal: 24), - height: 140, - alignment: Alignment.center, - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.centerLeft, - end: Alignment.centerRight, - stops: const [ - 0, - 0.01, - 0.8 - ], - colors: <Color>[ - Colors.white, - AGLDemoColors.neonBlueColor, - AGLDemoColors.neonBlueColor.withOpacity(0.15) - ]), - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // const SizedBox( - // width: 20, - // ), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const Text( - 'hernet_0090451v407b_cable', - style: TextStyle(color: Colors.white, fontSize: 40), - ), - Text( - 'connected, $deviceIP', - style: - const TextStyle(color: Colors.white, fontSize: 26), - ), - ], + Expanded(child: ListView.separated( + padding: const EdgeInsets.symmetric(horizontal: 120, vertical: 40), + separatorBuilder: (BuildContext context, int index) => const SizedBox(height: 24), + itemCount: interfaces.length, + itemBuilder: (BuildContext context, int index) { + if (index >= interfaces.length) + return null; + final String deviceName = interfaces[index].deviceName; + bool connected = interfaces[index].deviceIP != null; + final String deviceIP = interfaces[index].deviceIP ?? "N/A"; + return Container( + padding: const EdgeInsets.symmetric(vertical: 17, horizontal: 24), + height: 140, + alignment: Alignment.center, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.centerLeft, + end: Alignment.centerRight, + stops: const [ + 0, + 0.01, + 0.8 + ], + colors: <Color>[ + Colors.white, + AGLDemoColors.neonBlueColor, + AGLDemoColors.neonBlueColor.withOpacity(0.15) + ]), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // const SizedBox( + // width: 20, + // ), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + deviceName, + style: const TextStyle(color: Colors.white, fontSize: 40), + ), + Text( + connected ? 'connected, $deviceIP' : 'disconnected', + style: const TextStyle(color: Colors.white, fontSize: 26), + ), + ], + ), ), - ), - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(4), - color: AGLDemoColors.buttonFillEnabledColor, - border: Border.all(color: AGLDemoColors.neonBlueColor), - boxShadow: [Helpers.boxDropShadowRegular]), - child: Material( - color: Colors.transparent, - child: InkWell( - onTap: () {}, - borderRadius: BorderRadius.circular(4), - child: const Padding( - padding: - EdgeInsets.symmetric(vertical: 30, horizontal: 40), - child: Text( - "Configure", - style: TextStyle( - color: AGLDemoColors.periwinkleColor, - fontSize: 26), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4), + color: AGLDemoColors.buttonFillEnabledColor, + border: Border.all(color: AGLDemoColors.neonBlueColor), + boxShadow: [Helpers.boxDropShadowRegular]), + child: Material( + color: Colors.transparent, + child: InkWell( + onTap: () {}, + borderRadius: BorderRadius.circular(4), + child: const Padding( + padding: + EdgeInsets.symmetric(vertical: 30, horizontal: 40), + child: Text( + "Configure", + style: TextStyle( + color: AGLDemoColors.periwinkleColor, + fontSize: 26), + ), ), ), ), ), - ), - // ElevatedButton( - // style: ElevatedButton.styleFrom( - // backgroundColor: const Color(0xFF1C2D92), - // side: - // const BorderSide(color: Color(0xFF285DF4), width: 2), - // ), - // child: const Padding( - // padding: - // EdgeInsets.symmetric(vertical: 15.0, horizontal: 0), - // child: Text( - // 'Configure', - // style: TextStyle( - // color: Color(0xFFC1D8FF), - // fontSize: 26, - // ), - // ), - // ), - // onPressed: () {}, - // ), - ]), - ), + ] + ), + ); + }, + )), ], ); } |