Skip to content

Commit

Permalink
fix: update flagCount and viewCount
Browse files Browse the repository at this point in the history
  • Loading branch information
vskvj3 committed Jun 26, 2023
1 parent a427608 commit c51d640
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pages/alert_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class _AlertDetailsState extends State<AlertDetails> {
ElevatedButton(
onPressed: () async {
final response = await AlertFunctions.updateCount(
widget.alertDetails.id, widget.alertDetails.phone);
widget.alertDetails.id);
if (response.statusCode == 200) {
final responseData = json.decode(response.body);
profileData.flagCount = responseData['flag_count'];
Expand Down
10 changes: 8 additions & 2 deletions lib/utils/alert_functions.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class AlertFunctions {
static Future<http.Response> updateCount(String id, phone) async {
static Future<http.Response> updateCount(String id) async {
const storage = FlutterSecureStorage();
final phone = await storage.read(key: "phone");

Uri url = Uri.parse(
'https://alertme.onrender.com/api/v1/alert/flag/?_id=$id&phone=$phone');
String encodedUri = Uri.encodeComponent(
Expand All @@ -12,7 +16,9 @@ class AlertFunctions {
return http.put(url);
}

static Future<http.Response> updateView(String id, phone) async {
static Future<http.Response> updateView(String id) async {
const storage = FlutterSecureStorage();
final phone = await storage.read(key: "phone");
return http.put(
Uri.parse(
'https://alertme.onrender.com/api/v1/alert/view/?_id=$id&phone=$phone'),
Expand Down
3 changes: 1 addition & 2 deletions lib/utils/alert_receiver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class AlertReceiver {
responseData['view_count'],
responseData['flag_count']);

final viewUpdateResponse =
await AlertFunctions.updateView(id, responseData['phone']);
final viewUpdateResponse = await AlertFunctions.updateView(id);
if (viewUpdateResponse.statusCode == 200) {
debugPrint("view updated");
}
Expand Down

0 comments on commit c51d640

Please sign in to comment.