From e5501b6c3a093b33ff6d35a749acac6ac23f8d61 Mon Sep 17 00:00:00 2001 From: Daazed McFarland Date: Sun, 5 May 2024 21:06:16 -0700 Subject: [PATCH] get ip with the rest of creds --- .vscode/settings.json | 12 +++++++++++ lib/controllers/wipi_controller.dart | 25 ++++++++++++++++------- lib/models/saved_connections.dart | 10 ++++++---- lib/views/wipi_home.dart | 20 ++++++++++++++++++- test/widget_test.dart | 30 ---------------------------- 5 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 test/widget_test.dart diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..90a3aa8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "cSpell.words": [ + "creds", + "getx", + "Getx", + "Hotspot", + "keymgmt", + "localip", + "mgmt", + "wipi" + ] +} \ No newline at end of file diff --git a/lib/controllers/wipi_controller.dart b/lib/controllers/wipi_controller.dart index af573d6..1f9759f 100644 --- a/lib/controllers/wipi_controller.dart +++ b/lib/controllers/wipi_controller.dart @@ -1,8 +1,9 @@ +import 'package:flutter/foundation.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:wipi/models/saved_connections.dart'; -const String baseUrl = 'http://192.168.0.174/'; +const String baseUrl = 'http://192.168.6.9/'; const String showConnections = '${baseUrl}rec_creds?show_connections'; const String showCredentials = '${baseUrl}rec_creds?show_credentials='; const String deleteCredentials = '${baseUrl}rec_creds?delete_credentials='; @@ -22,6 +23,7 @@ class WiPiController extends GetxController { final displaySsid = "".obs; final displayPass = "".obs; final displayKeymgmt = "".obs; + final displayIpAddr = "".obs; bool connected = false; void fetchSavedConnections() async { @@ -38,12 +40,17 @@ class WiPiController extends GetxController { getDeleteColor(); final response = await getx.get("$showCredentials${wifiInfo.value}"); creds = response.body; + if (kDebugMode) { + print(creds); + } for (String key in creds.keys) { displayConnections = { key: Connection( - ssid: creds[key]["ssid"], - keymgmt: creds[key]["key-mgmt"], - psk: creds[key]["psk"]) + ssid: creds[key]["ssid"], + keymgmt: creds[key]["key-mgmt"], + psk: creds[key]["psk"], + localip: creds[key]["local-ip"], + ), }; } displayCredentials(); @@ -51,18 +58,22 @@ class WiPiController extends GetxController { void postCredentials() async { // print('Sending Credentials'); + await Future.delayed(const Duration(seconds: 10)); final response = await getx.post(sendCredentials, {"SSID": ssid, "PASS": pass}); - if (response.body == "Connected") { - connected = true; - fetchSavedConnections(); + if (kDebugMode) { + print(response.body); } + // displayIpAddr.value = response.body["local_ip"]; + // connected = true; + fetchSavedConnections(); } void displayCredentials() { displaySsid.value = displayConnections[wifiInfo.value]!.ssid; displayKeymgmt.value = displayConnections[wifiInfo.value]!.keymgmt; displayPass.value = displayConnections[wifiInfo.value]!.psk; + displayIpAddr.value = displayConnections[wifiInfo.value]!.localip; } void removeCredentials(connection) async { diff --git a/lib/models/saved_connections.dart b/lib/models/saved_connections.dart index 3ec9991..1829394 100644 --- a/lib/models/saved_connections.dart +++ b/lib/models/saved_connections.dart @@ -1,11 +1,13 @@ class Connection { - final String ssid; - final String keymgmt; - final String psk; + late final String ssid; + late final String keymgmt; + late final String psk; + late final String localip; - const Connection({ + Connection({ required this.ssid, required this.keymgmt, required this.psk, + required this.localip, }); } diff --git a/lib/views/wipi_home.dart b/lib/views/wipi_home.dart index e7ed961..643231b 100644 --- a/lib/views/wipi_home.dart +++ b/lib/views/wipi_home.dart @@ -28,7 +28,10 @@ class WiPiHome extends StatelessWidget { ), child: DropdownButton( hint: const Text( - 'Choose SSID', + style: TextStyle( + color: Colors.white, + ), + 'Cannot find device', ), onChanged: (newValue) { wipiController.wifiInfo(newValue); @@ -120,6 +123,21 @@ class WiPiHome extends StatelessWidget { ), ), ), + Card( + color: Colors.black, + child: Container( + margin: const EdgeInsets.all(0), + child: ListTile( + shape: const RoundedRectangleBorder(), + tileColor: Colors.grey[800], + title: Text( + style: const TextStyle(color: Colors.white), + wipiController.displayIpAddr.value), + leading: const Text( + style: TextStyle(color: Colors.white), "local_ip: "), + ), + ), + ), ], ), ), diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index a44b173..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:wipi/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}