Commit 6118d66e authored by Karunarathna K.M.D.Y.K's avatar Karunarathna K.M.D.Y.K

Merge branch 'IT19983202' into 'master'

Added providers

See merge request !10
parents 7723f0ed aeb6f7c8
import 'package:flutter/material.dart';
import 'package:govimithura/models/entity_model.dart';
import 'package:govimithura/models/error_model.dart';
import 'package:govimithura/services/crop_service.dart';
import 'package:govimithura/utils/utils.dart';
class CropProvider extends ChangeNotifier {
EntityModel cropEntity = EntityModel();
Future<void> getCropByName(BuildContext context) async {
return await CropService.getCropByName(cropEntity.description)
.then((value) {
if (value != null) {
cropEntity = EntityModel.fromMap(value.docs.first.data());
notifyListeners();
} else {
Utils.showSnackBar(context, ErrorModel.errorMessage);
return null;
}
});
}
setCrop(String cropName) async {
cropEntity.description = cropName;
notifyListeners();
}
}
import 'package:flutter/material.dart';
class HomeProvider extends ChangeNotifier {
int selectedScreenIndex = 0;
onNavigationChange(int index) {
selectedScreenIndex = index;
notifyListeners();
}
}
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:govimithura/models/error_model.dart';
import 'package:govimithura/models/location_model.dart';
import 'package:govimithura/services/location_service.dart';
import 'package:govimithura/services/weather_service.dart';
import 'package:govimithura/utils/utils.dart';
class LocationProvider extends ChangeNotifier {
Position? currentPosition;
double? currentLocationTemp;
String? currentAddress;
LocationModel locationModel = LocationModel();
Future<void> getCurrentPosition(BuildContext context) async {
await LocationService.getCurrentPosition().then((Position? position) {
if (position == null) {
Utils.showSnackBar(context, ErrorModel.errorMessage);
} else {
currentPosition = position;
GeoPoint geoPoint =
GeoPoint(currentPosition!.latitude, currentPosition!.longitude);
_getAddressFromLatLng(geoPoint, context);
notifyListeners();
}
});
}
Future<void> getCurrentLocationTemp(BuildContext context) async {
await getCurrentPosition(context);
if (currentPosition != null) {
GeoPoint geoPoint =
GeoPoint(currentPosition!.latitude, currentPosition!.longitude);
return await WeatherService.getCurrentTemprature(geoPoint)
.then((currentTemp) {
currentLocationTemp = currentTemp;
notifyListeners();
});
}
}
Future<void> _getAddressFromLatLng(
GeoPoint geoPoint, BuildContext context) async {
await LocationService.getListOfPlaceMarks(geoPoint)
.then((List<Placemark>? placemarks) {
if (placemarks != null) {
if (placemarks.isEmpty) {
Utils.showSnackBar(context, "No Location found");
return;
}
Placemark place = placemarks[1];
locationModel = LocationModel.fromJson(place.toJson());
if (place.street != null && place.street!.isNotEmpty) {
currentAddress = place.street;
}
if (place.subLocality != null && place.subLocality!.isNotEmpty) {
currentAddress = '$currentAddress, ${place.subLocality}';
}
if (place.subAdministrativeArea != null &&
place.subAdministrativeArea!.isNotEmpty) {
currentAddress = '$currentAddress, ${place.subAdministrativeArea}';
}
if (place.postalCode != null && place.postalCode!.isNotEmpty) {
currentAddress = '$currentAddress, ${place.postalCode}';
}
notifyListeners();
} else {
Utils.showSnackBar(context, ErrorModel.errorMessage);
}
});
}
setDistrict(String district) {
locationModel.district = district;
notifyListeners();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment