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 {
final directory = await getExternalStorageDirectory();
final file = File('${directory?.path}/ice_data_$selectedLake.json');
// Convert JSON data to string
final jsonString = jsonEncode(selectedMeasurements);
List<Map<String, dynamic>> measurementsJSON = [];
// Convert every measurement to JSON
for (var element in selectedMeasurements) {
measurementsJSON.add(element.toJson());
}
// Write JSON data to file
await file.writeAsString(jsonString);
await file.writeAsString(measurementsJSON.toString());
}
......
......@@ -198,21 +198,41 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: contPadding),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.white24),
),
child: const Text("Export 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(selectedMeasurements.toString());
},
)
Column(
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.white24),
fixedSize: MaterialStateProperty.all<Size>(
const Size(200.0, 40.0),
),
),
child: const Text("Download as JSON"),
onPressed: () { // Download all measurements as JSON
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> {
),
],
),
const SizedBox(height: contPadding), // Padding between containers
const SizedBox(height: contPadding*1.7), // Padding between containers
Column( // Ice stats container
crossAxisAlignment: CrossAxisAlignment.start,
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