aboutsummaryrefslogtreecommitdiffstats
path: root/lib/presentation/screens
diff options
context:
space:
mode:
authorTomi Leppänen <tomi.leppanen@seafarix.com>2024-09-13 17:13:58 +0300
committerTomi Leppänen <tomi.leppanen@seafarix.com>2024-11-29 18:11:04 +0200
commitecc867e1e320ccb248a75c1b800eab444f4c904f (patch)
tree667b5fb60ef5412bdfc64f6516655ab7dbe5a57e /lib/presentation/screens
parent9fcc67f7c92d2db9b89a1139533f8825a3834b2a (diff)
Make wired network settings functional
Fetch all network devices and show local IP. This removes public IP from display but leaves the code to fetch it for possible future use. Note that this does not attempt to filter out wireless or virtual network devices so those may be shown on Wired page now. Bug-AGL: SPEC-5296 Change-Id: I52de896ed3827c86782ee1cf29208a295532c3f2 Signed-off-by: Tomi Leppänen <tomi.leppanen@seafarix.com>
Diffstat (limited to 'lib/presentation/screens')
-rw-r--r--lib/presentation/screens/settings/settings_screens/wired/wired_screen.dart198
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: () {},
- // ),
- ]),
- ),
+ ]
+ ),
+ );
+ },
+ )),
],
);
}