# Untitled

unknown
dart
21 days ago
4.2 kB
2
Indexable
Never
```import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

@override
}

final int batchSize = 1;

@override
void initState() {
super.initState();
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

int compareAlertLevels(String level1, String level2) {
final priorityOrder = {
'Emergency': 0,
'High': 1,
'Medium': 2,
'Low': 3,
'Resolved': 4
};

int priority1 = priorityOrder[level1] ?? 999;  // Default to lowest priority
int priority2 = priorityOrder[level2] ?? 999;  // Default to lowest priority
return priority1.compareTo(priority2);
}

double haversine(double lat1, double lon1, double lat2, double lon2) {
// Haversine formula to calculate distance
double dlon = _degreesToRadians(lon2 - lon1);
double dlat = _degreesToRadians(lat2 - lat1);
double a = pow(sin(dlat / 2), 2) + cos(_degreesToRadians(lat1)) * cos(_degreesToRadians(lat2)) * pow(sin(dlon / 2), 2);
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
double r = 6371.0;  // Radius of the Earth in kilometers
double distance = c * r * 1000;  // Convert to meters
return distance;
}

return degrees * pi / 180;
}

// Sort by severity

// Further sort each severity level by distance
}

groupedBySeverity.forEach((severity, group) {
group.sort((a, b) {
double distance1 = haversine(a.latitude, a.longitude, userLatitude, userLongitude);
double distance2 = haversine(b.latitude, b.longitude, userLatitude, userLongitude);
return distance1.compareTo(distance2);
});
});

}

@override
Widget build(BuildContext context) {
final double userLatitude = user.latitude ?? 23.09;
final double userLongitude = user.longitude ?? 41.121;

return Scaffold(
appBar: AppBar(
),
builder: (context, state) {

return ListView.builder(
itemBuilder: (context, index) {
bool isClose = distance < 1000;
},
);