Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RGTechPro committed Aug 25, 2022
2 parents 6e545ed + f0405c8 commit 67217fe
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 38 deletions.
26 changes: 25 additions & 1 deletion lib/api/map_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:mera_aadhar/firebase/booking_db.dart';
import 'package:mera_aadhar/fixtures/nearby_center_fixture.dart';
import 'package:mera_aadhar/models/booking_model.dart';
import 'package:mera_aadhar/models/operator_model.dart';
import 'package:mera_aadhar/models/operator_data_model.dart';
import 'package:mera_aadhar/models/nearby_api_model.dart';
Expand Down Expand Up @@ -61,7 +63,23 @@ Future<String?> getAddressByLatLon(double lat, double lng) async{
return "${address.streetAddress}, ${address.region}, ${address.postal},";
}

Future<Tuple2<Map<String, Operator>, StreamGroup<OperatorData>>> getAllOperatorsByMyLatLong(String lat, String lon) async{
Future<bool> isOperatorBookingAvaliable(Operator operator, DateTime date, String time) async {
BookingDB bdb = BookingDB();
List<Booking> opBooking = await bdb.getOperatorIdBooking(operator.operatorId!);
for(int i=0; i<opBooking.length; i++){
Booking bookin = opBooking[i];
if(bookin.bookingStatus == "Completed") continue;
if(bookin.date!.difference(date).inDays == 0){
if(bookin.slotTime! == time){
print("${bookin.slotTime} == $time and ${bookin.date} == $date");
return false;
}
}
}
return true;
}

Future<Tuple2<Map<String, Operator>, StreamGroup<OperatorData>>> getAllOperatorsByMyLatLong(String lat, String lon, DateTime date, String time) async{
int rad = 5;
NearbyApiResponse nearby = await fetchMapdataFixture(lat, lon, rad);
while(nearby.len == null || nearby.len! == 0){
Expand All @@ -80,6 +98,12 @@ Future<Tuple2<Map<String, Operator>, StreamGroup<OperatorData>>> getAllOperators
List<Operator> operators = await odb.getOperatorsByLatLong(latlon);
for(final oper in operators){
print("found operator in vicinity with id! ${oper.operatorId!} with ${latlon}");

if(!(await isOperatorBookingAvaliable(oper, date, time))){
print("unavaliable operator, skipping!");
continue;
}

operatorIdMapOp[oper.operatorId!] = oper;
// Maybe cache to special provider map
Stream<OperatorData>? opdata = await odb.getOperatorLiveLocationById(oper.operatorId!);
Expand Down
18 changes: 18 additions & 0 deletions lib/firebase/booking_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ CollectionReference _collectionRef =
else return null;
}

Future<List<Booking>> getOperatorIdBooking(String oId) async {
FirebaseAuth auth = FirebaseAuth.instance;
QuerySnapshot snap = await _collectionRef
.where('operatorId', isEqualTo: oId)
.orderBy('timestamp', descending: true)
.get();

List<Booking> bookins = [];
for(int i=0; i<snap.size; i++){
Booking b = Booking.fromJson(snap.docs[i].data() as Map<String, dynamic>);
if(b.bookingStatus! == "Completed") continue;
bookins.add(b);
}

return bookins;
}


}
2 changes: 1 addition & 1 deletion lib/fixtures/booking_fixture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';

class BookingFixture {
static Booking dummyBooking(){
Map<String, dynamic> data = jsonDecode('{"bookingId":1,"operatorId":"abcdefgh","bookingType":0,"phoneNo":"+918872276957","bookingLocation":{"lat":23.25564,"lon":21.22134},"userdata":{"phoneNo":"nil","type":0,"locationText":"Hostel O, Tiet"},"confirmOtp":"1234","paydata":{"type":"CASH","receipt":null,"status":"Success"},"bookingStatus":"Inprogress","slotTime":"01:00 AM","slotDate":"01 Jan 1998","timestamp":1660465314}');
Map<String, dynamic> data = jsonDecode('{"bookingId":1,"operatorId":"abcdefgh","bookingType":0,"phoneNo":"+918872276957","bookingLocation":{"lat":23.25564,"lon":21.22134},"userdata":{"phoneNo":"nil","type":0,"locationText":"Hostel O, Tiet"},"confirmOtp":"+8++8","paydata":{"type":"CASH","receipt":null,"status":"Success"},"bookingStatus":"Inprogress","slotTime":"01:00 AM","slotDate":"01 Jan 1998","timestamp":1660465314}');
final Booking bookin = Booking.fromJson(data);
return bookin;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/models/booking_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Booking {
slotDate = json['slotDate'];
timestamp = json['timestamp'];

date = json['date'];
date = json['date'] != null ? json['date'].toDate() : null;
}

Map<String, dynamic> toJson() {
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/book_operator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class _BookOperatorScreenScreenState extends State<BookOperatorScreenScreen> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/date_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class _DatePageState extends State<DatePage> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/documentCheckPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class _DocumentCheckPageState extends State<DocumentCheckPage> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/editAddressPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class _EditAddressPageState extends State<EditAddressPage> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/modeSelectionPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class _ModeSelectPageState extends State<ModeSelectPage> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down
16 changes: 9 additions & 7 deletions lib/screens/onBoardingPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class _OnBoardingScreenState extends State<OnBoardingScreen> {
Center(
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 50,
radius: 40,
child: Image.asset(
'assets/logooo.png',
width: 100,
height: 100,
'assets/aadharlogo.png',
width: 55,
height: 55,
),
),
),
Expand All @@ -103,13 +103,15 @@ class _OnBoardingScreenState extends State<OnBoardingScreen> {
// textelement: translatedStrings["aadharUpdationOrEnrollmentAtYourHome"],
),
WelcomeScreen(

vectorLink: "assets/time.png",
textelement: "Select your own Time Slot",
textelement: "Select your own Time Slot & operator",
),
WelcomeScreen(
vectorLink: "assets/review.png",
textelement: "Review your appointments",
)
textelement: "Review your on-going appointments",

)
],
),
),
Expand Down
48 changes: 34 additions & 14 deletions lib/screens/operator_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
}
}

void registerDeregisterOperators() async {
void registerDeregisterOperators(DateTime date, String time) async {
String lat = pinLocation.latitude.toString();
String lon = pinLocation.longitude.toString();
Tuple2<Map<String, Operator>, StreamGroup<OperatorData>> rdata =
await getAllOperatorsByMyLatLong(lat, lon);
await getAllOperatorsByMyLatLong(lat, lon, date, time);
StreamGroup<OperatorData> streamgroup = rdata.item2;
idToOperator = rdata.item1;

Expand All @@ -132,7 +132,7 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
});
}

openMapmyIndiaPlacePickerWidget() async {
openMapmyIndiaPlacePickerWidget(BuildContext context) async {
ReverseGeocodePlace place;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
Expand All @@ -158,16 +158,30 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
pinLocation = LatLng(double.parse(place.lat!), double.parse(place.lng!));
}

setState(() {
// setState(() {
// _locationText = match.group(0)!;
_mapController.easeCamera(CameraUpdate.newLatLngZoom(pinLocation, 14));
addOrUpdateLocationMarker(pinLocation);
registerDeregisterOperators();
});

// });

// Change to time and slot
Navigator.push(
await Navigator.push(
context, MaterialPageRoute(builder: (context) => DatePage()));



DateTime? date = Provider.of<BookingProvider>(context, listen: false).booking.date;
String? time = Provider.of<BookingProvider>(context, listen: false).booking.slotTime;

while(date == null || time == null){
showSnackBar("Please select a valid date and time!!", context);
await Navigator.push(
context, MaterialPageRoute(builder: (context) => DatePage()));
date = Provider.of<BookingProvider>(context, listen: false).booking.date;
time = Provider.of<BookingProvider>(context, listen: false).booking.slotTime;
}
registerDeregisterOperators(date, time);
}

void utilHighlightOperator(Symbol symbol, bool highlight) async {
Expand Down Expand Up @@ -291,7 +305,7 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
icon: new Icon(Icons.edit),
highlightColor: Colors.pink,
onPressed: () {
openMapmyIndiaPlacePickerWidget();
openMapmyIndiaPlacePickerWidget(context);
},
),
),
Expand All @@ -315,8 +329,13 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
),
),
),
],
)


],

)


: Column(
children: [
const Icon(
Expand Down Expand Up @@ -368,9 +387,10 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),

),
),
const SizedBox(
Expand Down Expand Up @@ -403,14 +423,14 @@ class _OperatorSelectionScreenState extends State<OperatorSelectionScreen> {
"icon", "assets/operator_pin_icon.png");
addImageFromAsset(
"iconhigh", "assets/icon_op_yellow.png");
openMapmyIndiaPlacePickerWidget();
openMapmyIndiaPlacePickerWidget(context);
},
),
),
)),
GestureDetector(
onTap: () {
openMapmyIndiaPlacePickerWidget();
openMapmyIndiaPlacePickerWidget(context);
},
child: Padding(
padding: EdgeInsets.all(25),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/serviceSelectionPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ print(Provider.of<BookingProvider>(context, listen: false)
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Choose if you are a senior citizen or differently abled, otherwise go ahead.',
'Choose if you are a senior citizen (age>60) or differently abled, otherwise go ahead.',
style: GoogleFonts.poppins(
textStyle: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15,
fontSize: 13,
color: Colors.black,
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/slot_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class _SlotPageState extends State<SlotPage> {
radius: 40,
child: Image.asset(
'assets/aadharlogo.png',
width: 35,
height: 35,
width: 55,
height: 55,
),
),
),
Expand Down

0 comments on commit 67217fe

Please sign in to comment.