Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
446eb313
Commit
446eb313
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
requesting collections works, filling dropdown button not yet
parent
cbc265e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+18
-0
18 additions, 0 deletions
README.md
lib/configuration.dart
+75
-99
75 additions, 99 deletions
lib/configuration.dart
lib/datamodel.dart
+68
-0
68 additions, 0 deletions
lib/datamodel.dart
with
161 additions
and
99 deletions
README.md
+
18
−
0
View file @
446eb313
...
...
@@ -13,3 +13,21 @@ A cross plattform project for android and ios to log events offline everywhere a
## Questions:
-
How to store not uploaded events locally? Dumping jsons to a file?, ObjectBox, SharedPreferences,
## Local Base Data Concept
-
The configuration.dart age widget is used to get the online available information for available
devices and event creation.
-
This includes: All collections, All devices part of a selected collection, Event operation types
-
This "base data" is required to provide the dropdown menu options on the addevent.dart page.
-
This "base data" needs to be stored persistently, so that it is available also offline!
## Local Data Event Storage
-
Events added on the addevent.dart page have to be stored locally persistently. At least until the
are exported to sensor.awi.de
## Configuration Page
-
Dropdown "Collection" to select a collection
-
Textfield to show current locally selected and offline available collection
-
Button "get Collection devices from Sensor"
-
Button "store Collection devices locally"
This diff is collapsed.
Click to expand it.
lib/configuration.dart
+
75
−
99
View file @
446eb313
...
...
@@ -2,26 +2,8 @@ import 'package:flutter/cupertino.dart';
import
'package:flutter/material.dart'
;
import
'package:http/http.dart'
as
http
;
import
'dart:convert'
;
import
'datamodel.dart'
;
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++##"
);
...
...
@@ -40,6 +22,25 @@ Future<Collection> fetchCollection() async {
}
}
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
...
...
@@ -47,51 +48,25 @@ class Configuration extends StatefulWidget {
}
class
_MyHomePageState
extends
State
<
Configuration
>
{
int
_counter
=
0
;
int
_factor
=
1
;
String
selectedValue
=
'1'
;
var
available_items
=
[
'1'
,
'10'
,
'100'
,
];
late
Future
<
Collection
>
futureCollection
;
late
Future
<
List
<
Collection
>>
futureCollections
;
@override
void
initState
()
{
super
.
initState
();
futureCollection
=
fetchCollection
();
}
late
Future
<
String
>
eventTypes
;
futureCollections
=
fetchCollections
();
void
_incrementCounter
()
{
setState
(()
{
_counter
=
_counter
+
_factor
;
});
}
void
_decrementCounter
()
{
setState
(()
{
_counter
=
_counter
-
_factor
;
});
}
void
_resetCounter
()
{
setState
(()
{
_counter
=
0
;
});
}
late
Future
<
String
>
eventTypes
;
void
_getCollections
()
{
setState
(()
{});
}
@override
Widget
build
(
BuildContext
context
)
{
final
CollectionStoreInstance
storedCollections
=
CollectionStoreInstance
();
final
CollectionCurrentInstance
currentCollection
=
CollectionCurrentInstance
();
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Configuration'
),
...
...
@@ -100,40 +75,51 @@ class _MyHomePageState extends State<Configuration> {
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
const
Text
(
'You have pushed the button this many times:'
,
),
Text
(
'
$_counter
'
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headline2
,
),
DropdownButton
(
value:
selectedValue
,
icon:
const
Icon
(
Icons
.
keyboard_arrow_down
),
items:
available_items
.
map
((
String
available_items
)
{
return
DropdownMenuItem
(
value:
available_items
,
child:
Text
(
available_items
),
);
})
.
toList
(),
onChanged:
(
String
?
newValue
)
{
setState
(()
{
selectedValue
=
newValue
!
;
_factor
=
int
.
parse
(
selectedValue
);
});
},
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
)
future:
futureCollection
,
builder:
(
context
,
snapshot
){
if
(
snapshot
.
hasData
)
{
return
Text
(
snapshot
.
data
!.
collectionName
);
}
else
{
return
CircularProgressIndicator
();
else
{
return
CircularProgressIndicator
();
}
}
}
),
],
),
...
...
@@ -141,29 +127,19 @@ class _MyHomePageState extends State<Configuration> {
bottomNavigationBar:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
FloatingActionButton
(
heroTag:
null
,
onPressed:
_incrementCounter
,
tooltip:
'Increment'
,
child:
const
Icon
(
Icons
.
add
),
),
FloatingActionButton
(
heroTag:
null
,
onPressed:
_decrementCounter
,
tooltip:
'Decrement'
,
child:
const
Text
(
'-'
),
),
FloatingActionButton
(
FloatingActionButton
.
extended
(
heroTag:
null
,
onPressed:
_resetCounter
,
tooltip:
'Reset to 0'
,
child:
const
Icon
(
Icons
.
delete
),
tooltip:
'Request Collections from sensor.awi.de'
,
icon:
Icon
(
Icons
.
download
),
label:
const
Text
(
"Get Collections"
),
onPressed:
null
,
),
FloatingActionButton
(
FloatingActionButton
.
extended
(
heroTag:
null
,
onPressed:
_getCollections
,
tooltip:
'Reset to 0'
,
child:
const
Text
(
'Update'
),
tooltip:
'Select Collection and download corresponding devices'
,
icon:
Icon
(
Icons
.
save
),
label:
const
Text
(
'Select'
),
onPressed:
null
,
),
],
),
...
...
This diff is collapsed.
Click to expand it.
lib/datamodel.dart
+
68
−
0
View file @
446eb313
import
'package:shared_preferences/shared_preferences.dart'
;
class
Collection
{
int
id
;
String
description
;
String
collectionName
;
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'
],
);
}
@override
String
toString
(){
return
collectionName
;
}
}
class
Device
{
int
id
;
String
urn
;
...
...
@@ -63,6 +89,28 @@ class EventType{
}
}
abstract
class
CollectionStoreBase
{
List
<
Collection
>
store
=
[];
}
class
CollectionStoreInstance
extends
CollectionStoreBase
{
static
final
CollectionStoreInstance
_instance
=
CollectionStoreInstance
.
_internal
();
factory
CollectionStoreInstance
()
{
return
_instance
;
}
CollectionStoreInstance
.
_internal
()
{
store
=
[];
}
void
reset
()
{
store
=
[];
}
}
abstract
class
DeviceStoreBase
{
List
<
Device
>
store
=
[];
...
...
@@ -90,6 +138,10 @@ abstract class EventCurrentBase{
Event
store
=
Event
(
0
,
'urn0'
,
''
,
''
,
''
,
'PENDING'
);
}
abstract
class
CollectionCurrentBase
{
Collection
store
=
Collection
(
id:
-
1
,
description:
'description'
,
collectionName:
'name'
);
}
abstract
class
EventTypeStoreBase
{
List
<
EventType
>
store
=
[];
...
...
@@ -135,6 +187,22 @@ class EventCurrentInstance extends EventCurrentBase {
}
}
class
CollectionCurrentInstance
extends
CollectionCurrentBase
{
static
final
CollectionCurrentInstance
_instance
=
CollectionCurrentInstance
.
_internal
();
factory
CollectionCurrentInstance
(){
return
_instance
;
}
CollectionCurrentInstance
.
_internal
(){
store
=
Collection
(
collectionName:
'name'
,
description:
'description'
,
id:
-
1
);
}
void
reset
(){
store
=
Collection
(
collectionName:
'name'
,
description:
'description'
,
id:
-
1
);
}
}
class
EventTypeStoreInstance
extends
EventTypeStoreBase
{
static
final
EventTypeStoreInstance
_instance
=
EventTypeStoreInstance
.
_internal
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment