fixing and added widget logic
This commit is contained in:
parent
b915a069cf
commit
e1a4cc6f5a
|
@ -23,3 +23,10 @@ samples, guidance on mobile development, and a full API reference.
|
||||||
<br>
|
<br>
|
||||||
To build this projekt with windows be sure to set in <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/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
Future<Map<String, dynamic>> readJson() async {
|
Future<Map<String, dynamic>> readJson() async {
|
||||||
final data = await rootBundle.loadString('config/credentials.json');
|
final data = await rootBundle.loadString('config/credentials.json');
|
||||||
|
@ -12,15 +12,21 @@ Future<Map<String, dynamic>> readJson() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CloudServiceAPI {
|
class CloudServiceAPI {
|
||||||
late final Map<String, dynamic> credentials;
|
static late final Map<String, dynamic> credentials;
|
||||||
late Future loadJson;
|
static late Future loadJson;
|
||||||
late String basicAuth;
|
static late String basicAuth;
|
||||||
late String address;
|
static late String address;
|
||||||
late Map<String, String> headers;
|
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();
|
credentials = await readJson();
|
||||||
String username = credentials['username'];
|
String username = credentials['username'];
|
||||||
String password = credentials['password'];
|
String password = credentials['password'];
|
||||||
|
@ -29,7 +35,7 @@ class CloudServiceAPI {
|
||||||
headers = {
|
headers = {
|
||||||
'authorization': basicAuth,
|
'authorization': basicAuth,
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
'accept': 'application/json'
|
'accept': 'application/json',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Future<List> getDevices() async {
|
Future<List> getDevices() async {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
|
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:flutter/material.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/objects/cloud_service_api.dart';
|
||||||
import 'package:flutter_provisioning_for_iot/widgets/switch_widget.dart';
|
import 'package:flutter_provisioning_for_iot/widgets/switch_widget.dart';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class BluetoothScreen extends StatefulWidget {
|
class BluetoothScreen extends StatefulWidget {
|
||||||
const BluetoothScreen({super.key});
|
const BluetoothScreen({super.key});
|
||||||
|
|
||||||
|
@ -17,15 +20,17 @@ class BluetoothScreen extends StatefulWidget {
|
||||||
class _BluetoothScreen extends State<BluetoothScreen> {
|
class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
|
|
||||||
final textFieldValueHolder = TextEditingController();
|
final textFieldValueHolder = TextEditingController();
|
||||||
late CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
||||||
late List<BluetoothDiscoveryResult> results =
|
List<BluetoothDiscoveryResult> results =
|
||||||
List<BluetoothDiscoveryResult>.empty(growable: true);
|
List<BluetoothDiscoveryResult>.empty(growable: true);
|
||||||
late ButtonStyle buttonStyle = ElevatedButton.styleFrom(
|
ButtonStyle buttonStyle = ElevatedButton.styleFrom(
|
||||||
foregroundColor: Colors.black,
|
foregroundColor: Colors.black,
|
||||||
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
|
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
|
||||||
);
|
);
|
||||||
late String inputName = "";
|
String inputName = "";
|
||||||
late bool initScan = true;
|
bool initScan = true;
|
||||||
|
bool scanState = false;
|
||||||
|
bool widgetScanState = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -66,8 +71,7 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var textFieldValue =
|
var textFieldValue = textFieldValueHolder.value.text;
|
||||||
textFieldValueHolder.value.toString();
|
|
||||||
checkNameAvailability(textFieldValue);
|
checkNameAvailability(textFieldValue);
|
||||||
setState(() {
|
setState(() {
|
||||||
inputName = textFieldValue;
|
inputName = textFieldValue;
|
||||||
|
@ -88,34 +92,43 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
bottom: BorderSide(width: 1.5, color: Colors.grey),
|
bottom: BorderSide(width: 1.5, color: Colors.grey),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(children: const [
|
child: Row(children: [
|
||||||
Text(
|
const Text(
|
||||||
"Toggle Scan",
|
"Toggle Scan",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Expanded(child: Text("")),
|
const Expanded(child: Text("")),
|
||||||
SwitchWidget(),
|
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 {
|
Future<void> checkNameAvailability(String input) async {
|
||||||
await cloudServiceAPI.loadConfig();
|
// await cloudServiceAPI.loadConfig();
|
||||||
List<dynamic> devices = await cloudServiceAPI.getDevices();
|
List<dynamic> devices = await cloudServiceAPI.getDevices();
|
||||||
for (Map<String, dynamic> selected in devices) {
|
for (Map<String, dynamic> selected in devices) {
|
||||||
if (selected["id"] == input) {
|
if (selected["id"] == input) {
|
||||||
await showNameAvailabilityStatus(false);
|
await showNameAvailabilityStatus(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await showNameAvailabilityStatus(true);
|
await showNameAvailabilityStatus(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showNameAvailabilityStatus(bool status) async {
|
Future<void> showNameAvailabilityStatus(bool status) async {
|
||||||
|
|
|
@ -36,7 +36,7 @@ class _CloudService extends State<CloudService>{
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () async{
|
onPressed: () async{
|
||||||
var respond1 = await cloudServiceAPI.getDevices();
|
var respond1 = await cloudServiceAPI.getDevices();
|
||||||
debugPrint('Devices: ${respond1[0].toString()}');
|
debugPrint('Devices: ${respond1.toString()}');
|
||||||
var respond2 = await cloudServiceAPI.getInformation();
|
var respond2 = await cloudServiceAPI.getInformation();
|
||||||
debugPrint('Information: ${respond2.toString()}');
|
debugPrint('Information: ${respond2.toString()}');
|
||||||
var respond3 = await cloudServiceAPI.createDevice('1', 'asdas', 'sdwe1');
|
var respond3 = await cloudServiceAPI.createDevice('1', 'asdas', 'sdwe1');
|
||||||
|
|
|
@ -39,7 +39,7 @@ class _SettingsState extends State<Settings> {
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: "Address for the Classifier-Server"),
|
labelText: "Address for the Device Manager"),
|
||||||
initialValue: Settings.ip,
|
initialValue: Settings.ip,
|
||||||
onChanged: (String newValue) {
|
onChanged: (String newValue) {
|
||||||
Settings.ip = newValue;
|
Settings.ip = newValue;
|
||||||
|
@ -48,7 +48,7 @@ class _SettingsState extends State<Settings> {
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: "Port for the Classifier-Server"),
|
labelText: "Port for the Device Manager"),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
inputFormatters: <TextInputFormatter>[
|
inputFormatters: <TextInputFormatter>[
|
||||||
FilteringTextInputFormatter.digitsOnly
|
FilteringTextInputFormatter.digitsOnly
|
||||||
|
|
Loading…
Reference in New Issue