Skip to content
Snippets Groups Projects
Commit 99a1542f authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: export to share and download buttons

parent 4b6e0dbf
No related branches found
No related tags found
1 merge request!20Clhp map, fix unit tests
...@@ -11,11 +11,14 @@ Future<void> _exportIceData() async { ...@@ -11,11 +11,14 @@ Future<void> _exportIceData() async {
final directory = await getExternalStorageDirectory(); final directory = await getExternalStorageDirectory();
final file = File('${directory?.path}/ice_data_$selectedLake.json'); final file = File('${directory?.path}/ice_data_$selectedLake.json');
// Convert JSON data to string List<Map<String, dynamic>> measurementsJSON = [];
final jsonString = jsonEncode(selectedMeasurements); // Convert every measurement to JSON
for (var element in selectedMeasurements) {
measurementsJSON.add(element.toJson());
}
// Write JSON data to file // Write JSON data to file
await file.writeAsString(jsonString); await file.writeAsString(measurementsJSON.toString());
} }
......
...@@ -198,21 +198,41 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -198,21 +198,41 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
style: const TextStyle(fontSize: 20), style: const TextStyle(fontSize: 20),
), ),
const SizedBox(height: contPadding), const SizedBox(height: contPadding),
ElevatedButton( Column(
style: ButtonStyle( children: [
backgroundColor: MaterialStateProperty.all<Color>(Colors.white24), ElevatedButton(
), style: ButtonStyle(
child: const Text("Export JSON"), backgroundColor:
onPressed: () { // Export all measurements as JSON MaterialStateProperty.all<Color>(Colors.white24),
List<Map<String, dynamic>> measurementsJSON = []; fixedSize: MaterialStateProperty.all<Size>(
// Convert every measurement to JSON const Size(200.0, 40.0),
for (var element in selectedMeasurements) { ),
measurementsJSON.add(element.toJson()); ),
} child: const Text("Download as JSON"),
// Export the processed data onPressed: () { // Download all measurements as JSON
Share.share(selectedMeasurements.toString()); showProgressIndicator(context);
}, },
) ),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.white24),
fixedSize: MaterialStateProperty.all<Size>(
const Size(200.0, 40.0),
),
),
child: const Text("Share as JSON"),
onPressed: () { // Export all measurements as JSON
List<Map<String, dynamic>> measurementsJSON = [];
// Convert every measurement to JSON
for (var element in selectedMeasurements) {
measurementsJSON.add(element.toJson());
}
// Export the processed data
Share.share(measurementsJSON.toString());
},
),
],
),
], ],
), ),
), ),
...@@ -276,7 +296,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -276,7 +296,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
), ),
], ],
), ),
const SizedBox(height: contPadding), // Padding between containers const SizedBox(height: contPadding*1.7), // Padding between containers
Column( // Ice stats container Column( // Ice stats container
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment