fixing and added widget logic
This commit is contained in:
parent
b915a069cf
commit
e1a4cc6f5a
|
@ -22,4 +22,11 @@ For help getting started with Flutter development, view the
|
|||
samples, guidance on mobile development, and a full API reference.
|
||||
<br>
|
||||
To build this projekt with windows be sure to set in <br>
|
||||
settings -> windows security -> for developers -> developer mode -> on
|
||||
settings -> windows security -> for developers -> developer mode -> on
|
||||
<br>
|
||||
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'
|
||||
<br>
|
||||
Before
|
|
@ -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<Map<String, dynamic>> readJson() async {
|
||||
final data = await rootBundle.loadString('config/credentials.json');
|
||||
|
@ -12,15 +12,21 @@ Future<Map<String, dynamic>> readJson() async {
|
|||
}
|
||||
|
||||
class CloudServiceAPI {
|
||||
late final Map<String, dynamic> credentials;
|
||||
late Future loadJson;
|
||||
late String basicAuth;
|
||||
late String address;
|
||||
late Map<String, String> headers;
|
||||
static late final Map<String, dynamic> credentials;
|
||||
static late Future loadJson;
|
||||
static late String basicAuth;
|
||||
static late String address;
|
||||
static late Map<String, String> headers;
|
||||
static bool initState = false;
|
||||
|
||||
CloudServiceAPI();
|
||||
CloudServiceAPI(){
|
||||
if(!initState) {
|
||||
loadJson = loadConfig();
|
||||
initState = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> 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<List> getDevices() async {
|
||||
|
|
|
@ -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<BluetoothScreen> {
|
||||
|
||||
final textFieldValueHolder = TextEditingController();
|
||||
late CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
||||
late List<BluetoothDiscoveryResult> results =
|
||||
CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
||||
List<BluetoothDiscoveryResult> results =
|
||||
List<BluetoothDiscoveryResult>.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<BluetoothScreen> {
|
|||
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<BluetoothScreen> {
|
|||
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<void> checkNameAvailability(String input) async {
|
||||
await cloudServiceAPI.loadConfig();
|
||||
// await cloudServiceAPI.loadConfig();
|
||||
List<dynamic> devices = await cloudServiceAPI.getDevices();
|
||||
for (Map<String, dynamic> 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<void> showNameAvailabilityStatus(bool status) async {
|
||||
|
|
|
@ -36,7 +36,7 @@ class _CloudService extends State<CloudService>{
|
|||
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');
|
||||
|
|
|
@ -39,7 +39,7 @@ class _SettingsState extends State<Settings> {
|
|||
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<Settings> {
|
|||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Port for the Classifier-Server"),
|
||||
labelText: "Port for the Device Manager"),
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly
|
||||
|
|
Loading…
Reference in New Issue