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
cb6c8af5
Commit
cb6c8af5
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: load_saved_data.dart, not used
parent
c44603db
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Clhp map
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/pages/marker_handler/load_saved_data.dart
+51
-0
51 additions, 0 deletions
app/lib/pages/marker_handler/load_saved_data.dart
with
51 additions
and
0 deletions
app/lib/pages/marker_handler/load_saved_data.dart
0 → 100644
+
51
−
0
View file @
cb6c8af5
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'marker_data.dart'
;
import
'../consts.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'dart:typed_data'
;
/// loadSavedData parses json data from a saved file, either to a list
/// of Measurement objects or a Uint8List object depending if it reads
/// measurement data or relation data.
Future
<
FetchResult
>
loadSavedData
()
async
{
Uint8List
relation
;
List
<
Measurement
>
measurements
=
[];
// Get latest saved data from file if the server does not respond
Directory
appDocumentsDirectory
=
await
getApplicationDocumentsDirectory
();
String
filePath
=
'
${appDocumentsDirectory.path}
/last_data.sjon'
;
// Read measurement 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
measurements
=
jsonData
.
map
((
data
)
=
>
Measurement
.
fromJson
(
data
))
.
toList
();
}
else
{
throw
Exception
(
'File does not exist'
);
}
filePath
=
'
${appDocumentsDirectory.path}
/relation.json'
;
// Read relation file contents
file
=
File
(
filePath
);
if
(
await
file
.
exists
())
{
String
contents
=
await
file
.
readAsString
();
List
<
dynamic
>
jsonData
=
json
.
decode
(
contents
);
// Parse JSON string from file
relation
=
Uint8List
.
fromList
(
utf8
.
encode
(
jsonData
.
toString
()));
}
else
{
throw
Exception
(
'File does not exist'
);
}
return
FetchResult
(
relation
,
measurements
,
false
);
}
class
FetchResult
{
final
Uint8List
relation
;
final
List
<
Measurement
>
measurements
;
final
bool
connected
;
FetchResult
(
this
.
relation
,
this
.
measurements
,
this
.
connected
);
}
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