Newer
Older
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'datamodel.dart';
Future<Collection> fetchCollection() async {
print("Start HTTP GET++##");
final response = await http
.get(Uri.parse('https://sensor.awi.de/rest/sensors/collections/getCollection/22'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
return Collection.fromJson(jsonDecode(response.body));
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load Collection');
}
}
Future<List<Collection>> fetchCollections() async {
print("Fetching Collections...");
final response = await http
.get(Uri.parse('https://sensor.awi.de/rest/sensors/collections/getAllCollections?pointInTime=2018-07-03T12%3A30%3A55.389Z'));
if (response.statusCode == 200) {
List<Collection> collectionList;
return (json.decode(response.body) as List)
.map((i) => Collection.fromJson(i))
.toList();
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load Collection');
}
}
class Configuration extends StatefulWidget {
@override
State<Configuration> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<Configuration> {
late Future<Collection> futureCollection;
late Future<List<Collection>> futureCollections;
@override
void initState() {
super.initState();
futureCollection = fetchCollection();
futureCollections = fetchCollections();
late Future<String> eventTypes;
@override
Widget build(BuildContext context) {
final CollectionStoreInstance storedCollections = CollectionStoreInstance();
final CollectionCurrentInstance currentCollection = CollectionCurrentInstance();
return Scaffold(
appBar: AppBar(
title: Text('Configuration'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
FutureBuilder<List<Collection>>(
future: futureCollections,
builder: (context, snapshot){
if (snapshot.hasData)
{
print(snapshot.data);
print(futureCollections);
//storedCollections.store = snapshot.data!; // Store data locally
//var listlen = storedCollections.store.length();
//print('Length ###: ' + storedCollections.store.length().toString());
return DropdownButtonFormField(
value: currentCollection.store.collectionName,
decoration: const InputDecoration(
labelText: 'Chosen Collection',
),
items:
storedCollections.store.map((Collection collection) {
return DropdownMenuItem(
value: collection.collectionName,
child: Text(collection.collectionName),
);
}).toList(),
onChanged: (value) {
currentCollection.store.collectionName = value.toString();
}
);
}
else{
return CircularProgressIndicator();
}
}
FutureBuilder<Collection>(
future: futureCollection,
builder: (context, snapshot){
if (snapshot.hasData)
{
return Text(snapshot.data!.collectionName);
}
else{
return CircularProgressIndicator();
}
],
),
),
bottomNavigationBar: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FloatingActionButton.extended(
tooltip: 'Request Collections from sensor.awi.de',
icon: Icon(Icons.download),
label: const Text("Get Collections"),
onPressed: null,
FloatingActionButton.extended(
tooltip: 'Select Collection and download corresponding devices',
icon: Icon(Icons.save),
label: const Text('Select'),
onPressed: null,
),
],
),
);
}
}