Skip to content
Snippets Groups Projects
Commit cbc265e0 authored by Maximilian Betz's avatar Maximilian Betz
Browse files

added first future http get, not working yet

parent 8f678ee1
No related branches found
No related tags found
No related merge requests found
......@@ -31,4 +31,6 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to fetch data from the internet. -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Collection {
final int id;
final String description;
final String collectionName;
const Collection({
required this.id,
required this.description,
required this.collectionName,
});
factory Collection.fromJson(Map<String, dynamic> json) {
return Collection(
id: json['id'],
collectionName: json['collectionName'],
description: json['description'],
);
}
}
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');
}
}
class Configuration extends StatefulWidget {
......@@ -18,12 +57,16 @@ class _MyHomePageState extends State<Configuration> {
'100',
];
late Future<String> eventTypes;
late Future<Collection> futureCollection;
@override
void initState() {
super.initState();
futureCollection = fetchCollection();
}
late Future<String> eventTypes;
void _incrementCounter() {
setState(() {
......@@ -80,7 +123,18 @@ class _MyHomePageState extends State<Configuration> {
});
},
),
Text('blabla'),
FutureBuilder<Collection>(
future: futureCollection,
builder: (context, snapshot){
if (snapshot.hasData)
{
return Text(snapshot.data!.collectionName);
}
else{
return CircularProgressIndicator();
}
}
),
],
),
),
......
......@@ -83,6 +83,7 @@ abstract class DeviceStoreBase {
abstract class EventStoreBase{
List<Event> store = [];
}
abstract class EventCurrentBase{
......@@ -91,6 +92,15 @@ abstract class EventCurrentBase{
abstract class EventTypeStoreBase{
List<EventType> store = [];
int getEventIdFromName(String name) {
for (var eventType in store) {
if (eventType.name == name) {
return eventType.id;
}
}
throw Exception('Event with name :' + name + ' was not found.');
}
}
class EventStoreInstance extends EventStoreBase {
......
......@@ -93,6 +93,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
js:
dependency: transitive
description:
......
......@@ -31,6 +31,7 @@ dependencies:
sdk: flutter
shared_preferences: ^2.0.12
http: ^0.13.4
# The following adds the Cupertino Icons font to your application.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment