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
f3645dc2
Commit
f3645dc2
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
refactor: move exportation functions to utils/
parent
fb5139f6
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Clhp map
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/pages/default_page.dart
+1
-1
1 addition, 1 deletion
app/lib/pages/default_page.dart
app/lib/utils/export_data.dart
+69
-0
69 additions, 0 deletions
app/lib/utils/export_data.dart
app/lib/widgets/main_layout.dart
+2
-66
2 additions, 66 deletions
app/lib/widgets/main_layout.dart
with
72 additions
and
67 deletions
app/lib/pages/default_page.dart
+
1
−
1
View file @
f3645dc2
...
...
@@ -64,10 +64,10 @@ class _DefaultPageState extends State<DefaultPage> {
delegate:
CustomSearchDelegate
((
String
result
)
{
// Make request only if the selected lake is different from the current selected lake
if
(
result
!=
selectedLake
)
{
initialiseState
(
false
);
setState
(()
{
selectedLake
=
result
;
// NB update lastLake persistent variable
initialiseState
(
false
);
});
}
}),
...
...
This diff is collapsed.
Click to expand it.
app/lib/utils/export_data.dart
0 → 100644
+
69
−
0
View file @
f3645dc2
import
'dart:io'
;
import
'dart:convert'
;
import
'package:flutter/material.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'../../consts.dart'
;
// Saves all measurements to a file on the users mobile device
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
Future
.
delayed
(
const
Duration
(
seconds:
1
),
()
{
try
{
// Download JSON data
_exportIceData
();
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'Downloaded ice data as JSON'
)),
);
}
catch
(
e
)
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
SnackBar
(
content:
Text
(
'Failed to export 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
();
Navigator
.
of
(
context
)
.
pop
();
});
}
}
});
}
This diff is collapsed.
Click to expand it.
app/lib/widgets/main_layout.dart
+
2
−
66
View file @
f3645dc2
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'
;
...
...
@@ -13,6 +10,7 @@ import 'choropleth_map.dart';
import
'../data_classes.dart'
;
import
'satellite_layer.dart'
;
import
'quick_view_chart.dart'
;
import
'../utils/export_data.dart'
;
import
'../utils/format_month.dart'
;
/// MapContainerWidget is the main widget that contains the map with all
...
...
@@ -291,66 +289,4 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
},
);
}
}
// Saves all measurements to a file on the users mobile device
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
Future.delayed(const Duration(seconds: 1), () {
try { // Download JSON data
_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();
Navigator.of(context).pop();
});
}
}
});
}
}
\ 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