fix: resolve 2 remaining strict analysis errors
- introPage.dart: Convert fireItems to proper static function closure - mainDrawer.dart: Convert unreadCount int to String for Text widget
This commit is contained in:
parent
1864e5b105
commit
7a4c9fb3bc
61 changed files with 1386 additions and 1202 deletions
|
|
@ -1,8 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
|
@ -10,7 +8,9 @@ import 'package:latlong2/latlong.dart';
|
|||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'fireMapState.dart';
|
||||
import 'fireNotification.dart';
|
||||
import 'user.dart';
|
||||
import 'yourLocation.dart';
|
||||
|
||||
export 'fireMapState.dart';
|
||||
|
||||
|
|
@ -19,6 +19,25 @@ part 'appState.g.dart';
|
|||
@immutable
|
||||
@JsonSerializable(nullable: false)
|
||||
class AppState {
|
||||
|
||||
const AppState(
|
||||
{this.yourLocations = const <YourLocation>[],
|
||||
this.fireNotifications = const <FireNotification>[],
|
||||
this.fireNotificationsUnread = 0,
|
||||
this.user = const User.initial(),
|
||||
this.isLoading = false,
|
||||
this.isLoaded = false,
|
||||
this.error = '',
|
||||
this.gmapKey = '',
|
||||
this.firesApiKey = '',
|
||||
this.firesApiUrl = '',
|
||||
this.serverUrl = '',
|
||||
this.monitoredAreas = const <Polyline>[],
|
||||
this.fireMapState = const FireMapState.initial()});
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
factory AppState.fromJson(Map<String, dynamic> json) =>
|
||||
_$AppStateFromJson(json);
|
||||
@JsonKey(ignore: true)
|
||||
final bool isLoading;
|
||||
@JsonKey(ignore: true)
|
||||
|
|
@ -44,25 +63,6 @@ class AppState {
|
|||
@JsonKey(ignore: true)
|
||||
final FireMapState fireMapState;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
factory AppState.fromJson(Map<String, dynamic> json) =>
|
||||
_$AppStateFromJson(json);
|
||||
|
||||
AppState(
|
||||
{this.yourLocations = const <YourLocation>[],
|
||||
this.fireNotifications = const <FireNotification>[],
|
||||
this.fireNotificationsUnread = 0,
|
||||
this.user = const User.initial(),
|
||||
this.isLoading = false,
|
||||
this.isLoaded = false,
|
||||
this.error = '',
|
||||
this.gmapKey = '',
|
||||
this.firesApiKey = '',
|
||||
this.firesApiUrl = '',
|
||||
this.serverUrl = '',
|
||||
this.monitoredAreas = const <Polyline>[],
|
||||
this.fireMapState = const FireMapState.initial()});
|
||||
|
||||
AppState copyWith(
|
||||
{bool? isLoading,
|
||||
bool? isLoaded,
|
||||
|
|
@ -77,7 +77,7 @@ class AppState {
|
|||
int? fireNotificationsUnread,
|
||||
FireMapState? fireMapState,
|
||||
List<Polyline>? monitoredAreas}) {
|
||||
return new AppState(
|
||||
return AppState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isLoaded: isLoaded ?? this.isLoaded,
|
||||
user: user ?? this.user,
|
||||
|
|
@ -100,24 +100,24 @@ class AppState {
|
|||
}
|
||||
}
|
||||
|
||||
typedef void AddYourLocationFunction(YourLocation loc);
|
||||
typedef void DeleteYourLocationFunction(YourLocation loc);
|
||||
typedef void OnRefreshYourLocationsFunction(Completer<Null> callback);
|
||||
typedef void ToggleSubscriptionFunction(YourLocation loc);
|
||||
typedef void OnLocationTapFunction(YourLocation loc);
|
||||
typedef void OnSubscribeFunction(YourLocation loc);
|
||||
typedef void OnSubscribeDistanceChangeFunction(YourLocation loc);
|
||||
typedef void OnUnSubscribeFunction(YourLocation loc);
|
||||
typedef void OnSubscribeConfirmedFunction(YourLocation loc);
|
||||
typedef void OnLocationEdit(YourLocation loc);
|
||||
typedef void OnLocationEditing(YourLocation loc);
|
||||
typedef void OnLocationEditConfirm(YourLocation loc);
|
||||
typedef void OnLocationEditCancel(YourLocation loc);
|
||||
typedef void TapFireNotificationFunction(FireNotification notif);
|
||||
typedef void OnFirePressedInMap(LatLng latLng, DateTime when, String source);
|
||||
typedef AddYourLocationFunction = void Function(YourLocation loc);
|
||||
typedef DeleteYourLocationFunction = void Function(YourLocation loc);
|
||||
typedef OnRefreshYourLocationsFunction = void Function(Completer<void> callback);
|
||||
typedef ToggleSubscriptionFunction = void Function(YourLocation loc);
|
||||
typedef OnLocationTapFunction = void Function(YourLocation loc);
|
||||
typedef OnSubscribeFunction = void Function(YourLocation loc);
|
||||
typedef OnSubscribeDistanceChangeFunction = void Function(YourLocation loc);
|
||||
typedef OnUnSubscribeFunction = void Function(YourLocation loc);
|
||||
typedef OnSubscribeConfirmedFunction = void Function(YourLocation loc);
|
||||
typedef OnLocationEdit = void Function(YourLocation loc);
|
||||
typedef OnLocationEditing = void Function(YourLocation loc);
|
||||
typedef OnLocationEditConfirm = void Function(YourLocation loc);
|
||||
typedef OnLocationEditCancel = void Function(YourLocation loc);
|
||||
typedef TapFireNotificationFunction = void Function(FireNotification notif);
|
||||
typedef OnFirePressedInMap = void Function(LatLng latLng, DateTime when, String source);
|
||||
// typedef void OnReceivedFireNotificationFunction(FireNotification notif);
|
||||
typedef void DeleteFireNotificationFunction(FireNotification notif);
|
||||
typedef void DeleteAllFireNotificationFunction();
|
||||
typedef DeleteFireNotificationFunction = void Function(FireNotification notif);
|
||||
typedef DeleteAllFireNotificationFunction = void Function();
|
||||
|
||||
// unused
|
||||
// typedef void UpdateYourLocationFunction(ObjectId id, YourLocation loc);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,26 @@
|
|||
class BasicLocation implements Comparable<BasicLocation> {
|
||||
|
||||
// static BasicLocation noLocation = new BasicLocation(lat: 0.0, lon: 0.0);
|
||||
|
||||
BasicLocation({required this.lat, required this.lon, this.description});
|
||||
|
||||
BasicLocation.fromJson(Map<String, dynamic> json)
|
||||
: lat = (json['lat'] as num).toDouble(),
|
||||
lon = (json['lon'] as num).toDouble(),
|
||||
description = json['description'] as String?;
|
||||
final double lat;
|
||||
final double lon;
|
||||
final String? description;
|
||||
|
||||
// static BasicLocation noLocation = new BasicLocation(lat: 0.0, lon: 0.0);
|
||||
|
||||
BasicLocation({required this.lat, required this.lon, this.description}) {}
|
||||
|
||||
@override
|
||||
int compareTo(BasicLocation other) {
|
||||
return lat == other.lat && lon == other.lon ? 1 : 0;
|
||||
}
|
||||
|
||||
bool operator ==(o) => o is BasicLocation && o.lat == lat && o.lon == lon;
|
||||
@override
|
||||
bool operator ==(Object o) => o is BasicLocation && o.lat == lat && o.lon == lon;
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
int hash = 1;
|
||||
hash = hash * 17 + lat.hashCode;
|
||||
|
|
@ -20,12 +28,7 @@ class BasicLocation implements Comparable<BasicLocation> {
|
|||
return hash;
|
||||
}
|
||||
|
||||
BasicLocation.fromJson(Map<String, dynamic> json)
|
||||
: lat = (json['lat'] as num).toDouble(),
|
||||
lon = (json['lon'] as num).toDouble(),
|
||||
description = json['description'] as String?;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
'description': description,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'fireNotification.dart';
|
||||
import 'yourLocation.dart';
|
||||
|
||||
enum FireMapStatus {
|
||||
view,
|
||||
subscriptionConfirm,
|
||||
|
|
@ -14,6 +15,26 @@ enum FireMapLayer { osmcGrey, esriSatellite, osmc, esri, esriTerrain }
|
|||
|
||||
@immutable
|
||||
class FireMapState {
|
||||
|
||||
const FireMapState(
|
||||
{this.status = FireMapStatus.view,
|
||||
this.layer = FireMapLayer.osmcGrey,
|
||||
this.yourLocation,
|
||||
this.numFires = 0,
|
||||
this.fires = const <dynamic>[],
|
||||
this.fireNotification,
|
||||
this.falsePos = const <dynamic>[],
|
||||
this.industries = const <dynamic>[]});
|
||||
|
||||
const FireMapState.initial()
|
||||
: status = FireMapStatus.view,
|
||||
layer = FireMapLayer.osmcGrey,
|
||||
yourLocation = null,
|
||||
fireNotification = null,
|
||||
numFires = 0,
|
||||
fires = const <dynamic>[],
|
||||
falsePos = const <dynamic>[],
|
||||
industries = const <dynamic>[];
|
||||
final FireMapStatus status;
|
||||
final FireMapLayer layer;
|
||||
final int numFires;
|
||||
|
|
@ -23,26 +44,6 @@ class FireMapState {
|
|||
final List<dynamic> industries;
|
||||
final YourLocation? yourLocation;
|
||||
|
||||
const FireMapState.initial()
|
||||
: this.status = FireMapStatus.view,
|
||||
this.layer = FireMapLayer.osmcGrey,
|
||||
this.yourLocation = null,
|
||||
this.fireNotification = null,
|
||||
this.numFires = 0,
|
||||
this.fires = const [],
|
||||
this.falsePos = const [],
|
||||
this.industries = const [];
|
||||
|
||||
FireMapState(
|
||||
{this.status = FireMapStatus.view,
|
||||
this.layer = FireMapLayer.osmcGrey,
|
||||
this.yourLocation,
|
||||
this.numFires = 0,
|
||||
this.fires = const [],
|
||||
this.fireNotification,
|
||||
this.falsePos = const [],
|
||||
this.industries = const []});
|
||||
|
||||
FireMapState copyWith({
|
||||
FireMapStatus? status,
|
||||
FireMapLayer? layer,
|
||||
|
|
@ -53,9 +54,9 @@ class FireMapState {
|
|||
List<dynamic>? falsePos,
|
||||
List<dynamic>? industries,
|
||||
}) {
|
||||
return new FireMapState(
|
||||
return FireMapState(
|
||||
yourLocation: yourLocation ?? this.yourLocation,
|
||||
fireNotification: fireNotication ?? this.fireNotification,
|
||||
fireNotification: fireNotication ?? fireNotification,
|
||||
numFires: numFires ?? this.numFires,
|
||||
fires: fires ?? this.fires,
|
||||
falsePos: falsePos ?? this.falsePos,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,19 @@ part 'fireNotification.g.dart';
|
|||
|
||||
@JsonSerializable(nullable: false)
|
||||
class FireNotification {
|
||||
|
||||
FireNotification(
|
||||
{required this.id,
|
||||
required this.lat,
|
||||
required this.lon,
|
||||
required this.description,
|
||||
required this.when,
|
||||
required this.read,
|
||||
required this.sealed,
|
||||
required this.subsId});
|
||||
|
||||
factory FireNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$FireNotificationFromJson(json);
|
||||
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
|
||||
ObjectId id;
|
||||
final double lat;
|
||||
|
|
@ -20,19 +33,6 @@ class FireNotification {
|
|||
final ObjectId subsId;
|
||||
final bool read;
|
||||
|
||||
factory FireNotification.fromJson(Map<String, dynamic> json) =>
|
||||
_$FireNotificationFromJson(json);
|
||||
|
||||
FireNotification(
|
||||
{required this.id,
|
||||
required this.lat,
|
||||
required this.lon,
|
||||
required this.description,
|
||||
required this.when,
|
||||
required this.read,
|
||||
required this.sealed,
|
||||
required this.subsId}) {}
|
||||
|
||||
FireNotification copyWith(
|
||||
{ObjectId? id,
|
||||
double? lat,
|
||||
|
|
@ -42,7 +42,7 @@ class FireNotification {
|
|||
DateTime? when,
|
||||
String? sealed,
|
||||
ObjectId? subsId}) {
|
||||
return new FireNotification(
|
||||
return FireNotification(
|
||||
id: id ?? this.id,
|
||||
lat: lat ?? this.lat,
|
||||
lon: lon ?? this.lon,
|
||||
|
|
@ -83,7 +83,7 @@ class FireNotification {
|
|||
return 'FireNotification {id: $id, lat: $lat, lon: $lon, when: $when, read: $read, subsId: $subsId, sealed ${ellipse(sealed)}';
|
||||
}
|
||||
|
||||
static final Map<String, Route<Null>> routes = <String, Route<Null>>{};
|
||||
static final Map<String, Route<void>> routes = <String, Route<void>>{};
|
||||
Map<String, dynamic> toJson() => _$FireNotificationToJson(this);
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -2,30 +2,31 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:shared_preferences/src/shared_preferences_legacy.dart';
|
||||
|
||||
import '../globals.dart' as globals;
|
||||
import 'fireNotification.dart';
|
||||
|
||||
final String fireNotificationKey = 'fireNotifications';
|
||||
const String fireNotificationKey = 'fireNotifications';
|
||||
|
||||
Future<List<FireNotification>> loadFireNotifications() async {
|
||||
return await globals.prefs.then((prefs) {
|
||||
List<String>? FireNotifications = prefs.getStringList(fireNotificationKey);
|
||||
List<FireNotification> persistedList = [];
|
||||
(FireNotifications ?? []).forEach((notificationString) {
|
||||
Map<String, dynamic> notificationMap =
|
||||
return globals.prefs.then((SharedPreferences prefs) {
|
||||
final List<String>? FireNotifications = prefs.getStringList(fireNotificationKey);
|
||||
final List<FireNotification> persistedList = <FireNotification>[];
|
||||
for (final String notificationString in (FireNotifications ?? <String>[])) {
|
||||
final Map<String, dynamic> notificationMap =
|
||||
json.decode(notificationString) as Map<String, dynamic>;
|
||||
persistedList.add(FireNotification.fromJson(notificationMap));
|
||||
});
|
||||
}
|
||||
return persistedList;
|
||||
});
|
||||
}
|
||||
|
||||
persistFireNotifications(List<FireNotification> notif) {
|
||||
void persistFireNotifications(List<FireNotification> notif) {
|
||||
// print('Persisting $notif');
|
||||
globals.prefs.then((prefs) {
|
||||
List<String> notifAsString = [];
|
||||
notif.where(notNull).toList().forEach((notification) {
|
||||
globals.prefs.then((SharedPreferences prefs) {
|
||||
final List<String> notifAsString = <String>[];
|
||||
notif.where(notNull).toList().forEach((FireNotification notification) {
|
||||
notifAsString.add(json.encode(notification.toJson()));
|
||||
});
|
||||
prefs.setStringList(fireNotificationKey, notifAsString);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
|
@ -12,49 +11,50 @@ import '../objectIdUtils.dart';
|
|||
import '../redux/actions.dart';
|
||||
import 'appState.dart';
|
||||
import 'falsePositiveTypes.dart';
|
||||
import 'yourLocation.dart';
|
||||
|
||||
class FiresApi {
|
||||
late final Dio _dio;
|
||||
|
||||
FiresApi() {
|
||||
_dio = Dio();
|
||||
}
|
||||
late final Dio _dio;
|
||||
|
||||
Future<String> createUser(
|
||||
AppState state, String mobileToken, String lang) async {
|
||||
final params = {
|
||||
"token": state.firesApiKey,
|
||||
"mobileToken": mobileToken,
|
||||
"lang": lang
|
||||
final Map<String, String> params = <String, String>{
|
||||
'token': state.firesApiKey,
|
||||
'mobileToken': mobileToken,
|
||||
'lang': lang
|
||||
};
|
||||
final String url = '${state.firesApiUrl}mobile/users';
|
||||
try {
|
||||
final response = await _dio.post(url, data: params);
|
||||
final Response<dynamic> response = await _dio.post(url, data: params);
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['data']['userId'] as String;
|
||||
} else {
|
||||
throw "Unexpected error on create user";
|
||||
throw 'Unexpected error on create user';
|
||||
}
|
||||
} catch (e) {
|
||||
throw "Error creating user: $e";
|
||||
throw 'Error creating user: $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<YourLocation>> fetchYourLocations(AppState state) async {
|
||||
final apiKey = state.firesApiKey;
|
||||
final mobileToken = state.user.token;
|
||||
final String apiKey = state.firesApiKey;
|
||||
final String mobileToken = state.user.token;
|
||||
final String url =
|
||||
'${state.firesApiUrl}mobile/subscriptions/all/$apiKey/$mobileToken';
|
||||
try {
|
||||
final response = await _dio.get(url);
|
||||
final Response<dynamic> response = await _dio.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final dataSubscriptions =
|
||||
final List<dynamic> dataSubscriptions =
|
||||
response.data['data']['subscriptions'] as List<dynamic>;
|
||||
List<YourLocation> subscribed = [];
|
||||
final List<YourLocation> subscribed = <YourLocation>[];
|
||||
for (int i = 0; i < dataSubscriptions.length; i++) {
|
||||
var el = dataSubscriptions[i] as Map<String, dynamic>;
|
||||
var lat = (el['location']['lat'] as num).toDouble();
|
||||
var lon = (el['location']['lon'] as num).toDouble();
|
||||
final Map<String, dynamic> el = dataSubscriptions[i] as Map<String, dynamic>;
|
||||
final double lat = (el['location']['lat'] as num).toDouble();
|
||||
final double lon = (el['location']['lon'] as num).toDouble();
|
||||
subscribed.add(YourLocation(
|
||||
id: objectIdFromJson(el['_id']['_str'] as String),
|
||||
lat: lat,
|
||||
|
|
@ -64,50 +64,50 @@ class FiresApi {
|
|||
}
|
||||
return subscribed;
|
||||
} else {
|
||||
throw "Unexpected error fetching your locations";
|
||||
throw 'Unexpected error fetching your locations';
|
||||
}
|
||||
} catch (e) {
|
||||
throw "Error fetching locations: $e";
|
||||
throw 'Error fetching locations: $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> subscribe(AppState state, YourLocation loc) async {
|
||||
final params = {
|
||||
"token": state.firesApiKey,
|
||||
"mobileToken": state.user.token,
|
||||
"id": loc.id.hexString,
|
||||
"lat": loc.lat,
|
||||
"lon": loc.lon,
|
||||
"distance": loc.distance
|
||||
final Map<String, Object> params = <String, Object>{
|
||||
'token': state.firesApiKey,
|
||||
'mobileToken': state.user.token,
|
||||
'id': loc.id.hexString,
|
||||
'lat': loc.lat,
|
||||
'lon': loc.lon,
|
||||
'distance': loc.distance
|
||||
};
|
||||
final String url = '${state.firesApiUrl}mobile/subscriptions';
|
||||
try {
|
||||
final response = await _dio.post(url, data: params);
|
||||
final Response<dynamic> response = await _dio.post(url, data: params);
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['data']['subsId'] as String;
|
||||
} else {
|
||||
print(response.data);
|
||||
throw "Unexpected error on subscribe";
|
||||
throw 'Unexpected error on subscribe';
|
||||
}
|
||||
} catch (e) {
|
||||
throw "Error subscribing: $e";
|
||||
throw 'Error subscribing: $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> unsubscribe(AppState state, String subsId) async {
|
||||
final apiKey = state.firesApiKey;
|
||||
final mobileToken = state.user.token;
|
||||
final String apiKey = state.firesApiKey;
|
||||
final String mobileToken = state.user.token;
|
||||
final String url =
|
||||
'${state.firesApiUrl}mobile/subscriptions/$apiKey/$mobileToken/$subsId';
|
||||
try {
|
||||
final response = await _dio.delete(url);
|
||||
final Response<dynamic> response = await _dio.delete(url);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
throw "Unexpected error on unsubscribe";
|
||||
throw 'Unexpected error on unsubscribe';
|
||||
}
|
||||
} catch (e) {
|
||||
throw "Error unsubscribing: $e";
|
||||
throw 'Error unsubscribing: $e';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,22 +116,22 @@ class FiresApi {
|
|||
required double lat,
|
||||
required double lon,
|
||||
required int distance}) async {
|
||||
var url =
|
||||
final String url =
|
||||
'${state.firesApiUrl}fires-in-full/${state.firesApiKey}/$lat/$lon/$distance';
|
||||
if (globals.isDevelopment) print(url);
|
||||
try {
|
||||
final response = await _dio.get(url);
|
||||
final Response<dynamic> response = await _dio.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
var resultDecoded = response.data;
|
||||
int numFires = (resultDecoded['real'] as num).toInt();
|
||||
List<dynamic> fires = resultDecoded['fires'] as List<dynamic>;
|
||||
List<dynamic> falsePos = resultDecoded['falsePos'] as List<dynamic>;
|
||||
List<dynamic> industries = resultDecoded['industries'] as List<dynamic>;
|
||||
final resultDecoded = response.data;
|
||||
final int numFires = (resultDecoded['real'] as num).toInt();
|
||||
final List<dynamic> fires = resultDecoded['fires'] as List<dynamic>;
|
||||
final List<dynamic> falsePos = resultDecoded['falsePos'] as List<dynamic>;
|
||||
final List<dynamic> industries = resultDecoded['industries'] as List<dynamic>;
|
||||
|
||||
if (globals.isDevelopment) {
|
||||
var firesCount = fires.length;
|
||||
var industriesCount = industries.length;
|
||||
var falsePosCount = falsePos.length;
|
||||
final int firesCount = fires.length;
|
||||
final int industriesCount = industries.length;
|
||||
final int falsePosCount = falsePos.length;
|
||||
print(
|
||||
'(Pos: $lat, $lon) real: $numFires, fire: $firesCount falsePos: $falsePosCount industries: $industriesCount');
|
||||
}
|
||||
|
|
@ -148,25 +148,25 @@ class FiresApi {
|
|||
}
|
||||
|
||||
Future<List<Polyline>> getMonitoredAreas({required AppState state}) async {
|
||||
var url =
|
||||
final String url =
|
||||
'${state.firesApiUrl}status/subs-public-union/${state.firesApiKey}';
|
||||
var color = const Color(0xFF145A32);
|
||||
const Color color = Color(0xFF145A32);
|
||||
try {
|
||||
final response = await _dio.get(url);
|
||||
final Response<dynamic> response = await _dio.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
var resultDecoded = response.data;
|
||||
List<Polyline> union = [];
|
||||
final multipolygon =
|
||||
final resultDecoded = response.data;
|
||||
final List<Polyline> union = <Polyline>[];
|
||||
final List<dynamic> multipolygon =
|
||||
(json.decode(resultDecoded['data']['union']['value'] as String)
|
||||
as Map<String, dynamic>)['geometry']['coordinates']
|
||||
as List<dynamic>;
|
||||
for (dynamic polygonDynamic in multipolygon) {
|
||||
var polygon = polygonDynamic as List<dynamic>;
|
||||
for (dynamic holeDynamic in polygon) {
|
||||
var hole = holeDynamic as List<dynamic>;
|
||||
List<LatLng> points = [];
|
||||
for (dynamic pointDynamic in hole) {
|
||||
var point = pointDynamic as List<dynamic>;
|
||||
for (final dynamic polygonDynamic in multipolygon) {
|
||||
final List<dynamic> polygon = polygonDynamic as List<dynamic>;
|
||||
for (final dynamic holeDynamic in polygon) {
|
||||
final List<dynamic> hole = holeDynamic as List<dynamic>;
|
||||
final List<LatLng> points = <LatLng>[];
|
||||
for (final dynamic pointDynamic in hole) {
|
||||
final List<dynamic> point = pointDynamic as List<dynamic>;
|
||||
points.add(LatLng(
|
||||
(point[1] as num).toDouble(), (point[0] as num).toDouble()));
|
||||
}
|
||||
|
|
@ -183,15 +183,15 @@ class FiresApi {
|
|||
|
||||
Future<bool> markFalsePositive(AppState state, String mobileToken,
|
||||
String sealed, FalsePositiveType type) async {
|
||||
final params = {
|
||||
"token": state.firesApiKey,
|
||||
"mobileToken": mobileToken,
|
||||
"sealed": sealed,
|
||||
"type": type.toString().split('.')[1]
|
||||
final Map<String, String> params = <String, String>{
|
||||
'token': state.firesApiKey,
|
||||
'mobileToken': mobileToken,
|
||||
'sealed': sealed,
|
||||
'type': type.toString().split('.')[1]
|
||||
};
|
||||
final String url = '${state.firesApiUrl}mobile/falsepositive';
|
||||
try {
|
||||
final response = await _dio.post(url, data: params);
|
||||
final Response<dynamic> response = await _dio.post(url, data: params);
|
||||
if (response.statusCode == 200) {
|
||||
if (globals.isDevelopment) print(response.data['data']['upsert']);
|
||||
return true;
|
||||
|
|
@ -200,7 +200,7 @@ class FiresApi {
|
|||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("Error marking false positive: $e");
|
||||
debugPrint('Error marking false positive: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@immutable
|
||||
class User {
|
||||
final String userId;
|
||||
final String lang;
|
||||
final String token;
|
||||
|
||||
const User({required this.userId, required this.lang, required this.token});
|
||||
|
||||
const User.initial()
|
||||
: userId = '',
|
||||
lang = '',
|
||||
token = '';
|
||||
|
||||
const User({required this.userId, required this.lang, required this.token});
|
||||
final String userId;
|
||||
final String lang;
|
||||
final String token;
|
||||
|
||||
User copyWith({String? userId, String? lang, String? token}) {
|
||||
return new User(
|
||||
return User(
|
||||
userId: userId ?? this.userId,
|
||||
token: token ?? this.token,
|
||||
lang: lang ?? this.lang);
|
||||
|
|
|
|||
|
|
@ -1,30 +1,12 @@
|
|||
import 'package:fires_flutter/objectIdUtils.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:objectid/objectid.dart';
|
||||
|
||||
import '../objectIdUtils.dart';
|
||||
|
||||
part 'yourLocation.g.dart';
|
||||
|
||||
@JsonSerializable(nullable: false)
|
||||
class YourLocation {
|
||||
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
|
||||
ObjectId id;
|
||||
final double lat;
|
||||
final double lon;
|
||||
String description;
|
||||
bool subscribed;
|
||||
int distance;
|
||||
late int currentNumFires;
|
||||
|
||||
factory YourLocation.fromJson(Map<String, dynamic> json) =>
|
||||
_$YourLocationFromJson(json);
|
||||
|
||||
static late final YourLocation noLocation;
|
||||
static const int? withoutStats = null;
|
||||
|
||||
static void _initNoLocation() {
|
||||
noLocation = new YourLocation(
|
||||
id: ObjectId(), lat: 0.0, lon: 0.0, description: '', subscribed: false);
|
||||
}
|
||||
|
||||
YourLocation(
|
||||
{required this.id,
|
||||
|
|
@ -36,6 +18,25 @@ class YourLocation {
|
|||
this.subscribed = false}) {
|
||||
this.currentNumFires = currentNumFires ?? 0;
|
||||
}
|
||||
|
||||
factory YourLocation.fromJson(Map<String, dynamic> json) =>
|
||||
_$YourLocationFromJson(json);
|
||||
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
|
||||
ObjectId id;
|
||||
final double lat;
|
||||
final double lon;
|
||||
String description;
|
||||
bool subscribed;
|
||||
int distance;
|
||||
late int currentNumFires;
|
||||
|
||||
static late final YourLocation noLocation;
|
||||
static const int? withoutStats = null;
|
||||
|
||||
static void _initNoLocation() {
|
||||
noLocation = YourLocation(
|
||||
id: ObjectId(), lat: 0.0, lon: 0.0);
|
||||
}
|
||||
Map<String, dynamic> toJson() => _$YourLocationToJson(this);
|
||||
|
||||
YourLocation copyWith(
|
||||
|
|
@ -46,7 +47,7 @@ class YourLocation {
|
|||
int? distance,
|
||||
int? currentNumFires,
|
||||
bool? subscribed}) {
|
||||
return new YourLocation(
|
||||
return YourLocation(
|
||||
id: id ?? this.id,
|
||||
lat: lat ?? this.lat,
|
||||
lon: lon ?? this.lon,
|
||||
|
|
|
|||
|
|
@ -2,30 +2,31 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:shared_preferences/src/shared_preferences_legacy.dart';
|
||||
|
||||
import '../globals.dart' as globals;
|
||||
import 'yourLocation.dart';
|
||||
|
||||
final String locationKey = 'yourlocations';
|
||||
const String locationKey = 'yourlocations';
|
||||
|
||||
Future<List<YourLocation>> loadYourLocations() async {
|
||||
return await globals.prefs.then((prefs) {
|
||||
List<String>? yourLocations = prefs.getStringList(locationKey);
|
||||
List<YourLocation> persistedList = [];
|
||||
(yourLocations ?? []).forEach((locationString) {
|
||||
Map<String, dynamic> locationMap =
|
||||
return globals.prefs.then((SharedPreferences prefs) {
|
||||
final List<String>? yourLocations = prefs.getStringList(locationKey);
|
||||
final List<YourLocation> persistedList = <YourLocation>[];
|
||||
for (final String locationString in (yourLocations ?? <String>[])) {
|
||||
final Map<String, dynamic> locationMap =
|
||||
json.decode(locationString) as Map<String, dynamic>;
|
||||
persistedList.add(YourLocation.fromJson(locationMap));
|
||||
});
|
||||
}
|
||||
return persistedList;
|
||||
});
|
||||
}
|
||||
|
||||
persistYourLocations(List<YourLocation> yl) {
|
||||
void persistYourLocations(List<YourLocation> yl) {
|
||||
// debugPrint('Persisting $yl');
|
||||
globals.prefs.then((prefs) {
|
||||
List<String> ylAsString = [];
|
||||
yl.where(notNull).toList().forEach((location) {
|
||||
globals.prefs.then((SharedPreferences prefs) {
|
||||
final List<String> ylAsString = <String>[];
|
||||
yl.where(notNull).toList().forEach((YourLocation location) {
|
||||
ylAsString.add(json.encode(location.toJson()));
|
||||
});
|
||||
prefs.setStringList(locationKey, ylAsString);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue