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
Merge requests
!7
Clhp map
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Clhp map
clhp_map
into
main
Overview
0
Commits
16
Pipelines
0
Changes
13
Merged
Sara Savanovic Djordjevic
requested to merge
clhp_map
into
main
1 year ago
Overview
0
Commits
16
Pipelines
0
Changes
13
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
dedd71a7
16 commits,
1 year ago
13 files
+
158
−
54
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
13
Search (e.g. *.vue) (Ctrl+P)
app/lib/pages/marker_handler/get_relation.dart
+
30
−
6
Options
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'../consts.dart'
;
import
'dart:typed_data'
;
import
'package:path_provider/path_provider.dart'
;
import
'../consts.dart'
;
/// Fetch relation data from server
Future
<
Uint8List
>
fetchRelation
()
async
{
@@ -21,16 +23,38 @@ Future<Uint8List> fetchRelation() async {
var
responseBody
=
await
response
.
transform
(
utf8
.
decoder
)
.
join
();
if
(
responseBody
.
isNotEmpty
)
{
Directory
appDocumentsDirectory
=
await
getApplicationDocumentsDirectory
();
String
filePath
=
'
${appDocumentsDirectory.path}
/last_relation.json'
;
try
{
// Write most recent time of update to file
await
File
(
filePath
)
.
writeAsString
(
responseBody
,
mode:
FileMode
.
write
);
print
(
'Relation written to file'
);
}
catch
(
error
)
{
print
(
'Error in writing to file:
$error
'
);}
// Return relation data from the response body
return
Uint8List
.
fromList
(
utf8
.
encode
(
responseBody
));
}
else
{
throw
Exception
(
'Response body is empty'
);
}
}
else
{
throw
Exception
(
'Failed to fetch relation data: Status code
${response.statusCode}
'
);
}
return
loadSavedRelation
();
}
catch
(
e
)
{
throw
Exception
(
'Failed to fetch relation data:
${e.toString()}
'
);
return
loadSavedRelation
();
}
}
Future
<
Uint8List
>
loadSavedRelation
()
async
{
// Get latest saved relation from file if the server does not respond
Directory
appDocumentsDirectory
=
await
getApplicationDocumentsDirectory
();
String
filePath
=
'
${appDocumentsDirectory.path}
/last_relation.json'
;
// Read file contents
File
file
=
File
(
filePath
);
if
(
await
file
.
exists
())
{
String
contents
=
await
file
.
readAsString
();
List
<
dynamic
>
jsonData
=
json
.
decode
(
contents
);
// Parse JSON string from file
Uint8List
relation
=
Uint8List
.
fromList
(
utf8
.
encode
(
jsonData
.
toString
()));
return
relation
;
}
else
{
throw
Exception
(
'File does not exist'
);
}
}
Loading