From e1a4cc6f5a9efef8203d66c34fc890b65dd7b61e Mon Sep 17 00:00:00 2001 From: Simeon5566 Date: Wed, 23 Nov 2022 16:48:31 +0100 Subject: [PATCH] fixing and added widget logic --- README.md | 9 +++++- lib/objects/cloud_service_api.dart | 24 +++++++++------ lib/screens/bluetooth_screen.dart | 47 +++++++++++++++++++----------- lib/screens/cloud_service_ui.dart | 2 +- lib/screens/settings.dart | 4 +-- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 9c77c30..88db4d5 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,11 @@ For help getting started with Flutter development, view the samples, guidance on mobile development, and a full API reference.
To build this projekt with windows be sure to set in
-settings -> windows security -> for developers -> developer mode -> on \ No newline at end of file +settings -> windows security -> for developers -> developer mode -> on +
+For the Cloud Service, be sure deactivating web security when working with Edge Browser. +1. Go to 'flutter\bin\cache' remove the following file 'flutter_tools.stamp' +2. Go to 'flutter\packages\flutter_tools\lib\src\web' and open 'chrome.dart' +3. find '--disable-extensions' and add '--disable-web-security' +
+Before \ No newline at end of file diff --git a/lib/objects/cloud_service_api.dart b/lib/objects/cloud_service_api.dart index 97273cb..bc49006 100644 --- a/lib/objects/cloud_service_api.dart +++ b/lib/objects/cloud_service_api.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:http/http.dart'; - +import 'dart:developer'; Future> readJson() async { final data = await rootBundle.loadString('config/credentials.json'); @@ -12,15 +12,21 @@ Future> readJson() async { } class CloudServiceAPI { - late final Map credentials; - late Future loadJson; - late String basicAuth; - late String address; - late Map headers; + static late final Map credentials; + static late Future loadJson; + static late String basicAuth; + static late String address; + static late Map headers; + static bool initState = false; - CloudServiceAPI(); + CloudServiceAPI(){ + if(!initState) { + loadJson = loadConfig(); + initState = true; + } + } - Future loadConfig() async{ + Future loadConfig() async{ credentials = await readJson(); String username = credentials['username']; String password = credentials['password']; @@ -29,7 +35,7 @@ class CloudServiceAPI { headers = { 'authorization': basicAuth, 'content-type': 'application/json', - 'accept': 'application/json' + 'accept': 'application/json', }; } Future getDevices() async { diff --git a/lib/screens/bluetooth_screen.dart b/lib/screens/bluetooth_screen.dart index 5971dcf..3e6144f 100644 --- a/lib/screens/bluetooth_screen.dart +++ b/lib/screens/bluetooth_screen.dart @@ -1,5 +1,6 @@ import 'dart:async'; - +import 'dart:developer'; +import 'dart:io'; import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:flutter/material.dart'; @@ -7,6 +8,8 @@ import 'package:flutter_provisioning_for_iot/widgets/bluetooth_discovery.dart'; import 'package:flutter_provisioning_for_iot/objects/cloud_service_api.dart'; import 'package:flutter_provisioning_for_iot/widgets/switch_widget.dart'; +import 'package:flutter/material.dart'; + class BluetoothScreen extends StatefulWidget { const BluetoothScreen({super.key}); @@ -17,15 +20,17 @@ class BluetoothScreen extends StatefulWidget { class _BluetoothScreen extends State { final textFieldValueHolder = TextEditingController(); - late CloudServiceAPI cloudServiceAPI = CloudServiceAPI(); - late List results = + CloudServiceAPI cloudServiceAPI = CloudServiceAPI(); + List results = List.empty(growable: true); - late ButtonStyle buttonStyle = ElevatedButton.styleFrom( + ButtonStyle buttonStyle = ElevatedButton.styleFrom( foregroundColor: Colors.black, backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color) ); - late String inputName = ""; - late bool initScan = true; + String inputName = ""; + bool initScan = true; + bool scanState = false; + bool widgetScanState = false; @override Widget build(BuildContext context) { @@ -66,8 +71,7 @@ class _BluetoothScreen extends State { width: double.infinity, child: ElevatedButton( onPressed: () { - var textFieldValue = - textFieldValueHolder.value.toString(); + var textFieldValue = textFieldValueHolder.value.text; checkNameAvailability(textFieldValue); setState(() { inputName = textFieldValue; @@ -88,34 +92,43 @@ class _BluetoothScreen extends State { bottom: BorderSide(width: 1.5, color: Colors.grey), ), ), - child: Row(children: const [ - Text( + child: Row(children: [ + const Text( "Toggle Scan", style: TextStyle(fontWeight: FontWeight.bold), ), - Expanded(child: Text("")), - SwitchWidget(), + const Expanded(child: Text("")), + Switch( + value: widgetScanState, + onChanged: (bool toggleState) { + scanState = toggleState; + log("widget state: $scanState"); + setState(() { + widgetScanState = toggleState; + }); + }) ]), ), - BluetoothDiscovery(start: initScan, deviceID: inputName), + // BluetoothDiscovery(start: initScan, deviceID: inputName), ], ), //), ), + ), ); } Future checkNameAvailability(String input) async { - await cloudServiceAPI.loadConfig(); + // await cloudServiceAPI.loadConfig(); List devices = await cloudServiceAPI.getDevices(); for (Map selected in devices) { - if (selected["id"] == input) { - await showNameAvailabilityStatus(false); + if (selected["id"] == input) { + await showNameAvailabilityStatus(true); return; } } - await showNameAvailabilityStatus(true); + await showNameAvailabilityStatus(false); } Future showNameAvailabilityStatus(bool status) async { diff --git a/lib/screens/cloud_service_ui.dart b/lib/screens/cloud_service_ui.dart index fde8dbe..90b4b6b 100644 --- a/lib/screens/cloud_service_ui.dart +++ b/lib/screens/cloud_service_ui.dart @@ -36,7 +36,7 @@ class _CloudService extends State{ child: TextButton( onPressed: () async{ var respond1 = await cloudServiceAPI.getDevices(); - debugPrint('Devices: ${respond1[0].toString()}'); + debugPrint('Devices: ${respond1.toString()}'); var respond2 = await cloudServiceAPI.getInformation(); debugPrint('Information: ${respond2.toString()}'); var respond3 = await cloudServiceAPI.createDevice('1', 'asdas', 'sdwe1'); diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index d203119..3b3a843 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -39,7 +39,7 @@ class _SettingsState extends State { children: [ TextFormField( decoration: const InputDecoration( - labelText: "Address for the Classifier-Server"), + labelText: "Address for the Device Manager"), initialValue: Settings.ip, onChanged: (String newValue) { Settings.ip = newValue; @@ -48,7 +48,7 @@ class _SettingsState extends State { ), TextFormField( decoration: const InputDecoration( - labelText: "Port for the Classifier-Server"), + labelText: "Port for the Device Manager"), keyboardType: TextInputType.number, inputFormatters: [ FilteringTextInputFormatter.digitsOnly