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

refactor: move exportation functions to utils/

parent fb5139f6
No related branches found
No related tags found
1 merge request!14Clhp map
......@@ -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);
});
}
}),
......
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();
});
}
}
});
}
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
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