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
cb2d27bb
Commit
cb2d27bb
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: working alert
parent
04a9d20e
No related branches found
Branches containing commit
No related tags found
2 merge requests
!9
Clhp map
,
!8
Clhp map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/pages/default_page.dart
+40
-25
40 additions, 25 deletions
app/lib/pages/default_page.dart
server/map/__pycache__/get_relation.cpython-311.pyc
+0
-0
0 additions, 0 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
with
40 additions
and
25 deletions
app/lib/pages/default_page.dart
+
40
−
25
View file @
cb2d27bb
...
...
@@ -19,12 +19,13 @@ class _DefaultPageState extends State<DefaultPage> {
late
Timer
_timer
;
bool
showBar
=
false
;
bool
serverConnection
=
true
;
bool
dialogShown
=
false
;
late
Future
<
List
<
Measurement
>>
markerListFuture
;
late
Future
<
Uint8List
>
relationFuture
;
/// Fetch measurement and relation data, check server connection, and
/// start a request timer
final
GlobalKey
<
ScaffoldMessengerState
>
_scaffoldMessengerKey
=
GlobalKey
<
ScaffoldMessengerState
>();
@override
void
initState
()
{
super
.
initState
();
...
...
@@ -36,44 +37,55 @@ class _DefaultPageState extends State<DefaultPage> {
// Return the measurements
return
measurements
;
})
.
catchError
((
error
)
{
serverConnection
=
false
;
throw
Exception
(
"Failed to fetch measurements:
$error
"
);
});
if
(
!
serverConnection
)
{
_showConnectionMessage
();
}
relationFuture
=
fetchRelation
();
// Schedule fetchMarkerData to run periodically based on fetchInterval
from consts
// Schedule fetchMarkerData to run periodically based on fetchInterval
const
Duration
interval
=
Duration
(
minutes:
fetchInterval
);
// NB fetchInterval value to be determined
_timer
=
Timer
.
periodic
(
interval
,
(
timer
)
{
fetchMeasurements
();
});
}
/// Display a message for 5 seconds informing the user
/// of lacking server connection
void
_showConnectionMessage
()
{
const
snackBar
=
SnackBar
(
content:
Text
(
'Failed to connect to the server. Information about'
'ice safety could be outdated!'
),
duration:
Duration
(
seconds:
5
),
);
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
snackBar
);
}
/// Timer for resending requests to server
@override
void
dispose
()
{
// Cancel timer on widget termination
_timer
.
cancel
();
super
.
dispose
();
}
/// Display message to user
void
showConnectionMessage
()
{
showDialog
(
context:
context
,
builder:
(
context
)
=
>
AlertDialog
(
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
)
.
pop
();
},
child:
const
Text
(
"Ok"
),
)
],
title:
const
Center
(
child:
Text
(
"No server connection"
)
),
contentPadding:
const
EdgeInsets
.
all
(
10.0
),
content:
const
Text
(
"The app may display outdated information. Use with caution!"
,
textAlign:
TextAlign
.
center
,
// Align text center
),
),
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
Scaffold
(
key:
_scaffoldMessengerKey
,
appBar:
AppBar
(
title:
const
Text
(
'IceMap'
),
actions:
[
...
...
@@ -90,7 +102,6 @@ class _DefaultPageState extends State<DefaultPage> {
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
Container
(
decoration:
const
BoxDecoration
(
// Background color for loading screen
...
...
@@ -107,12 +118,17 @@ class _DefaultPageState extends State<DefaultPage> {
}
else
if
(
snapshot
.
hasError
)
{
return
Center
(
child:
Text
(
'Error:
${snapshot.error}
'
));
}
else
{
if
(
!
serverConnection
)
{
// NB: implement dialogue box
print
(
"Failed to connect to server"
);
// Here...
}
// Display default page once all data is loaded from server
// Alert the user after the build completes if there is no server connection
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
if
(
serverConnection
&&
!
dialogShown
)
{
dialogShown
=
true
;
showConnectionMessage
();
}
});
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
(
...
...
@@ -134,4 +150,3 @@ class _DefaultPageState extends State<DefaultPage> {
);
}
}
This diff is collapsed.
Click to expand it.
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
cb2d27bb
No preview for this file type
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