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
a71f637d
Commit
a71f637d
authored
11 months ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: working JSON exportation, i think
parent
d4ee25c0
No related branches found
No related tags found
1 merge request
!14
Clhp map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/server_requests/init_state.dart
+1
-1
1 addition, 1 deletion
app/lib/server_requests/init_state.dart
app/lib/widgets/main_layout.dart
+68
-2
68 additions, 2 deletions
app/lib/widgets/main_layout.dart
with
69 additions
and
3 deletions
app/lib/server_requests/init_state.dart
+
1
−
1
View file @
a71f637d
...
...
@@ -93,4 +93,4 @@ Future<void> initSearchOptions() async {
Future
<
void
>
setLastLake
()
async
{
final
prefs
=
await
SharedPreferences
.
getInstance
();
await
prefs
.
setString
(
'lastLake'
,
selectedLake
);
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
app/lib/widgets/main_layout.dart
+
68
−
2
View file @
a71f637d
import
'dart:io'
;
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'package:flutter/material.dart'
;
import
'package:google_fonts/google_fonts.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'osm_layer.dart'
;
...
...
@@ -188,10 +191,12 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
),
child:
const
Text
(
"Export JSON"
),
onPressed:
()
{
Navigator
.
pop
(
context
);
Navigator
.
of
(
context
)
.
pop
();
// Show progress indicator
showProgressIndicator
(
context
);
},
)
// Add more children here as needed
],
),
),
...
...
@@ -289,3 +294,64 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
}
}
Future<void> _exportIceData() async {
final directory = await getExternalStorageDirectory();
final file = File('
$
{
directory
?.
path
}
/
ice_data_$selectedLake
.
json
');
// Convert JSON data to string
final jsonString = jsonEncode(selectedMarkerList);
// Write JSON data to file
await file.writeAsString(jsonString);
}
// Display a progress indicator while JSON data is being downloaded
void showProgressIndicator(BuildContext context) {
BuildContext? dialogContext;
showDialog(
context: context,
builder: (BuildContext context) {
dialogContext = context;
return WillPopScope(
onWillPop: () async => false, // Prevent dialog from being closed by user
child: const AlertDialog(
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(), // Progress indicator
SizedBox(height: 20),
Text('
Exporting
JSON
data
...
'),
],
),
),
);
},
);
// Ensure that the progress indicator runs for at lest 1 second
// before exporting the data
Future.delayed(const Duration(milliseconds: 1000), () {
try {
_exportIceData();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('
Downloaded
ice
data
as
JSON
')),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('
Error
exporting
JSON
data:
$e
')),
);
} finally {
if (dialogContext != null) {
// Add 2 second delay before closing the dialog
Future.delayed(const Duration(seconds: 2), () {
Navigator.of(dialogContext!).pop();
});
}
}
});
}
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