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

fix: export functionality to use built in android share

parent bc0bb7e1
No related branches found
No related tags found
1 merge request!20Clhp map, fix unit tests
import 'dart:core'; import 'dart:core';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:flutter/material.dart';
class Measurement { class Measurement {
int measurementID; int measurementID;
...@@ -41,11 +40,21 @@ class Measurement { ...@@ -41,11 +40,21 @@ class Measurement {
} }
} }
Map<String, dynamic> toJson() {
return {
'MeasurementID': measurementID,
'TimeMeasured': timeMeasured.toIso8601String(),
'Sensor': sensor.toJson(),
'BodyOfWater': bodyOfWater,
'CenterLat': center.latitude,
'CenterLon': center.longitude,
'Subdivisions': subDivs.map((subDiv) => subDiv.toJson()).toList(),
};
}
} }
class SubDiv { class SubDiv {
String sub_div_id; String sub_div_id;
int groupID;
double minThickness; double minThickness;
double avgThickness; double avgThickness;
LatLng center; LatLng center;
...@@ -55,7 +64,6 @@ class SubDiv { ...@@ -55,7 +64,6 @@ class SubDiv {
SubDiv({ SubDiv({
required this.sub_div_id, required this.sub_div_id,
required this.groupID,
required this.minThickness, required this.minThickness,
required this.avgThickness, required this.avgThickness,
required this.center, required this.center,
...@@ -68,7 +76,6 @@ class SubDiv { ...@@ -68,7 +76,6 @@ class SubDiv {
try { try {
return SubDiv( return SubDiv(
sub_div_id: json['SubdivID'].toString(), sub_div_id: json['SubdivID'].toString(),
groupID: json['GroupID'] ?? 0,
minThickness: (json['MinThickness'] as num?)?.toDouble() ?? 0, minThickness: (json['MinThickness'] as num?)?.toDouble() ?? 0,
avgThickness: (json['AvgThickness'] as num?)?.toDouble() ?? 0, avgThickness: (json['AvgThickness'] as num?)?.toDouble() ?? 0,
center: json['CenLatitude'] != null && json['CenLongitude'] != null center: json['CenLatitude'] != null && json['CenLongitude'] != null
...@@ -85,6 +92,25 @@ class SubDiv { ...@@ -85,6 +92,25 @@ class SubDiv {
throw FormatException('Error parsing SubDiv: $e'); throw FormatException('Error parsing SubDiv: $e');
} }
} }
Map<String, dynamic> toJson() {
// Call the toJson method of every element in the list 'iceStats'
List<Map<String, dynamic>> iceStatsJSON = [];
for (var element in iceStats) {
iceStatsJSON.add(element.toJson());
}
return {
'SubdivID': sub_div_id,
'MinThickness': minThickness,
'AvgThickness': avgThickness,
'CenLatitude': center.latitude,
'CenLongitude': center.longitude,
'Accuracy': accuracy,
'Color': color,
'IceStats': iceStatsJSON,
};
}
} }
class IceStats { class IceStats {
...@@ -137,6 +163,19 @@ class IceStats { ...@@ -137,6 +163,19 @@ class IceStats {
throw FormatException('Error parsing IceStats: $e'); throw FormatException('Error parsing IceStats: $e');
} }
} }
Map<String, dynamic> toJson() {
return {
'Date': dateTime.toIso8601String(), // Convert DateTime object to string
'Slush ice (m)': slushIce,
'Black ice (m)': blackIce,
'Total ice (m)': totalIce,
'Snow depth (m)': snowDepth,
'Total snow (m)': totalSnow,
'Cloud cover': cloudCover,
'Temperature (t)': temperature,
};
}
} }
class Sensor { class Sensor {
...@@ -166,4 +205,12 @@ class Sensor { ...@@ -166,4 +205,12 @@ class Sensor {
throw FormatException('Error parsing Sensor: $e'); throw FormatException('Error parsing Sensor: $e');
} }
} }
Map<String, dynamic> toJson() {
return {
'SensorID': sensorID,
'SensorType': sensorType,
'Active': active,
};
}
} }
import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
...@@ -201,10 +203,14 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -201,10 +203,14 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
backgroundColor: MaterialStateProperty.all<Color>(Colors.white24), backgroundColor: MaterialStateProperty.all<Color>(Colors.white24),
), ),
child: const Text("Export JSON"), child: const Text("Export JSON"),
onPressed: () { onPressed: () { // Export all measurements as JSON
// Close bottom sheet before displaying progress bar List<Map<String, dynamic>> measurementsJSON = [];
showProgressIndicator(context); // Convert every measurement to JSON
for (var element in selectedMeasurements) {
measurementsJSON.add(element.toJson());
}
// Export the processed data
Share.share(selectedMeasurements.toString());
}, },
) )
], ],
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_linux
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST
......
...@@ -7,10 +7,14 @@ import Foundation ...@@ -7,10 +7,14 @@ import Foundation
import connectivity_plus import connectivity_plus
import path_provider_foundation import path_provider_foundation
import share_plus_macos
import shared_preferences_foundation import shared_preferences_foundation
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
} }
...@@ -65,6 +65,14 @@ packages: ...@@ -65,6 +65,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.4" version: "1.2.4"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32"
url: "https://pub.dev"
source: hosted
version: "0.3.4+1"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
...@@ -109,10 +117,18 @@ packages: ...@@ -109,10 +117,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: file name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "7.0.0" version: "6.1.4"
fixnum:
dependency: transitive
description:
name: fixnum
sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
fl_chart: fl_chart:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -296,6 +312,14 @@ packages: ...@@ -296,6 +312,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
mime:
dependency: transitive
description:
name: mime
sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
nested: nested:
dependency: transitive dependency: transitive
description: description:
...@@ -440,6 +464,54 @@ packages: ...@@ -440,6 +464,54 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.0.0" version: "5.0.0"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: f582d5741930f3ad1bf0211d358eddc0508cc346e5b4b248bd1e569c995ebb7a
url: "https://pub.dev"
source: hosted
version: "4.5.3"
share_plus_linux:
dependency: transitive
description:
name: share_plus_linux
sha256: dc32bf9f1151b9864bb86a997c61a487967a08f2e0b4feaa9a10538712224da4
url: "https://pub.dev"
source: hosted
version: "3.0.1"
share_plus_macos:
dependency: transitive
description:
name: share_plus_macos
sha256: "44daa946f2845045ecd7abb3569b61cd9a55ae9cc4cbec9895b2067b270697ae"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "251eb156a8b5fa9ce033747d73535bf53911071f8d3b6f4f0b578505ce0d4496"
url: "https://pub.dev"
source: hosted
version: "3.4.0"
share_plus_web:
dependency: transitive
description:
name: share_plus_web
sha256: eaef05fa8548b372253e772837dd1fbe4ce3aca30ea330765c945d7d4f7c9935
url: "https://pub.dev"
source: hosted
version: "3.1.0"
share_plus_windows:
dependency: transitive
description:
name: share_plus_windows
sha256: "3a21515ae7d46988d42130cd53294849e280a5de6ace24bae6912a1bffd757d4"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
shared_preferences: shared_preferences:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -509,6 +581,14 @@ packages: ...@@ -509,6 +581,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
...@@ -597,6 +677,78 @@ packages: ...@@ -597,6 +677,78 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.1" version: "0.3.1"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e"
url: "https://pub.dev"
source: hosted
version: "6.2.6"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "360a6ed2027f18b73c8d98e159dda67a61b7f2e0f6ec26e86c3ada33b0621775"
url: "https://pub.dev"
source: hosted
version: "6.3.1"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "7068716403343f6ba4969b4173cbf3b84fc768042124bc2c011e5d782b24fe89"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
uuid:
dependency: transitive
description:
name: uuid
sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8"
url: "https://pub.dev"
source: hosted
version: "4.4.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
......
...@@ -9,20 +9,21 @@ environment: ...@@ -9,20 +9,21 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_map: ^4.0.0 # Maps ans map customization flutter_map: ^4.0.0 # OpenStreetMap layer
http: ^0.13.3 # HTTPS requests http: ^0.13.3 # HTTPS requests
latlong2: ^0.8.2 # LatLng object latlong2: ^0.8.2 # LatLng object for maps
provider: ^5.0.0 # Ice layer bar chart configuration provider: ^5.0.0 # Ice layer bar chart
fl_chart: ^0.20.0-nullsafety1 # Charts and diagrams fl_chart: ^0.20.0-nullsafety1 # Charts and diagrams
google_fonts: any # Fonts google_fonts: any # Fonts
syncfusion_flutter_maps: ^20.4.41 # Choropleth map_handler syncfusion_flutter_maps: ^20.4.41 # Choropleth map_handler
syncfusion_flutter_core: any # Choropleth shape selection syncfusion_flutter_core: any # Map shape selection
path_provider: ^2.0.8 # Persistent variables path_provider: ^2.0.8 # Persistent file storage
shared_preferences: any # Persistent data storage shared_preferences: any # Persistent variables
fuzzy: any # Search algorithm fuzzy: any # Search algorithm
connectivity_plus: ^3.0.3 # Check internet connection connectivity_plus: ^3.0.3 # Check internet connectivity
get: ^4.6.5 # HTTP get requests get: ^4.6.5 # HTTP GET requests
liquid_pull_to_refresh: ^3.0.0 # Pull to refresh animation liquid_pull_to_refresh: ^3.0.0 # Pull to refresh animation
share_plus: ^4.0.4 # Exportation of lake measurement data
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
......
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <connectivity_plus/connectivity_plus_windows_plugin.h> #include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar( ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus connectivity_plus
url_launcher_windows
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST
......
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