|
1 | 1 | import 'package:flutter/material.dart'; |
2 | 2 | import 'package:provider/provider.dart'; |
3 | 3 | import '../../app_states/ble_app_state.dart'; |
| 4 | +import 'dart:convert'; |
| 5 | + |
| 6 | +import 'package:robot_app/ble_files/services/ble_connection/ble_interface.dart'; |
| 7 | +import '../../ble_files/widgets/ble_connect_button.dart'; |
| 8 | +import '../../ble_files/services/robot_profiles.dart'; |
| 9 | + |
4 | 10 |
|
5 | | -// Wifi has not been implemented, this page just contains a button that toggles wifi state and has no real backend |
6 | 11 |
|
| 12 | +// Wifi has not been implemented, this page just contains a button that toggles wifi state and has no real backend |
7 | 13 | class WifiPage extends StatelessWidget { |
8 | 14 | const WifiPage({super.key}); |
9 | 15 |
|
10 | 16 | @override |
11 | 17 | Widget build(BuildContext context) { |
| 18 | + // You need to grab the bleDriver from the provider to use it inside the button |
| 19 | + final bleDriver = context.read<BleInterface>(); |
| 20 | + final TextEditingController _ssidController = TextEditingController(); |
| 21 | + final TextEditingController _passController = TextEditingController(); |
| 22 | + |
12 | 23 | return Center( |
13 | | - child: SizedBox( |
14 | | - width: 180, |
15 | | - height: 60, |
16 | | - child: ElevatedButton( |
17 | | - onPressed: () { |
18 | | - context.read<AppState>().toggleWifi(); |
19 | | - }, |
20 | | - child: const Text('Toggle WiFi', style: TextStyle(fontSize: 18)), |
21 | | - ), |
| 24 | + child: Column( // Use a Column so buttons don't overlap in the SizedBox |
| 25 | + mainAxisAlignment: MainAxisAlignment.center, |
| 26 | + children: [ |
| 27 | + TextField(//Text field where you input the ssid of the wifi |
| 28 | + controller: _ssidController, |
| 29 | + decoration: InputDecoration(labelText: 'Wi-Fi Name (SSID)'), |
| 30 | + ), |
| 31 | + TextField(//Text where you input the wifi password |
| 32 | + controller: _passController, |
| 33 | + obscureText: true, |
| 34 | + decoration: InputDecoration(labelText: 'Password'), |
| 35 | + ), |
| 36 | + SizedBox( |
| 37 | + width: 250, |
| 38 | + height: 60, |
| 39 | + child: ElevatedButton( |
| 40 | + onPressed: () { |
| 41 | + context.read<AppState>().toggleWifi(); |
| 42 | + }, |
| 43 | + child: const Text('Toggle App State WiFi', style: TextStyle(fontSize: 18)), |
| 44 | + ), |
| 45 | + ), |
| 46 | + const SizedBox(height: 20), |
| 47 | + SizedBox( |
| 48 | + width: 250, |
| 49 | + height: 60, |
| 50 | + child: ElevatedButton( |
| 51 | + onPressed: () async { // Fixed the syntax: onPressed: () async { ... } |
| 52 | + try { |
| 53 | + // This command tells the robot to start a Wi-Fi Scan |
| 54 | + await bleDriver.writeToCharacteristic(utf8.encode('N#1#${_ssidController.text}#${_passController.text}#')); |
| 55 | + debugPrint("Wi-Fi Scan Command Sent!"); |
| 56 | + } catch (e) { |
| 57 | + debugPrint("BLE Write Error: $e"); |
| 58 | + } |
| 59 | + }, |
| 60 | + child: const Text('Send Wifi info to Robot'), |
| 61 | + ), |
| 62 | + ), |
| 63 | + ], |
22 | 64 | ), |
23 | 65 | ); |
24 | 66 | } |
|
0 commit comments