91 lines
2.8 KiB
Dart
91 lines
2.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../objects/cloud_service_api.dart';
|
|
import '../widgets/sidebar.dart';
|
|
|
|
Future<Map<String, dynamic>> readJson() async {
|
|
final String data = await rootBundle.loadString('config/credentials.json');
|
|
final Map<String, dynamic> dataMap = json.decode(data);
|
|
log("loaded json input $dataMap");
|
|
return dataMap;
|
|
}
|
|
|
|
class CloudService extends StatefulWidget {
|
|
const CloudService({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<CloudService> createState() => _CloudService();
|
|
}
|
|
|
|
class _CloudService extends State<CloudService> {
|
|
late final Map<String, dynamic> credentials;
|
|
CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
|
int _selectedIndex = 0;
|
|
|
|
void _onItemTapped(int index){
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
if(_selectedIndex == 0){
|
|
cloudServiceAPI.updateDeviceList();
|
|
}
|
|
if(_selectedIndex == 1){
|
|
// implementation missing
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Cloud Service"),
|
|
),
|
|
body: Column(
|
|
children: <Widget>[
|
|
Expanded(child: ListView.separated(
|
|
itemCount: cloudServiceAPI.getLoadedDevices().length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return Container(
|
|
height: 100,
|
|
color: Colors.lightBlueAccent[100],
|
|
child: Center(child: Text("Id: ${cloudServiceAPI.getLoadedDevices()[index]['id']} \n"
|
|
"endpoint: ${cloudServiceAPI.getLoadedDevices()[index]['endpoint']} \n"
|
|
"status: ${cloudServiceAPI.getLoadedDevices()[index]['endpoint']} \n"
|
|
"connectionState: ${cloudServiceAPI.getLoadedDevices()[index]['connectionState']} \n"
|
|
"lastActivityTime: ${cloudServiceAPI.getLoadedDevices()[index]['lastActivityTime']}"),),
|
|
);
|
|
}, separatorBuilder: (BuildContext context, int index) => const Divider(
|
|
thickness: 0,
|
|
indent: 0,
|
|
height: 5,
|
|
color: Colors.white,
|
|
),)
|
|
)
|
|
],
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
type: BottomNavigationBarType.fixed,
|
|
items: const<BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.refresh),
|
|
label: 'Reload',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.search),
|
|
label: 'Search',
|
|
),
|
|
],
|
|
currentIndex: _selectedIndex,
|
|
selectedItemColor: Colors.lightBlueAccent,
|
|
onTap: _onItemTapped,
|
|
),
|
|
drawer: const Sidebar(),
|
|
);
|
|
}
|
|
}
|