Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
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
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
Sara Savanovic Djordjevic
PROG2900
Commits
5a13a6df
Commit
5a13a6df
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: loading screen
parent
32c60e92
No related branches found
Branches containing commit
No related tags found
2 merge requests
!5
Clhp map
,
!4
Clhp map
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/pages/default_page.dart
+49
-65
49 additions, 65 deletions
app/lib/pages/default_page.dart
with
49 additions
and
65 deletions
app/lib/pages/default_page.dart
+
49
−
65
View file @
5a13a6df
...
...
@@ -8,7 +8,7 @@ import 'marker_handler/get_relation.dart';
import
'dart:typed_data'
;
class
DefaultPage
extends
StatefulWidget
{
const
DefaultPage
({
super
.
key
}
);
const
DefaultPage
({
Key
?
key
})
:
super
(
key
:
key
);
@override
_DefaultPageState
createState
()
=
>
_DefaultPageState
();
...
...
@@ -18,55 +18,23 @@ class _DefaultPageState extends State<DefaultPage> {
late
Timer
_timer
;
bool
showBar
=
false
;
List
<
Measurement
>
markerList
=
[]
;
Uint8List
relation
=
Uint8List
(
0
)
;
late
Future
<
List
<
Measurement
>
>
markerList
Future
;
late
Future
<
Uint8List
>
relation
Future
;
// Call fetchMarkerTemplate and await its result before setting the state
Future
<
void
>
loadMarkerList
()
async
{
try
{
List
<
Measurement
>
fetchedMarkers
=
await
fetchMarkerData
();
Uint8List
fetchedRelation
=
await
fetchRelation
();
setState
(()
{
// Initialise markers and relations
markerList
=
fetchedMarkers
;
relation
=
fetchedRelation
;
});
}
catch
(
e
)
{
showDialog
(
context:
context
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
title:
const
Text
(
"Error"
),
content:
Text
(
e
.
toString
()),
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
)
.
pop
();
},
child:
const
Text
(
"OK"
),
),
],
);
},
);
}
}
// State initializer
@override
void
initState
()
{
super
.
initState
();
// Load marker data from server
loadMarkerList
();
markerListFuture
=
fetchMarkerData
();
relationFuture
=
fetchRelation
();
// Schedule fetchMarkerData to run periodically based on fetchInterval from consts
const
Duration
interval
=
Duration
(
minutes:
fetchInterval
);
const
Duration
interval
=
Duration
(
minutes:
fetchInterval
);
// NB fetchInterval value to be determined
_timer
=
Timer
.
periodic
(
interval
,
(
timer
)
{
fetchMarkerData
();
});
}
// Fetch timer
// Fetch
-interval
timer
@override
void
dispose
()
{
// Cancel timer on widget termination
...
...
@@ -77,34 +45,50 @@ class _DefaultPageState extends State<DefaultPage> {
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
Container
(
decoration:
const
BoxDecoration
(
// Set background color
gradient:
LinearGradient
(
begin:
Alignment
.
topCenter
,
end:
Alignment
.
bottomCenter
,
colors:
[
darkBlue
,
darkestBlue
],
),
),
child:
Scaffold
(
backgroundColor:
Colors
.
transparent
,
appBar:
AppBar
(
title:
const
Text
(
'IceMap'
),
actions:
[
IconButton
(
icon:
const
Icon
(
Icons
.
search
),
onPressed:
()
{
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'IceMap'
),
actions:
[
IconButton
(
icon:
const
Icon
(
Icons
.
search
),
onPressed:
()
{
setState
(()
{
showBar
=
!
showBar
;
},
),
],
),
body:
ListView
(
children:
[
// Add main widget
MapContainerWidget
(
markerList:
markerList
,
relation:
relation
),
],
),
});
},
),
],
),
body:
FutureBuilder
(
future:
Future
.
wait
([
markerListFuture
,
relationFuture
]),
builder:
(
BuildContext
context
,
AsyncSnapshot
<
List
<
dynamic
>>
snapshot
)
{
// Display loading screen until data is fetched
if
(
snapshot
.
connectionState
==
ConnectionState
.
waiting
)
{
return
const
Center
(
child:
CircularProgressIndicator
());
}
else
if
(
snapshot
.
hasError
)
{
return
Center
(
child:
Text
(
'Error:
${snapshot.error}
'
));
}
else
{
// Display default page once all data is loaded from server
List
<
Measurement
>
markerList
=
snapshot
.
data
!
[
0
]
as
List
<
Measurement
>;
Uint8List
relation
=
snapshot
.
data
!
[
1
]
as
Uint8List
;
return
Container
(
// Return container with list view and background color
decoration:
const
BoxDecoration
(
// Set background color
gradient:
LinearGradient
(
begin:
Alignment
.
topCenter
,
end:
Alignment
.
bottomCenter
,
colors:
[
darkBlue
,
darkestBlue
],
),
),
child:
ListView
(
children:
[
MapContainerWidget
(
markerList:
markerList
,
relation:
relation
),
],
),
);
}
},
),
),
);
}
}
\ No newline at end of file
}
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