Skip to content
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

fix: updated the project #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/osj/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/osj/development/ocg/Taxi-App"
export "FLUTTER_TARGET=/Users/osj/development/ocg/Taxi-App/lib/main.dart"
export "FLUTTER_ROOT=D:\Softwares\flutter"
export "FLUTTER_APPLICATION_PATH=E:\local disk\Applications\2023\templates\Taxi-App"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/osj/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
182 changes: 104 additions & 78 deletions lib/bloc/taxi_booking_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:taxi_app/bloc/taxi_booking_event.dart';
import 'package:taxi_app/bloc/taxi_booking_state.dart';
import 'package:equatable/equatable.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:taxi_app/controllers/location_controller.dart';
import 'package:taxi_app/controllers/payment_method_controller.dart';
import 'package:taxi_app/controllers/taxi_booking_controller.dart';
Expand All @@ -9,92 +11,116 @@ import 'package:taxi_app/models/payment_method.dart';
import 'package:taxi_app/models/taxi.dart';
import 'package:taxi_app/models/taxi_booking.dart';
import 'package:taxi_app/models/taxi_driver.dart';
import 'package:taxi_app/models/taxi_type.dart';
import 'package:taxi_app/storage/taxi_booking_storage.dart';

part 'taxi_booking_event.dart';
part 'taxi_booking_state.dart';

class TaxiBookingBloc extends Bloc<TaxiBookingEvent, TaxiBookingState> {
@override
TaxiBookingState get initialState => TaxiBookingNotInitializedState();
TaxiBookingBloc() : super(TaxiBookingNotInitializedState()) {
on<TaxiBookingStartEvent>(_taxiBookingStarted);
on<DestinationSelectedEvent>(_destinationSelected);
on<DetailsSubmittedEvent>(_detailsSubmitted);
on<TaxiSelectedEvent>(_taxSelected);
on<PaymentMadeEvent>(_paymentMade);
on<TaxiBookingCancelEvent>(_taxiBookingCancelled);
on<BackPressedEvent>(_backPressed);
}

@override
Stream<TaxiBookingState> mapEventToState(TaxiBookingEvent event) async* {
if (event is TaxiBookingStartEvent) {
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
yield TaxiBookingNotSelectedState(taxisAvailable: taxis);
}
if (event is DestinationSelectedEvent) {
TaxiBookingStorage.open();
yield TaxiBookingLoadingState(
state: DetailsNotFilledState(booking: null));
Future<void> _taxiBookingStarted(
TaxiBookingStartEvent event, Emitter<TaxiBookingState> emit) async {
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
emit(TaxiBookingNotSelectedState(taxisAvailable: taxis));
}

GoogleLocation source = await LocationController.getCurrentLocation();
GoogleLocation destination =
await LocationController.getLocationfromId(event.destination);
await TaxiBookingStorage.addDetails(TaxiBooking.named(
source: source, destination: destination, noOfPersons: 1));
TaxiBooking taxiBooking = await TaxiBookingStorage.getTaxiBooking();
yield DetailsNotFilledState(booking: taxiBooking);
}
if (event is DetailsSubmittedEvent) {
yield TaxiBookingLoadingState(state: TaxiNotSelectedState(booking: null));
await Future.delayed(Duration(seconds: 1));
await TaxiBookingStorage.addDetails(TaxiBooking.named(
Future<void> _destinationSelected(
DestinationSelectedEvent event, Emitter<TaxiBookingState> emit) async {
TaxiBookingStorage.open();
emit(TaxiBookingLoadingState(state: DetailsNotFilledState(booking: null)));
GoogleLocation source = await LocationController.getCurrentLocation();
GoogleLocation destination =
await LocationController.getLocationfromId(event.destination);

await TaxiBookingStorage.addDetails(
TaxiBooking.named(
source: source,
destination: destination,
noOfPersons: 1,
),
);

TaxiBooking taxiBooking = await TaxiBookingStorage.getTaxiBooking();
emit(DetailsNotFilledState(booking: taxiBooking));
}

Future<void> _detailsSubmitted(
DetailsSubmittedEvent event, Emitter<TaxiBookingState> emit) async {
emit(TaxiBookingLoadingState(state: TaxiNotSelectedState(booking: null)));
await Future.delayed(Duration(seconds: 1));
await TaxiBookingStorage.addDetails(
TaxiBooking.named(
source: event.source,
destination: event.destination,
noOfPersons: event.noOfPersons,
bookingTime: event.bookingTime,
));
TaxiBooking booking = await TaxiBookingStorage.getTaxiBooking();
yield TaxiNotSelectedState(
booking: booking,
);
}
if (event is TaxiSelectedEvent) {
yield TaxiBookingLoadingState(
state:
PaymentNotInitializedState(booking: null, methodsAvaiable: []));
TaxiBooking prevBooking = await TaxiBookingStorage.getTaxiBooking();
double price = await TaxiBookingController.getPrice(prevBooking);
await TaxiBookingStorage.addDetails(
TaxiBooking.named(taxiType: event.taxiType, estimatedPrice: price));
TaxiBooking booking = await TaxiBookingStorage.getTaxiBooking();
List<PaymentMethod> methods = await PaymentMethodController.getMethods();
yield PaymentNotInitializedState(
booking: booking, methodsAvaiable: methods);
}
if (event is PaymentMadeEvent) {
yield TaxiBookingLoadingState(
state:
PaymentNotInitializedState(booking: null, methodsAvaiable: null));
TaxiBooking booking = await TaxiBookingStorage.addDetails(
TaxiBooking.named(paymentMethod: event.paymentMethod));
TaxiDriver taxiDriver =
await TaxiBookingController.getTaxiDriver(booking);
yield TaxiNotConfirmedState(booking: booking, driver: taxiDriver);
await Future.delayed(Duration(seconds: 1));
yield TaxiBookingConfirmedState(booking: booking, driver: taxiDriver);
}
if (event is TaxiBookingCancelEvent) {
yield TaxiBookingCancelledState();
await Future.delayed(Duration(milliseconds: 500));
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
yield TaxiBookingNotSelectedState(taxisAvailable: taxis);
}
if (event is BackPressedEvent) {
switch (state.runtimeType) {
case DetailsNotFilledState:
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
),
);
TaxiBooking booking = await TaxiBookingStorage.getTaxiBooking();
emit(TaxiNotSelectedState(booking: booking));
}

Future<void> _taxSelected(
TaxiSelectedEvent event, Emitter<TaxiBookingState> emit) async {
emit(TaxiBookingLoadingState(
state:
PaymentNotInitializedState(booking: null, methodsAvailable: [])));
TaxiBooking previousBooking = await TaxiBookingStorage.getTaxiBooking();
double price = await TaxiBookingController.getPrice(previousBooking);
await TaxiBookingStorage.addDetails(
TaxiBooking.named(taxiType: event.taxiType, estimatedPrice: price));
TaxiBooking booking = await TaxiBookingStorage.getTaxiBooking();
List<PaymentMethod> methods = await PaymentMethodController.getMethods();
emit(PaymentNotInitializedState(
booking: booking, methodsAvailable: methods));
}

Future<void> _paymentMade(
PaymentMadeEvent event, Emitter<TaxiBookingState> emit) async {
emit(TaxiBookingLoadingState(
state:
PaymentNotInitializedState(booking: null, methodsAvailable: null)));
TaxiBooking booking = await TaxiBookingStorage.addDetails(
TaxiBooking.named(paymentMethod: event.paymentMethod));
TaxiDriver taxiDriver = await TaxiBookingController.getTaxiDriver(booking);
emit(TaxiNotConfirmedState(booking: booking, driver: taxiDriver));
await Future.delayed(Duration(seconds: 1));
emit(TaxiBookingConfirmedState(booking: booking, driver: taxiDriver));
}

Future<void> _taxiBookingCancelled(
TaxiBookingCancelEvent event, Emitter<TaxiBookingState> emit) async {
emit(TaxiBookingCancelledState());
await Future.delayed(Duration(milliseconds: 500));
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
emit(TaxiBookingNotSelectedState(taxisAvailable: taxis));
}

yield TaxiBookingNotSelectedState(taxisAvailable: taxis);
break;
case PaymentNotInitializedState:
yield TaxiNotSelectedState(
booking: (state as PaymentNotInitializedState).booking);
break;
case TaxiNotSelectedState:
yield DetailsNotFilledState(
booking: (state as TaxiNotSelectedState).booking);
break;
}
Future<void> _backPressed(
BackPressedEvent event, Emitter<TaxiBookingState> emit) async {
switch (state.runtimeType) {
case DetailsNotFilledState:
List<Taxi> taxis = await TaxiBookingController.getTaxisAvailable();
emit(TaxiBookingNotSelectedState(taxisAvailable: taxis));
break;
case PaymentNotInitializedState:
emit(TaxiNotSelectedState(
booking: (state as PaymentNotInitializedState).booking));
break;
case TaxiNotSelectedState:
emit(DetailsNotFilledState(
booking: (state as TaxiNotSelectedState).booking));
break;
}
}
}
24 changes: 10 additions & 14 deletions lib/bloc/taxi_booking_event.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:taxi_app/models/google_location.dart';
import 'package:taxi_app/models/payment_method.dart';
import 'package:taxi_app/models/taxi_type.dart';
part of 'taxi_booking_bloc.dart';

abstract class TaxiBookingEvent extends Equatable {
TaxiBookingEvent();
Expand All @@ -17,7 +12,7 @@ class TaxiBookingStartEvent extends TaxiBookingEvent {
class DestinationSelectedEvent extends TaxiBookingEvent {
final LatLng destination;

DestinationSelectedEvent({@required this.destination});
DestinationSelectedEvent({this.destination});

@override
List<Object> get props => [destination];
Expand All @@ -29,11 +24,12 @@ class DetailsSubmittedEvent extends TaxiBookingEvent {
final int noOfPersons;
final DateTime bookingTime;

DetailsSubmittedEvent(
{@required this.source,
@required this.destination,
@required this.noOfPersons,
@required this.bookingTime});
DetailsSubmittedEvent({
this.source,
this.destination,
this.noOfPersons,
this.bookingTime,
});

@override
List<Object> get props => [source, destination, noOfPersons, bookingTime];
Expand All @@ -42,7 +38,7 @@ class DetailsSubmittedEvent extends TaxiBookingEvent {
class TaxiSelectedEvent extends TaxiBookingEvent {
final TaxiType taxiType;

TaxiSelectedEvent({@required this.taxiType});
TaxiSelectedEvent({this.taxiType});

@override
List<Object> get props => [taxiType];
Expand All @@ -51,7 +47,7 @@ class TaxiSelectedEvent extends TaxiBookingEvent {
class PaymentMadeEvent extends TaxiBookingEvent {
final PaymentMethod paymentMethod;

PaymentMadeEvent({@required this.paymentMethod});
PaymentMadeEvent({this.paymentMethod});

@override
List<Object> get props => [paymentMethod];
Expand Down
27 changes: 11 additions & 16 deletions lib/bloc/taxi_booking_state.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:taxi_app/models/payment_method.dart';
import 'package:taxi_app/models/taxi.dart';
import 'package:taxi_app/models/taxi_booking.dart';
import 'package:taxi_app/models/taxi_driver.dart';
part of 'taxi_booking_bloc.dart';

abstract class TaxiBookingState extends Equatable {
TaxiBookingState();
Expand All @@ -18,7 +13,7 @@ class TaxiBookingNotInitializedState extends TaxiBookingState {
class TaxiBookingNotSelectedState extends TaxiBookingState {
final List<Taxi> taxisAvailable;

TaxiBookingNotSelectedState({@required this.taxisAvailable});
TaxiBookingNotSelectedState({this.taxisAvailable});

@override
List<Object> get props => null;
Expand All @@ -27,27 +22,27 @@ class TaxiBookingNotSelectedState extends TaxiBookingState {
class DetailsNotFilledState extends TaxiBookingState {
final TaxiBooking booking;

DetailsNotFilledState({@required this.booking});
DetailsNotFilledState({this.booking});
@override
List<Object> get props => [booking];
}

class TaxiNotSelectedState extends TaxiBookingState {
final TaxiBooking booking;

TaxiNotSelectedState({@required this.booking});
TaxiNotSelectedState({this.booking});

@override
List<Object> get props => [booking];
}

class PaymentNotInitializedState extends TaxiBookingState {
final TaxiBooking booking;
final List<PaymentMethod> methodsAvaiable;
final List<PaymentMethod> methodsAvailable;

PaymentNotInitializedState({
@required this.booking,
@required this.methodsAvaiable,
this.booking,
this.methodsAvailable,
});

@override
Expand All @@ -58,7 +53,7 @@ class TaxiNotConfirmedState extends TaxiBookingState {
final TaxiDriver driver;
final TaxiBooking booking;

TaxiNotConfirmedState({@required this.driver, @required this.booking});
TaxiNotConfirmedState({this.driver, this.booking});

@override
List<Object> get props => [driver, booking];
Expand All @@ -68,7 +63,7 @@ class TaxiConfirmedState extends TaxiBookingState {
final TaxiDriver driver;
final TaxiBooking booking;

TaxiConfirmedState({@required this.driver, @required this.booking});
TaxiConfirmedState({this.driver, this.booking});

@override
List<Object> get props => [driver, booking];
Expand All @@ -82,7 +77,7 @@ class TaxiBookingCancelledState extends TaxiBookingState {
class TaxiBookingLoadingState extends TaxiBookingState {
final TaxiBookingState state;

TaxiBookingLoadingState({@required this.state});
TaxiBookingLoadingState({this.state});
@override
List<Object> get props => [state];
}
Expand All @@ -91,7 +86,7 @@ class TaxiBookingConfirmedState extends TaxiBookingState {
final TaxiDriver driver;
final TaxiBooking booking;

TaxiBookingConfirmedState({@required this.driver, @required this.booking});
TaxiBookingConfirmedState({this.driver, this.booking});
@override
List<Object> get props => [driver];
}
8 changes: 4 additions & 4 deletions lib/controllers/user_location_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:location/location.dart';
class UserLocationController {
static Future<LatLng> getCurrentLocation() async {
Location location = Location();
bool check = await location.hasPermission();
if (!check) {
bool result = await location.requestPermission();
if (result) {
PermissionStatus check = await location.hasPermission();
if (check == PermissionStatus.denied) {
check = await location.requestPermission();
if (check == PermissionStatus.granted) {
LocationData position = await location.getLocation();
return LatLng(position.latitude, position.longitude);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class MyApp extends StatelessWidget {
primaryColor: Colors.black,
fontFamily: 'Ubuntu',
textTheme: TextTheme(
title: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600),
subtitle: TextStyle(color: Colors.black54),
subhead:
titleMedium:
TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600),
titleSmall: TextStyle(color: Colors.black54),
headlineSmall:
TextStyle(color: Colors.black54, fontWeight: FontWeight.w800),
headline:
headlineMedium:
TextStyle(fontSize: 18.0, fontWeight: FontWeight.w800))),
home: HomeScreen(),
);
Expand Down
Loading