added Cloud Service, first draw
This commit is contained in:
parent
68cc9534e2
commit
84dfa474ee
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"username": "...",
|
||||||
|
"password": "...",
|
||||||
|
"address": "..."
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> readJson() async {
|
||||||
|
final data = await rootBundle.loadString('config/credentials.json');
|
||||||
|
var data_ = json.decode(data) as Map<String, dynamic>;
|
||||||
|
debugPrint(data_.toString());
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CloudServiceAPI{
|
||||||
|
late final Map<String, dynamic> credentials;
|
||||||
|
late Future loadJson;
|
||||||
|
late String basicAuth;
|
||||||
|
late String address;
|
||||||
|
late Map<String, String> headers;
|
||||||
|
|
||||||
|
CloudServiceAPI() {
|
||||||
|
loadJson = loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future loadConfig() async{
|
||||||
|
credentials = await readJson();
|
||||||
|
String username = credentials['username'];
|
||||||
|
String password = credentials['password'];
|
||||||
|
address = credentials['address'];
|
||||||
|
basicAuth = 'Basic ${base64.encode(utf8.encode('$username:$password'))}';
|
||||||
|
headers = {
|
||||||
|
'authorization': basicAuth,
|
||||||
|
'content-type': 'application/json',
|
||||||
|
'accept': 'application/json'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Future<List> getDevices() async {
|
||||||
|
var url = Uri.https(address, '/api/devices');
|
||||||
|
Response r = await get(url, headers: headers);
|
||||||
|
return json.decode(r.body) as List<dynamic>;
|
||||||
|
}
|
||||||
|
Future<Map<String, dynamic>> getDeviceInfo(deviceID) async {
|
||||||
|
var url = Uri.https(address, '/api/devices/$deviceID');
|
||||||
|
Response r = await get(url, headers: headers);
|
||||||
|
return json.decode(r.body) as Map<String, dynamic>;
|
||||||
|
}
|
||||||
|
Future<Map<String, dynamic>> getInformation() async {
|
||||||
|
var url = Uri.https(address, '/api/app');
|
||||||
|
Response r = await get(url, headers: headers);
|
||||||
|
return json.decode(r.body) as Map<String, dynamic>;
|
||||||
|
}
|
||||||
|
Future<bool> createDevice(
|
||||||
|
id,
|
||||||
|
primaryThumbprint,
|
||||||
|
secondaryThumbprint) async{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'cloud_service_api.dart';
|
||||||
|
import 'sidebar.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class CloudService extends StatefulWidget {
|
||||||
|
const CloudService({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CloudService> createState() => _CloudService();
|
||||||
|
|
||||||
|
}
|
||||||
|
Future<Map<String, dynamic>> readJson() async {
|
||||||
|
final data = await rootBundle.loadString('config/credentials.json');
|
||||||
|
var data_ = json.decode(data) as Map<String, dynamic>;
|
||||||
|
debugPrint(data_.toString());
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CloudService extends State<CloudService>{
|
||||||
|
late final Map<String, dynamic> credentials;
|
||||||
|
final CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text("Cloud Service"),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () async{
|
||||||
|
var respond1 = await cloudServiceAPI.getDevices();
|
||||||
|
debugPrint('Devices: ${respond1[0].toString()}');
|
||||||
|
var respond2 = await cloudServiceAPI.getInformation();
|
||||||
|
debugPrint('Information: ${respond2.toString()}');
|
||||||
|
}, child: const Text("Example"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
drawer: const Sidebar(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,6 +38,7 @@ dependencies:
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
flutter_blue: ^0.8.0
|
flutter_blue: ^0.8.0
|
||||||
shared_preferences: ^2.0.13
|
shared_preferences: ^2.0.13
|
||||||
|
http: ^0.13.5
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
@ -66,6 +67,8 @@ flutter:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
# - images/a_dot_ham.jpeg
|
# - images/a_dot_ham.jpeg
|
||||||
|
assets:
|
||||||
|
- config/credentials.json
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||||
|
|
Loading…
Reference in New Issue