diff --git a/lib/data/rest_request.dart b/lib/data/rest_request.dart deleted file mode 100644 index 8db1578..0000000 --- a/lib/data/rest_request.dart +++ /dev/null @@ -1,247 +0,0 @@ -import 'dart:io'; - -import 'package:http/http.dart' as http; -import 'dart:convert'; - -import 'package:panduza_sandbox_flutter/data/company.dart'; - -String baseCloudUrl = "http://192.168.97.180:8000/"; - -// lucas address : 192.168.97.180 - -// Change url to swap to cloud api or local - - -// Create first account -Future createFirstAccount(String username, String password) async { - - String url = '${baseCloudUrl}first_register/'; - - - Map body = { - 'username' : username, - 'password' : password - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: {"Content-Type": "application/json"}, - body: encodedBody - ); - - return response; -} - -// login -Future login(String username, String password) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'username' : username, - 'password' : password - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: {"Content-Type": "application/json"}, - body: encodedBody - ); - - return response; -} - -// get cloud information (broker address/ broker port/ certificat) -Future getBrokerInfo(String token) async { - - String url = '${baseCloudUrl}first_register/'; - - var response = await http.get( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - } - ); - - return response; -} - -// set cloud info (company name, broker address, broker port, certificat) -Future postBrokerInfo(String token, Company company) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'company_name' : company.companyName, - 'broker_address' : company.brokerAddress, - 'broker_port' : company.brokerPort, - 'certificat' : company.certificat - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - -// Add account user or admin -Future addAccount(String token, - String username, String password, bool isAdmin) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'username' : username, - 'password' : password, - 'is_admin' : isAdmin - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - -// Get bench -Future getBench(String token) async { - - String url = '${baseCloudUrl}first_register/'; - - var response = await http.get( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - } - ); - - return response; -} - - -// Post a new bench with name -Future postBench(String token, String name) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'name' : name - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - -// Post a new device with name and type -Future postDevice(String token, String name, String type) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'name' : name, - "type" : type - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.post( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - -// Link a device to a bench -Future putDeviceInBench(String token, int benchId, int deviceId) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'id' : benchId, - 'devices': [ - deviceId - ] - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.put( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - - -// Delete a device (it will be delete of the bench) -Future delDevice(String token, int id) async { - - String url = '${baseCloudUrl}first_register/'; - - Map body = { - 'id' : id - }; - - // encode Map to json - String encodedBody = json.encode(body); - - var response = await http.delete( - Uri.parse(url), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - body: encodedBody - ); - - return response; -} - diff --git a/lib/forms/add_bench_to_config_form.dart b/lib/forms/add_bench_to_config_form.dart index 373768b..557f732 100644 --- a/lib/forms/add_bench_to_config_form.dart +++ b/lib/forms/add_bench_to_config_form.dart @@ -1,8 +1,6 @@ -import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/rest_request.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; // Form to add a new manual connection // The user can add on his disk a new setup of connection mqtt @@ -50,21 +48,11 @@ class AddBenchToConfigForm extends StatelessWidget { // Connect to the broker with the info of username and password given ElevatedButton( onPressed: () { - // Send a request to api to created a new bench - postBench(token, ctrlName.text).then((value) { - - // instead to keep a copy of the data we can make a - // new request to get every bench to the API - - getBench(token).then((response) { - Map responseObject = json.decode(response.body); - Navigator.pop(context, responseObject["bench"]); - }); - }); + // TO DO when cloud will be more advanced }, // Show error message if unsuccessful connection style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(blue) + backgroundColor: WidgetStateProperty.all(blue) ), child: Text( 'SAVE', diff --git a/lib/forms/add_connection_form.dart b/lib/forms/add_connection_form.dart index 3691c03..2440038 100644 --- a/lib/forms/add_connection_form.dart +++ b/lib/forms/add_connection_form.dart @@ -1,11 +1,9 @@ -import 'dart:ffi'; - import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/connections_page.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/utils.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_functions.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; // Form to add a new manual connection // The user can add on his disk a new setup of connection mqtt diff --git a/lib/forms/add_device_to_bench_form.dart b/lib/forms/add_device_to_bench_form.dart index 38d2a16..3cf0864 100644 --- a/lib/forms/add_device_to_bench_form.dart +++ b/lib/forms/add_device_to_bench_form.dart @@ -1,11 +1,6 @@ -import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/rest_request.dart'; -import 'package:panduza_sandbox_flutter/data/utils.dart'; -import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/userspace_page.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; // Form to add a new manual connection // The user can add on his disk a new setup of connection mqtt @@ -63,16 +58,7 @@ class AddDeviceToBenchForm extends StatelessWidget { // Connect to the broker with the info of username and password given ElevatedButton( onPressed: () { - // Send a request to api to created a new device - postDevice(token, ctrlName.text, ctrlType.text).then((response) { - - var responseObject = json.decode(response.body); - - // then link this new device to the targeted bench - putDeviceInBench(token, benchId, responseObject["id"]).then((value) { - Navigator.pop(context); - }); - }); + // TO DO when cloud will be more advanced }, // Show error message if unsuccessful connection style: ButtonStyle( diff --git a/lib/forms/authentification_form.dart b/lib/forms/authentification_form.dart index f45b5e9..8c3ce84 100644 --- a/lib/forms/authentification_form.dart +++ b/lib/forms/authentification_form.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/utils.dart'; -import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/userspace_page.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_functions.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/broker_connection_info.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/userspace_page.dart'; // Form to add a new manual connection // The user can add on his disk a new setup of connection mqtt @@ -69,7 +69,7 @@ class AuthentificationForm extends StatelessWidget { context, MaterialPageRoute( builder: (context) => UserspacePage( - broker_connection_info: BrokerConnectionInfo( + brokerConnectionInfo: BrokerConnectionInfo( ip, int.parse(port), client diff --git a/lib/forms/cloud_auth_form.dart b/lib/forms/cloud_auth_form.dart index b6dcfb1..c3fd237 100644 --- a/lib/forms/cloud_auth_form.dart +++ b/lib/forms/cloud_auth_form.dart @@ -1,9 +1,7 @@ -import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/rest_request.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; // Form to add a new manual connection // The user can add on his disk a new setup of connection mqtt @@ -58,42 +56,7 @@ class CloudAuthForm extends StatelessWidget { // Connect to the broker with the info of username and password given ElevatedButton( onPressed: () { - // connect to the api admin, get broker info before change of page - login(ctrlUsername.text, ctrlPassword.text).then((tokenResponse) { - if (tokenResponse.statusCode == 200) { - String token = json.decode(tokenResponse.body)['access']; - getBrokerInfo(token).then((brokerInfoResponse) { - if (brokerInfoResponse.statusCode == 200) { - // deserialize the company object into a object (maybe it could be - // made alone with a function deserialize or something) - Map responseObject = json.decode(brokerInfoResponse.body); - - String companyName = responseObject["company_name"]; - String brokerAddress = responseObject["broker_address"]; - String brokerPort = responseObject["broker_port"]; - String certificat = responseObject["certificat"]; - - /* - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CloudConfigPage( - token: token, - company: Company(companyName, brokerAddress, brokerPort, certificat) - ) - ), - ); - */ - } else { - // mangage error code - print("error with get broker info request : ${brokerInfoResponse.statusCode}"); - } - }); - } else { - // manage error code - print("error with login request : ${tokenResponse.statusCode}"); - } - }); + // TO DO when cloud will more advanced }, // Show error message if unsuccessful connection style: ButtonStyle( diff --git a/lib/forms/edit_connection_form.dart b/lib/forms/edit_connection_form.dart index 020aa4f..a76b405 100644 --- a/lib/forms/edit_connection_form.dart +++ b/lib/forms/edit_connection_form.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/utils.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_functions.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; // Form to edit a existing connection diff --git a/lib/main.dart b/lib/main.dart index 898da61..6318f1a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/choice_cloud_self_managed_page.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/choice_cloud_self_managed_page.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'data/const.dart'; - // Think about init SharedPreferences only to the start of the application diff --git a/lib/after_setup_pages/add_cloud_or_self_managed.dart b/lib/pages/after_setup_pages/add_cloud_or_self_managed.dart similarity index 63% rename from lib/after_setup_pages/add_cloud_or_self_managed.dart rename to lib/pages/after_setup_pages/add_cloud_or_self_managed.dart index d515d88..d6901bc 100644 --- a/lib/after_setup_pages/add_cloud_or_self_managed.dart +++ b/lib/pages/after_setup_pages/add_cloud_or_self_managed.dart @@ -1,12 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/add_connection_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/add_connection_page.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart'; -import 'package:panduza_sandbox_flutter/forms/add_connection_form.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/cloud_config_auth_page.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/cloud_config_auth_page.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; // Page to give the choice between use the panduza cloud or // use a broker the user has himself init (self-managed broker) diff --git a/lib/after_setup_pages/add_connection_page.dart b/lib/pages/after_setup_pages/add_connection_page.dart similarity index 67% rename from lib/after_setup_pages/add_connection_page.dart rename to lib/pages/after_setup_pages/add_connection_page.dart index 0b0f27a..f51b9a3 100644 --- a/lib/after_setup_pages/add_connection_page.dart +++ b/lib/pages/after_setup_pages/add_connection_page.dart @@ -1,11 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/discovery_page.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/manual_connection_page.dart'; -import 'package:auto_size_text/auto_size_text.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/discovery_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/manual_connection_page.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; // Page with the 2 choices of adding connection : // with manual input, with discovery diff --git a/lib/after_setup_pages/add_connection_with_discovery.dart b/lib/pages/after_setup_pages/add_connection_with_discovery.dart similarity index 92% rename from lib/after_setup_pages/add_connection_with_discovery.dart rename to lib/pages/after_setup_pages/add_connection_with_discovery.dart index cda2a45..63da9cc 100644 --- a/lib/after_setup_pages/add_connection_with_discovery.dart +++ b/lib/pages/after_setup_pages/add_connection_with_discovery.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/add_connection_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page with the 3 choices of adding connection : diff --git a/lib/after_setup_pages/add_device_to_bench_page.dart b/lib/pages/after_setup_pages/add_device_to_bench_page.dart similarity index 84% rename from lib/after_setup_pages/add_device_to_bench_page.dart rename to lib/pages/after_setup_pages/add_device_to_bench_page.dart index 42bffb1..567c240 100644 --- a/lib/after_setup_pages/add_device_to_bench_page.dart +++ b/lib/pages/after_setup_pages/add_device_to_bench_page.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/add_device_to_bench_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/forms/add_device_to_bench_form.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to create the first account diff --git a/lib/after_setup_pages/connections_page.dart b/lib/pages/after_setup_pages/connections_page.dart similarity index 82% rename from lib/after_setup_pages/connections_page.dart rename to lib/pages/after_setup_pages/connections_page.dart index bb7cc1d..bf9632c 100644 --- a/lib/after_setup_pages/connections_page.dart +++ b/lib/pages/after_setup_pages/connections_page.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/add_cloud_or_self_managed.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/choice_cloud_self_managed_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/add_cloud_or_self_managed.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/drawer.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/drawer.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; List platformNames = []; diff --git a/lib/after_setup_pages/device_page.dart b/lib/pages/after_setup_pages/device_page.dart similarity index 76% rename from lib/after_setup_pages/device_page.dart rename to lib/pages/after_setup_pages/device_page.dart index 92e4ea8..4153f33 100644 --- a/lib/after_setup_pages/device_page.dart +++ b/lib/pages/after_setup_pages/device_page.dart @@ -1,33 +1,20 @@ import 'package:flutter/material.dart'; -import 'dart:convert'; -// import '../widgets/interface_control/icw_bpc.dart'; -import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/device_config.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -// import 'package:mqtt_client/mqtt_server_client.dart'; - -// import 'userspace/ic_bpc.dart'; -// import 'userspace/ic_not_managed.dart'; -// import 'userspace/ic_platform.dart'; - -import '../data/interface_connection.dart'; - -// import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; - -import '../data/platform_config.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/device_config.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/platform_config.dart'; class DevicePage extends StatefulWidget { - DevicePage(this._deviceStore, this._platformConfig, this._deviceConfig, + const DevicePage(this._deviceStore, this._deviceConfig, {super.key}); - Map _deviceStore; + final Map _deviceStore; - PlatformConfig _platformConfig; + // PlatformConfig _platformConfig; - DeviceConfig _deviceConfig; + final DeviceConfig _deviceConfig; @override _DevicePageState createState() => _DevicePageState(_deviceConfig); @@ -52,13 +39,13 @@ class _DevicePageState extends State { List childrens = []; if (widget._deviceStore.containsKey(_config.ref)) { - List settings_props = - widget._deviceStore[_config.ref]["settings_props"]; - print(settings_props.toString()); + List settingsProps = + widget._deviceStore[_config.ref]["settingsProps"]; + print(settingsProps.toString()); print(_config.settings); - for (Map prop in settings_props) { + for (Map prop in settingsProps) { if (prop["name"] is String) { final propName = prop['name']; switch (prop["type"]) { diff --git a/lib/after_setup_pages/discovery_page.dart b/lib/pages/after_setup_pages/discovery_page.dart similarity index 97% rename from lib/after_setup_pages/discovery_page.dart rename to lib/pages/after_setup_pages/discovery_page.dart index 1a4cf60..6c8132d 100644 --- a/lib/after_setup_pages/discovery_page.dart +++ b/lib/pages/after_setup_pages/discovery_page.dart @@ -4,8 +4,8 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:auto_size_text/auto_size_text.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; import 'manual_connection_page.dart'; @@ -97,7 +97,7 @@ class _DiscoveryPageState extends State { print("Succes listening on ${address.address}:63500"); } catch(e) { // If not successly listen on this network address - print(e); + print("Error while trying to bind socket : $e"); } } } @@ -110,6 +110,8 @@ class _DiscoveryPageState extends State { socket.send(utf8.encode(jsonEncode({"search" : true})), InternetAddress("255.255.255.255"), portLocalDiscovery); } on SocketException catch(e) { print("Local discovery on ${e.address}:${e.port} failed, error code = ${e.osError?.errorCode}, ${e.osError?.message}"); + } catch(e) { + print("Send failed : $e"); } } } diff --git a/lib/after_setup_pages/edit_page.dart b/lib/pages/after_setup_pages/edit_page.dart similarity index 92% rename from lib/after_setup_pages/edit_page.dart rename to lib/pages/after_setup_pages/edit_page.dart index a4f5368..dbd1101 100644 --- a/lib/after_setup_pages/edit_page.dart +++ b/lib/pages/after_setup_pages/edit_page.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/edit_connection_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page with the 3 choices of adding connection : // with manual input, with discovery or with the cloud diff --git a/lib/after_setup_pages/home/mqtt_connection_form.dart b/lib/pages/after_setup_pages/home/mqtt_connection_form.dart similarity index 88% rename from lib/after_setup_pages/home/mqtt_connection_form.dart rename to lib/pages/after_setup_pages/home/mqtt_connection_form.dart index 1c86dc6..7da9c46 100644 --- a/lib/after_setup_pages/home/mqtt_connection_form.dart +++ b/lib/pages/after_setup_pages/home/mqtt_connection_form.dart @@ -5,22 +5,20 @@ import 'package:flutter/material.dart'; // import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; -import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/userspace_page.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/broker_connection_info.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/userspace_page.dart'; class MqttConnectionForm extends StatefulWidget { - const MqttConnectionForm({Key? key}) : super(key: key); + const MqttConnectionForm({super.key}); @override State createState() => _MqttConnectionFormState(); } class _MqttConnectionFormState extends State { - // final _ctrlHost = TextEditingController(text: "localhost"); - // final _ctrlHost = TextEditingController(text: "192.168.1.39"); + final _ctrlHost = TextEditingController(text: "192.168.1.33"); - // final _ctrlHost = TextEditingController(text: "10.3.141.1"); final _ctrlPort = TextEditingController(text: "1883"); late MqttServerClient _client; bool _isConnecting = false; @@ -118,7 +116,7 @@ class _MqttConnectionFormState extends State { context, MaterialPageRoute( builder: (context) => UserspacePage( - broker_connection_info: BrokerConnectionInfo( + brokerConnectionInfo: BrokerConnectionInfo( getHost(), getPort(), _client), )), ); diff --git a/lib/after_setup_pages/hunt_page.dart b/lib/pages/after_setup_pages/hunt_page.dart similarity index 74% rename from lib/after_setup_pages/hunt_page.dart rename to lib/pages/after_setup_pages/hunt_page.dart index 24b523a..12ff957 100644 --- a/lib/after_setup_pages/hunt_page.dart +++ b/lib/pages/after_setup_pages/hunt_page.dart @@ -1,27 +1,17 @@ import 'package:flutter/material.dart'; import 'dart:convert'; -// import '../widgets/interface_control/icw_bpc.dart'; import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/data/device_config.dart'; -// import 'package:mqtt_client/mqtt_server_client.dart'; - -// import 'userspace/ic_bpc.dart'; -// import 'userspace/ic_not_managed.dart'; -// import 'userspace/ic_platform.dart'; - -import 'package:panduza_sandbox_flutter/data/interface_connection.dart'; - -// import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; - -import '../data/platform_config.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/device_config.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/platform_config.dart'; class HuntPage extends StatefulWidget { - HuntPage(this._interfaceConnection, this._platformConfig, {super.key}); + const HuntPage(this._interfaceConnection, this._platformConfig, {super.key}); final InterfaceConnection _interfaceConnection; - PlatformConfig _platformConfig; + final PlatformConfig _platformConfig; @override State createState() => _HuntPageState(); @@ -42,7 +32,7 @@ class _HuntPageState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -59,12 +49,8 @@ class _HuntPageState extends State { Map store = jsonObject["devices"]["store"]; for (var v in store.keys) { - // print(v); - // print(store[v]); List instances = store[v]["instances"]; - // print("instances"); - // print(instances); if (instances.isNotEmpty) { for (var i in instances) { update.add(i); @@ -91,15 +77,8 @@ class _HuntPageState extends State { widget._interfaceConnection.client.updates!.listen(onMqttMessage); String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; - // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); - - // if (sub != null) { - // print("coool !!"); - // } else { - // print("nullllll"); - // } } /// @@ -138,11 +117,6 @@ class _HuntPageState extends State { Navigator.pop(context, true); }, - // style: ElevatedButton.styleFrom( - // elevation: 0, - // backgroundColor: Colors.green, // Green background - // foregroundColor: Colors.white, // White foreground - // ), child: const Text("Use"), ), ]))); @@ -183,14 +157,8 @@ class _HuntPageState extends State { name: "empty" ) ); - // print(widget._platformConfig.devices.length); Navigator.pop(context, true); }, - // style: ElevatedButton.styleFrom( - // elevation: 0, - // backgroundColor: Colors.green, // Green background - // foregroundColor: Colors.white, // White foreground - // ), child: const Text("Empty"), ), ] diff --git a/lib/after_setup_pages/manual_connection_page.dart b/lib/pages/after_setup_pages/manual_connection_page.dart similarity index 91% rename from lib/after_setup_pages/manual_connection_page.dart rename to lib/pages/after_setup_pages/manual_connection_page.dart index fabc836..e47a9ad 100644 --- a/lib/after_setup_pages/manual_connection_page.dart +++ b/lib/pages/after_setup_pages/manual_connection_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/add_connection_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to add a new connection manually diff --git a/lib/after_setup_pages/platform_page.dart b/lib/pages/after_setup_pages/platform_page.dart similarity index 81% rename from lib/after_setup_pages/platform_page.dart rename to lib/pages/after_setup_pages/platform_page.dart index d287623..fff8dfc 100644 --- a/lib/after_setup_pages/platform_page.dart +++ b/lib/pages/after_setup_pages/platform_page.dart @@ -1,34 +1,14 @@ import 'package:flutter/material.dart'; import 'dart:convert'; -// import '../widgets/interface_control/icw_bpc.dart'; import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -// import 'package:mqtt_client/mqtt_server_client.dart'; - -// import 'userspace/ic_bpc.dart'; -// import 'userspace/ic_not_managed.dart'; -// import 'userspace/ic_platform.dart'; - +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; import 'hunt_page.dart'; - import 'device_page.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/platform_config.dart'; -import '../data/interface_connection.dart'; - -// import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; - -import '../data/platform_config.dart'; - -// class BrokerConnectionInfo { -// String host; -// int port; - -// MqttServerClient client; - -// BrokerConnectionInfo(this.host, this.port, this.client); -// } class PlatformPage extends StatefulWidget { const PlatformPage(this._interfaceConnection, {super.key}); @@ -36,7 +16,7 @@ class PlatformPage extends StatefulWidget { final InterfaceConnection _interfaceConnection; @override - _PlatformPageState createState() => _PlatformPageState(); + State createState() => _PlatformPageState(); } class _PlatformPageState extends State { @@ -51,7 +31,7 @@ class _PlatformPageState extends State { /// void sendConfigToPlatform() { final update = _platformConfig.toMap(); - print("update config = ${update}"); + print("update config = $update"); MqttClientPayloadBuilder builder = MqttClientPayloadBuilder(); @@ -79,7 +59,7 @@ class _PlatformPageState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -97,7 +77,7 @@ class _PlatformPageState extends State { } if (c[0].topic.endsWith('/dtree')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); var jsonObject = json.decode(pt); @@ -123,14 +103,8 @@ class _PlatformPageState extends State { String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); - - // if (sub != null) { - // print("coool !!"); - // } else { - // print("nullllll"); - // } } List deviceListItems() { @@ -147,7 +121,7 @@ class _PlatformPageState extends State { context, MaterialPageRoute( builder: (context) => - DevicePage(_deviceStore, _platformConfig, device)), + DevicePage(_deviceStore, device)), ).then((value) { setState(() {}); }); diff --git a/lib/after_setup_pages/userspace_page.dart b/lib/pages/after_setup_pages/userspace_page.dart similarity index 71% rename from lib/after_setup_pages/userspace_page.dart rename to lib/pages/after_setup_pages/userspace_page.dart index 91f57bf..470da2b 100644 --- a/lib/after_setup_pages/userspace_page.dart +++ b/lib/pages/after_setup_pages/userspace_page.dart @@ -5,25 +5,25 @@ import 'dart:convert'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_blc.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_bpc.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_platform.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_powermeter.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_not_managed.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_video.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_blc.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_bpc.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_platform.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_powermeter.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_not_managed.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_video.dart'; // import '../widgets/interface_control/icw_bpc.dart'; -import 'package:panduza_sandbox_flutter/data/interface_connection.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_relay.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/ic_thermometer.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_relay.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/ic_thermometer.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/broker_connection_info.dart'; class UserspacePage extends StatefulWidget { - const UserspacePage({super.key, required this.broker_connection_info}); + const UserspacePage({super.key, required this.brokerConnectionInfo}); - final BrokerConnectionInfo broker_connection_info; + final BrokerConnectionInfo brokerConnectionInfo; @override State createState() => _UserspacePageState(); @@ -67,28 +67,28 @@ class _UserspacePageState extends State { void initState() { super.initState(); - widget.broker_connection_info.client + widget.brokerConnectionInfo.client .subscribe('pza/+/+/+/atts/info', MqttQos.atLeastOnce); MqttClientPayloadBuilder builder = MqttClientPayloadBuilder(); builder.addString('*'); final payload = builder.payload; - widget.broker_connection_info.client + widget.brokerConnectionInfo.client .publishMessage('pza', MqttQos.atLeastOnce, payload!); - Future.delayed(Duration(milliseconds: 1), () async { + Future.delayed(const Duration(milliseconds: 1), () async { // Run your async function here // await myAsyncFunction(); - mqttSubscription = widget.broker_connection_info.client.updates! + mqttSubscription = widget.brokerConnectionInfo.client.updates! .listen((List> c) { - if (c![0].topic.startsWith("pza") & c![0].topic.endsWith("atts/info")) { - final recMess = c![0].payload as MqttPublishMessage; + if (c[0].topic.startsWith("pza") & c[0].topic.endsWith("atts/info")) { + final recMess = c[0].payload as MqttPublishMessage; - var topic = c![0] + var topic = c[0] .topic - .substring(0, c![0].topic.length - "/atts/info".length); + .substring(0, c[0].topic.length - "/atts/info".length); final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -98,7 +98,7 @@ class _UserspacePageState extends State { // print(jsonObject); InterfaceConnection ic = InterfaceConnection( - widget.broker_connection_info.client, topic, jsonObject["info"]); + widget.brokerConnectionInfo.client, topic, jsonObject["info"]); if (!interfaceAlreadyRegistered(ic)) { if (ic.getType() != "device") { diff --git a/lib/setup_pages/add_bench_to_config_page.dart b/lib/pages/setup_pages/add_bench_to_config_page.dart similarity index 90% rename from lib/setup_pages/add_bench_to_config_page.dart rename to lib/pages/setup_pages/add_bench_to_config_page.dart index 630d787..b1094ac 100644 --- a/lib/setup_pages/add_bench_to_config_page.dart +++ b/lib/pages/setup_pages/add_bench_to_config_page.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/add_bench_to_config_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to create the first account diff --git a/lib/setup_pages/authentification_page.dart b/lib/pages/setup_pages/authentification_page.dart similarity index 91% rename from lib/setup_pages/authentification_page.dart rename to lib/pages/setup_pages/authentification_page.dart index 0e93f5d..10dbc20 100644 --- a/lib/setup_pages/authentification_page.dart +++ b/lib/pages/setup_pages/authentification_page.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/authentification_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to authentificate to a broker diff --git a/lib/setup_pages/choice_cloud_self_managed_page.dart b/lib/pages/setup_pages/choice_cloud_self_managed_page.dart similarity index 85% rename from lib/setup_pages/choice_cloud_self_managed_page.dart rename to lib/pages/setup_pages/choice_cloud_self_managed_page.dart index c1562e5..80bb6d6 100644 --- a/lib/setup_pages/choice_cloud_self_managed_page.dart +++ b/lib/pages/setup_pages/choice_cloud_self_managed_page.dart @@ -1,13 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/add_connection_page.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/add_connection_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/connections_page.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/utils_widgets.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/cloud_config_auth_page.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/cloud_config_auth_page.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to give the choice between use the panduza cloud or // use a broker the user has himself init diff --git a/lib/setup_pages/cloud_config_auth_page.dart b/lib/pages/setup_pages/cloud_config_auth_page.dart similarity index 81% rename from lib/setup_pages/cloud_config_auth_page.dart rename to lib/pages/setup_pages/cloud_config_auth_page.dart index f7dcd7f..d5820a8 100644 --- a/lib/setup_pages/cloud_config_auth_page.dart +++ b/lib/pages/setup_pages/cloud_config_auth_page.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:panduza_sandbox_flutter/forms/cloud_auth_form.dart'; -import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart'; -import 'package:panduza_sandbox_flutter/forms/authentification_form.dart'; +import 'package:panduza_sandbox_flutter/widgets/utils_widgets/appBar.dart'; // Page to create the first account diff --git a/lib/data/const.dart b/lib/utils/const.dart similarity index 100% rename from lib/data/const.dart rename to lib/utils/const.dart diff --git a/lib/data/utils.dart b/lib/utils/utils_functions.dart similarity index 99% rename from lib/data/utils.dart rename to lib/utils/utils_functions.dart index 3c9e321..689e651 100644 --- a/lib/data/utils.dart +++ b/lib/utils/utils_functions.dart @@ -1,13 +1,13 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; late MqttServerClient _client; bool _isConnecting = false; diff --git a/lib/data/broker_connection_info.dart b/lib/utils/utils_objects/broker_connection_info.dart similarity index 100% rename from lib/data/broker_connection_info.dart rename to lib/utils/utils_objects/broker_connection_info.dart diff --git a/lib/data/company.dart b/lib/utils/utils_objects/company.dart similarity index 100% rename from lib/data/company.dart rename to lib/utils/utils_objects/company.dart diff --git a/lib/data/device_config.dart b/lib/utils/utils_objects/device_config.dart similarity index 100% rename from lib/data/device_config.dart rename to lib/utils/utils_objects/device_config.dart diff --git a/lib/data/interface_connection.dart b/lib/utils/utils_objects/interface_connection.dart similarity index 100% rename from lib/data/interface_connection.dart rename to lib/utils/utils_objects/interface_connection.dart diff --git a/lib/data/platform_config.dart b/lib/utils/utils_objects/platform_config.dart similarity index 97% rename from lib/data/platform_config.dart rename to lib/utils/utils_objects/platform_config.dart index ded3141..55a615a 100644 --- a/lib/data/platform_config.dart +++ b/lib/utils/utils_objects/platform_config.dart @@ -1,5 +1,4 @@ import 'device_config.dart'; -import 'dart:convert'; class PlatformConfig { List devices = []; diff --git a/lib/userspace_widgets/ic_blc.dart b/lib/widgets/userspace_widgets/ic_blc.dart similarity index 98% rename from lib/userspace_widgets/ic_blc.dart rename to lib/widgets/userspace_widgets/ic_blc.dart index 1476ee2..bad526e 100644 --- a/lib/userspace_widgets/ic_blc.dart +++ b/lib/widgets/userspace_widgets/ic_blc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'templates.dart'; -import '../../data/interface_connection.dart'; +import '../../utils/utils_objects/interface_connection.dart'; import 'dart:convert'; @@ -58,7 +58,7 @@ class _IcBlcState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -193,7 +193,7 @@ class _IcBlcState extends State { String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); } @@ -442,7 +442,7 @@ class _IcBlcState extends State { ), child: const Text("Apply"), ), - Spacer(), + const Spacer(), Switch( value: _enableValueEff!, onChanged: enableValueSwitchOnChanged()), diff --git a/lib/userspace_widgets/ic_bpc.dart b/lib/widgets/userspace_widgets/ic_bpc.dart similarity index 96% rename from lib/userspace_widgets/ic_bpc.dart rename to lib/widgets/userspace_widgets/ic_bpc.dart index b68f657..1a007cf 100644 --- a/lib/userspace_widgets/ic_bpc.dart +++ b/lib/widgets/userspace_widgets/ic_bpc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'templates.dart'; -import '../../data/interface_connection.dart'; +import '../../utils/utils_objects/interface_connection.dart'; import 'dart:convert'; @@ -39,7 +39,7 @@ class _IcBpcState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -97,7 +97,7 @@ class _IcBpcState extends State { String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); } @@ -292,7 +292,7 @@ class _IcBpcState extends State { ), child: const Text("Apply"), ), - Spacer(), + const Spacer(), Switch( value: _enableValueEff!, onChanged: enableValueSwitchOnChanged()), @@ -301,7 +301,7 @@ class _IcBpcState extends State { ], )); } else { - return Card(); + return const Card(); } } } diff --git a/lib/userspace_widgets/ic_not_managed.dart b/lib/widgets/userspace_widgets/ic_not_managed.dart similarity index 65% rename from lib/userspace_widgets/ic_not_managed.dart rename to lib/widgets/userspace_widgets/ic_not_managed.dart index 214cb8e..141dcae 100644 --- a/lib/userspace_widgets/ic_not_managed.dart +++ b/lib/widgets/userspace_widgets/ic_not_managed.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'templates.dart'; -import '../../data/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; class IcNotManaged extends StatefulWidget { - IcNotManaged(this._interfaceConnection); + const IcNotManaged(this._interfaceConnection, {super.key}); - InterfaceConnection _interfaceConnection; + final InterfaceConnection _interfaceConnection; @override State createState() => _IcNotManagedState(); diff --git a/lib/userspace_widgets/ic_platform.dart b/lib/widgets/userspace_widgets/ic_platform.dart similarity index 85% rename from lib/userspace_widgets/ic_platform.dart rename to lib/widgets/userspace_widgets/ic_platform.dart index 927ddae..0c8647e 100644 --- a/lib/userspace_widgets/ic_platform.dart +++ b/lib/widgets/userspace_widgets/ic_platform.dart @@ -1,18 +1,19 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; + import 'package:mqtt_client/mqtt_client.dart'; -import '../../data/interface_connection.dart'; -import 'dart:convert'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/platform_page.dart'; import 'templates.dart'; -import '../after_setup_pages/platform_page.dart'; - class IcPlatform extends StatefulWidget { - IcPlatform(this._interfaceConnection); + const IcPlatform(this._interfaceConnection, {super.key}); - InterfaceConnection _interfaceConnection; + final InterfaceConnection _interfaceConnection; @override - _IcPlatformState createState() => _IcPlatformState(); + State createState() => _IcPlatformState(); } class _IcPlatformState extends State { @@ -49,7 +50,7 @@ class _IcPlatformState extends State { final payload = builder.payload; widget._interfaceConnection.client.publishMessage( - widget._interfaceConnection.topic + "/cmds/set", + "${widget._interfaceConnection.topic}/cmds/set", MqttQos.atLeastOnce, payload!); } diff --git a/lib/userspace_widgets/ic_powermeter.dart b/lib/widgets/userspace_widgets/ic_powermeter.dart similarity index 87% rename from lib/userspace_widgets/ic_powermeter.dart rename to lib/widgets/userspace_widgets/ic_powermeter.dart index d4c6e5f..537ec3d 100644 --- a/lib/userspace_widgets/ic_powermeter.dart +++ b/lib/widgets/userspace_widgets/ic_powermeter.dart @@ -1,16 +1,14 @@ import 'dart:async'; +import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'templates.dart'; -import '../../data/interface_connection.dart'; - -import 'dart:convert'; - -// import '../widgets/interface_control/icw_bpc.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; import 'package:mqtt_client/mqtt_client.dart'; + class IcPowermeter extends StatefulWidget { const IcPowermeter(this._interfaceConnection, {super.key}); @@ -36,7 +34,7 @@ class _IcPowermeterState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -53,15 +51,15 @@ class _IcPowermeterState extends State { switch (atts.key) { case "measure": if (field.key == "value") { - double update_val = 0; + double updateVal = 0; switch (field.value.runtimeType) { case int: - update_val = field.value.toDouble(); + updateVal = field.value.toDouble(); case double: - update_val = field.value; + updateVal = field.value; } setState(() { - _value = update_val; + _value = updateVal; }); } break; @@ -82,13 +80,12 @@ class _IcPowermeterState extends State { String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); } late TextEditingController _freqController; - late TextEditingController _freqControllerRequested; /// Perform MQTT Subscriptions at the start of the component /// diff --git a/lib/userspace_widgets/ic_relay.dart b/lib/widgets/userspace_widgets/ic_relay.dart similarity index 89% rename from lib/userspace_widgets/ic_relay.dart rename to lib/widgets/userspace_widgets/ic_relay.dart index 3a0f825..203117a 100644 --- a/lib/userspace_widgets/ic_relay.dart +++ b/lib/widgets/userspace_widgets/ic_relay.dart @@ -1,13 +1,11 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -// import '../widgets/interface_control/icw_bpc.dart'; import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/userspace_widgets/templates.dart'; -import 'package:panduza_sandbox_flutter/data/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/templates.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; class IcRelay extends StatefulWidget { const IcRelay(this._interfaceConnection, { @@ -32,7 +30,7 @@ class _IcRelayState extends State { if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -73,7 +71,7 @@ class _IcRelayState extends State { await Future.delayed(const Duration(milliseconds: 400)); String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); } diff --git a/lib/userspace_widgets/ic_thermometer.dart b/lib/widgets/userspace_widgets/ic_thermometer.dart similarity index 91% rename from lib/userspace_widgets/ic_thermometer.dart rename to lib/widgets/userspace_widgets/ic_thermometer.dart index 71717a0..058e286 100644 --- a/lib/userspace_widgets/ic_thermometer.dart +++ b/lib/widgets/userspace_widgets/ic_thermometer.dart @@ -1,16 +1,14 @@ import 'dart:async'; +import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'templates.dart'; -import '../../data/interface_connection.dart'; - -import 'dart:convert'; - -// import '../widgets/interface_control/icw_bpc.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; import 'package:mqtt_client/mqtt_client.dart'; + class IcThermometer extends StatefulWidget { const IcThermometer(this._interfaceConnection, {super.key}); @@ -34,7 +32,7 @@ class _IcThermometerState extends State { // if (c[0].topic.startsWith(widget._interfaceConnection.topic)) { if (!c[0].topic.endsWith('/info')) { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message); @@ -81,13 +79,12 @@ class _IcThermometerState extends State { String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; // print(attsTopic); - Subscription? sub = widget._interfaceConnection.client + widget._interfaceConnection.client .subscribe(attsTopic, MqttQos.atLeastOnce); } late TextEditingController _freqController; - late TextEditingController _freqControllerRequested; /// Perform MQTT Subscriptions at the start of the component /// diff --git a/lib/userspace_widgets/ic_video.dart b/lib/widgets/userspace_widgets/ic_video.dart similarity index 89% rename from lib/userspace_widgets/ic_video.dart rename to lib/widgets/userspace_widgets/ic_video.dart index 976a457..d6454d3 100644 --- a/lib/userspace_widgets/ic_video.dart +++ b/lib/widgets/userspace_widgets/ic_video.dart @@ -3,9 +3,8 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:mqtt_client/mqtt_client.dart'; -import 'package:panduza_sandbox_flutter/data/interface_connection.dart'; - -import 'package:panduza_sandbox_flutter/userspace_widgets/templates.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; +import 'package:panduza_sandbox_flutter/widgets/userspace_widgets/templates.dart'; class IcVideo extends StatefulWidget { const IcVideo(this._interfaceConnection, @@ -31,7 +30,7 @@ class _IcVideoState extends State { // init the receving of frame on some topic (maybe add some topic) void initFrameRecevingMqtt() { - Future.delayed(Duration(milliseconds: 1), () { + Future.delayed(const Duration(milliseconds: 1), () { // Subscribe to receive message link to video String attsTopic = "${widget._interfaceConnection.topic}/atts/#"; @@ -55,9 +54,9 @@ class _IcVideoState extends State { mqttSubscription = widget._interfaceConnection.client.updates! .listen((List> c) { - if (c![0].topic == "${widget._interfaceConnection.topic}/atts/frame") { + if (c[0].topic == "${widget._interfaceConnection.topic}/atts/frame") { - final recMess = c![0].payload as MqttPublishMessage; + final recMess = c[0].payload as MqttPublishMessage; // Reading frame and putting it on the video stream diff --git a/lib/userspace_widgets/templates.dart b/lib/widgets/userspace_widgets/templates.dart similarity index 86% rename from lib/userspace_widgets/templates.dart rename to lib/widgets/userspace_widgets/templates.dart index 9a567e8..928fe44 100644 --- a/lib/userspace_widgets/templates.dart +++ b/lib/widgets/userspace_widgets/templates.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import '../../data/interface_connection.dart'; + +import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart'; Widget cardHeadLine(InterfaceConnection ic) { return ListTile( diff --git a/lib/utils_widgets/appBar.dart b/lib/widgets/utils_widgets/appBar.dart similarity index 90% rename from lib/utils_widgets/appBar.dart rename to lib/widgets/utils_widgets/appBar.dart index 5c49b1a..0c9fb62 100644 --- a/lib/utils_widgets/appBar.dart +++ b/lib/widgets/utils_widgets/appBar.dart @@ -1,9 +1,8 @@ import 'package:auto_size_text/auto_size_text.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/cloud_config_auth_page.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/cloud_config_auth_page.dart'; // bar at the top of the application on nearly every page diff --git a/lib/utils_widgets/drawer.dart b/lib/widgets/utils_widgets/drawer.dart similarity index 93% rename from lib/utils_widgets/drawer.dart rename to lib/widgets/utils_widgets/drawer.dart index 4b3b3c1..6d96616 100644 --- a/lib/utils_widgets/drawer.dart +++ b/lib/widgets/utils_widgets/drawer.dart @@ -1,9 +1,9 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/add_cloud_or_self_managed.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/add_cloud_or_self_managed.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/authentification_page.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/authentification_page.dart'; // Drawer show on the home page (connections page) diff --git a/lib/utils_widgets/utils_widgets.dart b/lib/widgets/utils_widgets/utils_widgets.dart similarity index 92% rename from lib/utils_widgets/utils_widgets.dart rename to lib/widgets/utils_widgets/utils_widgets.dart index 86422c5..5cb1fd8 100644 --- a/lib/utils_widgets/utils_widgets.dart +++ b/lib/widgets/utils_widgets/utils_widgets.dart @@ -1,20 +1,14 @@ -import 'dart:io'; -import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:auto_size_text/auto_size_text.dart'; -import 'package:http/http.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/cloud_config_auth_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/connections_page.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:panduza_sandbox_flutter/data/const.dart'; -import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/userspace_page.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/edit_page.dart'; -import 'package:panduza_sandbox_flutter/after_setup_pages/manual_connection_page.dart'; -import 'package:panduza_sandbox_flutter/data/utils.dart'; -import 'package:panduza_sandbox_flutter/data/rest_request.dart'; -import 'package:panduza_sandbox_flutter/setup_pages/authentification_page.dart'; +import 'package:panduza_sandbox_flutter/utils/const.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_objects/broker_connection_info.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/userspace_page.dart'; +import 'package:panduza_sandbox_flutter/pages/after_setup_pages/edit_page.dart'; +import 'package:panduza_sandbox_flutter/utils/utils_functions.dart'; +import 'package:panduza_sandbox_flutter/pages/setup_pages/authentification_page.dart'; // on the home page content of each connection button // displaying the name, the host ip and the port @@ -28,7 +22,7 @@ Widget getConnectionButton(SharedPreferences prefs, List platformNames, children: [ // Think to try changing in auto ajust text AutoSizeText( - '${platformNames[index]}', + platformNames[index], style: TextStyle( color: blue ), @@ -38,14 +32,14 @@ Widget getConnectionButton(SharedPreferences prefs, List platformNames, height: 5, ), AutoSizeText( - '${(prefs.getStringList(platformNames[index]) as List)[1]}', + (prefs.getStringList(platformNames[index]) as List)[1], maxLines: 1, ), const SizedBox( height: 5, ), AutoSizeText( - '${(prefs.getStringList(platformNames[index]) as List)[2]}', + (prefs.getStringList(platformNames[index]) as List)[2], maxLines: 1, ) ], @@ -442,7 +436,7 @@ Widget getConnectionsButtonsList(SharedPreferences prefs, List platformN context, MaterialPageRoute( builder: (context) => UserspacePage( - broker_connection_info: BrokerConnectionInfo( + brokerConnectionInfo: BrokerConnectionInfo( host, int.parse(port), client