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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue