Skip to content

V35 #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.13.7'
flutter-version: '3.19.5'

- name: Statically analyze the Dart code for any errors/warnings, ignoring "info" level warnings
run: |
Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion assets/config/dev.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"baseUrl": "https://webdev.mosquitoalert.com"
"baseUrl": "https://api.mosquitoalert.com/v1"
}
Binary file added assets/fonts/Nunito-Black.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-BlackItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-Bold.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-BoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-ExtraBold.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-ExtraLight.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-ExtraLightItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-Italic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-Light.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-LightItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-Medium.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-MediumItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-Regular.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-SemiBold.ttf
Binary file not shown.
Binary file added assets/fonts/Nunito-SemiBoldItalic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Black.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-BlackItalic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Bold.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-BoldItalic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Italic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Light.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-LightItalic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Medium.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-MediumItalic.ttf
Binary file not shown.
Binary file removed assets/fonts/Rubik-Regular.ttf
Binary file not shown.
195 changes: 1 addition & 194 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import 'package:mosquito_alert_app/models/owcampaing.dart';
import 'package:mosquito_alert_app/models/partner.dart';
import 'package:mosquito_alert_app/models/report.dart';
import 'package:mosquito_alert_app/models/response.dart';
import 'package:mosquito_alert_app/models/session.dart';
import 'package:mosquito_alert_app/models/topic.dart';
import 'package:mosquito_alert_app/utils/PushNotificationsManager.dart';
import 'package:mosquito_alert_app/utils/UserManager.dart';
import 'package:mosquito_alert_app/utils/Utils.dart';
import 'package:mosquito_alert_app/app_config.dart';
Expand All @@ -37,19 +35,12 @@ class ApiSingleton {
//Reports
static const reports = '/reports/';

//Session
static const sessions = '/sessions/';
static const sessionUpdate = '/session_update/';

//Images
static const photos = '/photos/';

//Notifications
static const notifications = '/user_notifications/';
static const mark_notification_as_read = '/mark_notif_as_ack/';
static const subscribe_to_topic = '/subscribe_to_topic/';
static const unsub_from_topic = '/unsub_from_topic/';
static const get_my_topics = '/topics_subscribed/';
static const firebaseToken = '/token/';

//Fixes
Expand Down Expand Up @@ -80,7 +71,7 @@ class ApiSingleton {
static Future<void> initialize(String env) async {
final config = await AppConfig.forEnvironment(env: env);
baseUrl = config.baseUrl;
serverUrl = '$baseUrl/api';
serverUrl = baseUrl;
await UserManager.setServerUrl(serverUrl);
}

Expand Down Expand Up @@ -187,104 +178,6 @@ class ApiSingleton {
}
}

//Sessions
Future<dynamic> getLastSession(String? userUUID) async {
try {
final response = await http
.get(
Uri.parse('$serverUrl$sessions?user=$userUUID'),
headers: headers,
)
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);

if (response.statusCode != 200) {
print(
'Request: ${response.request.toString()} -> Response: ${response.body}');
return ApiResponse.fromJson(json.decode(response.body));
} else {
List<dynamic> jsonAnswer = json.decode(response.body);
var allSessions = <Session>[];

for (var item in jsonAnswer) {
allSessions.add(Session.fromJson(item));
}

if (allSessions.isEmpty) {
return 0;
}

return allSessions[0].session_ID;
}
} catch (e) {
print(e);
return false;
}
}

Future<dynamic> createSession(Session session) async {
try {
final response = await http
.post(Uri.parse('$serverUrl$sessions'),
headers: headers,
body: json.encode(
session.toJson(),
))
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
;

if (response.statusCode != 201) {
print(
'Request: ${response.request.toString()} -> Response: ${response.body}');
return ApiResponse.fromJson(json.decode(response.body));
}

var body = json.decode(response.body);
return body['id'];
} catch (e) {
// print(e);
return false;
}
}

Future<dynamic> closeSession(Session session) async {
try {
final response = await http
.put(Uri.parse('$serverUrl$sessionUpdate${session.session_ID}/'),
headers: headers,
body: json.encode({'session_end_time': session.session_end_time}))
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
;

if (response.statusCode != 200) {
print(
'Request: ${response.request.toString()} -> Response: ${response.body}');
return ApiResponse.fromJson(json.decode(response.body));
}

return true;
} catch (e) {
return false;
}
}

//Reports
Future<Report?> createReport(Report report) async {
try {
Expand Down Expand Up @@ -395,8 +288,6 @@ class ApiSingleton {
var jsonAnswer = json.decode(response.body);
var newReport = await Report.fromJsonAsync(jsonAnswer);

await PushNotificationsManager.subscribeToReportResult(newReport);

await getUserScores();
return newReport;
} catch (e) {
Expand Down Expand Up @@ -674,90 +565,6 @@ class ApiSingleton {
}
}

Future<bool> subscribeToTopic(
String userIdentifier, String? topicIdentifier) async {
try {
final response = await http
.post(
Uri.parse(
'$serverUrl$subscribe_to_topic?user=$userIdentifier&code=$topicIdentifier'),
headers: headers)
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
if (response.statusCode == 201) {
print('Succes subscribing to $topicIdentifier.');

return true;
}
print(
'subscribeToTopic $topicIdentifier, failed (code ${response.statusCode})');
return false;
} catch (e) {
print('subscribeToTopic $topicIdentifier, failed for $e');
return false;
}
}

Future<bool> unsubscribeFromTopic(
String userIdentifier, String topicIdentifier) async {
try {
final response = await http
.post(
Uri.parse(
'$serverUrl$unsub_from_topic?user=$userIdentifier&code=$topicIdentifier'),
headers: headers)
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
if (response.statusCode == 204) {
return true;
}
print('unsubscribeFromTopic, failed.');
return false;
} catch (e) {
print('unsubscribeFromTopic, failed for $e.');
return false;
}
}

Future<List<Topic>?> getTopicsSubscribed(String userIdentifier) async {
try {
final response = await http
.get(Uri.parse('$serverUrl$get_my_topics?user=$userIdentifier'),
headers: headers)
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as List;
var topicList = <Topic>[];
for (dynamic top in data) {
var topic = Topic.fromJson(top);
topicList.add(topic);
}
return topicList;
}
print('getTopicsSubscribed, failed.');
return null;
} catch (e) {
print('getTopicsSubscribed, failed for $e');
return null;
}
}

Future<bool> setFirebaseToken(String? userIdentifier, String fcmToken) async {
print(userIdentifier);
print(fcmToken);
Expand Down
58 changes: 43 additions & 15 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'dart:async';

import 'package:mosquito_alert_app/pages/main/main_vc.dart';
import 'package:mosquito_alert_app/utils/BackgroundTracking.dart';
import 'package:workmanager/workmanager.dart';

import 'package:connectivity/connectivity.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:mosquito_alert_app/api/api.dart';
import 'package:mosquito_alert_app/pages/main/drawer_and_header.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:mosquito_alert_app/utils/Application.dart';
import 'package:mosquito_alert_app/utils/MyLocalizationsDelegate.dart';
Expand Down Expand Up @@ -112,20 +112,48 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return OverlaySupport(
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.orange,
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'Nunito',
textTheme: TextTheme(
titleMedium: TextStyle(
color: Color(0xFF000000),
fontSize: 25.0,
fontWeight: FontWeight.w400,
),
bodyMedium: TextStyle(
color: Color(0xFF000000),
fontSize: 16.0,
fontWeight: FontWeight.w400,
),
bodySmall: TextStyle(
color: Colors.grey[600],
fontSize: 11.0,
fontWeight: FontWeight.w400,
),
labelMedium: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
labelSmall: TextStyle(
color: Color(0xFF979797),
fontSize: 10.0,
fontWeight: FontWeight.normal,
),
),
),
navigatorKey: navigatorKey,
home: MainVC(),
localizationsDelegates: [
_newLocaleDelegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: application.supportedLocales(),
),
navigatorKey: navigatorKey,
home: MainVC(),
localizationsDelegates: [
_newLocaleDelegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: application.supportedLocales(),
));
);
}
}
Loading