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

Feature/map screen #13

Open
wants to merge 6 commits into
base: main
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
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<application
android:label="${appName}"
android:icon="@mipmap/ic_launcher">

<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBbvurpUV2c7LU9E43ZfqauESb6BqV-43Q"/>

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Binary file added assets/images/png/Rectangle 39.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/png/Vector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/png/location.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '12.0'
platform :ios, '13.0'

pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '9.5.0'

Expand Down
4 changes: 4 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
Expand All @@ -8,6 +9,9 @@ import Flutter
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)

GMSServices.provideAPIKey("AIzaSyBbvurpUV2c7LU9E43ZfqauESb6BqV-43Q")

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
10 changes: 10 additions & 0 deletions lib/core/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'dart:io';

import 'package:devfest/views/controller_page/tabs/home/sub_pages/sponsors_page.dart';
import 'package:devfest/views/controller_page/tabs/home/sub_pages/teams_page.dart';
import 'package:devfest/views/maps_page/maps_page.dart';
import 'package:devfest/views/maps_page/maps_search_page.dart';

import 'package:devfest/views/onboarding/onboarding_page.dart';
import 'package:devfest/views/signin_page/signin_page.dart';
import 'package:devfest/views/splash_page.dart';
Expand Down Expand Up @@ -69,6 +72,7 @@ abstract class AppRouter {
view: const TalkCategoriesSubPage(),
);


case Routes.sponsorsPage:
return getPageRoute(
settings: settings,
Expand All @@ -80,6 +84,12 @@ abstract class AppRouter {
settings: settings,
view: const TeamsPage(),
);
case Routes.mapsPage:
return getPageRoute(settings: settings, view: const MapsPage());

case Routes.mapsSearch:
return getPageRoute(settings: settings, view: const MapSearchPage());


default:
return getPageRoute(
Expand Down
4 changes: 4 additions & 0 deletions lib/core/router/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ abstract class Routes {
static const speakerPage = '/speaker_page';
static const moreInfoPage = '/more_info_page';
static const allTalkPage = '/all_talk_page';

static const sponsorsPage = '/sponsors_page';
static const teamPage = '/team_page';
static const mapsPage = '/maps_page';
static const mapsSearch = '/maps_search_page';

}
8 changes: 7 additions & 1 deletion lib/core/state/providers.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

import 'package:devfest/core/model/category_response.dart';
import 'package:devfest/core/model/speakers_response.dart';
import 'package:devfest/core/model/sponsors_response.dart';
import 'package:devfest/core/model/team_response.dart';
import 'package:devfest/core/model/venue_response.dart';

import 'package:devfest/core/state/viewmodels/viewmodels.dart';
import 'package:devfest/services/auth.dart';
import 'package:devfest/services/firestore_db.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'package:devfest/core/state/viewmodels/maps_vm.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../model/session_response.dart';

final homeVM = ChangeNotifierProvider((_) => HomeVM(_.read));
final signinVM = ChangeNotifierProvider((_) => SigninVM(_.read));
final controllerVM = ChangeNotifierProvider((_) => ControllerVM(_.read));
final themeVM = ChangeNotifierProvider((_) => ThemeVM());
final speakersVM = ChangeNotifierProvider((_) => SpeakersVM());
final mapsVm = ChangeNotifierProvider((_) => MapsVM());

final authProvider = Provider((_) => AuthImpl());
final categoriesStreamProvider = StreamProvider.autoDispose<List<Category>?>(
(ref) => FirestoreUserDBService.instance.categoriesStream());
Expand All @@ -30,3 +35,4 @@ final sponsorsStreamProvider = StreamProvider.autoDispose<List<Sponsor>?>(
final sessionsStreamProvider =
StreamProvider.autoDispose<List<Future<Session>>?>(
(ref) => FirestoreUserDBService.instance.sessionsStream());

8 changes: 7 additions & 1 deletion lib/core/state/viewmodels/controller_vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:devfest/core/router/navigator.dart';
import 'package:devfest/views/controller_page/controller_page_item.dart';
import 'package:devfest/views/controller_page/tabs/home/home_page.dart';
import 'package:devfest/views/controller_page/tabs/profile/profile_page.dart';
import 'package:devfest/views/maps_page/maps_page.dart';
import 'package:devfest/views/speakers_page/speakers_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down Expand Up @@ -48,7 +49,7 @@ class ControllerVM extends ChangeNotifier {
name: 'Agenda',
),
const ControllerPageItem(
page: HomePage(
page: MapsPage(
key: PageStorageKey<String>('map'),
),
image: 'map',
Expand Down Expand Up @@ -89,6 +90,11 @@ class ControllerVM extends ChangeNotifier {
notifyListeners();
}

void goToMap() {
currentTab = 2;
notifyListeners();
}

void goToSpeakers() {
currentTab = 3;
notifyListeners();
Expand Down
221 changes: 221 additions & 0 deletions lib/core/state/viewmodels/maps_vm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import 'dart:async';

import 'package:devfest/core/router/navigator.dart';
import 'package:flutter/material.dart';
import 'package:devfest/views/maps_page/maps_search_page.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:devfest/utils/constants.dart';
import 'package:google_place/google_place.dart' as places;
import 'package:location/location.dart';

class MapsVM extends ChangeNotifier {
TextEditingController _your_location_ctrl = TextEditingController();
TextEditingController get yourlocation_ctrl => this._your_location_ctrl;
set yourlocation_ctrl(TextEditingController value) {
this._your_location_ctrl = value;
notifyListeners();
}

TextEditingController _landmark_ctrl = TextEditingController();
TextEditingController get landmarkctrl => this._landmark_ctrl;
set landmarkctrl(TextEditingController value) {
this._landmark_ctrl = value;
notifyListeners();
}

final Completer<GoogleMapController> _controller = Completer();

late GoogleMapController _mapController;
get mapController => this._mapController;

set mapController(value) {
this._mapController = value;
notifyListeners();
}

late places.GooglePlace googlePlace;
get getGooglePlace => this.googlePlace;

void setGooglePlace(googlePlace) {
this.googlePlace = googlePlace;
//notifyListeners();
}

List<LatLng> _polylineCoordinates = [];
List<LatLng> get getPolylineCoordinates => this._polylineCoordinates;
set setPolylineCoordinates(List<LatLng> polylineCoordinates) {
this._polylineCoordinates = polylineCoordinates;
notifyListeners();
}

var _currentLocation;
get currentLocation => this._currentLocation;
set currentLocation(var value) {
this._currentLocation = value;
notifyListeners();
}

//LatLng source = const LatLng(6.5355, 3.3087);

LatLng destination =
const LatLng(6.4230432, 3.4450862); //Landmark event center.

LocationData? _curentLocation;
get getCurentLocation => this._curentLocation;

set setCurentLocation(curentLocation) {
this._curentLocation = curentLocation;
notifyListeners();
}

List<places.AutocompletePrediction> predictions = [];

Timer? _debounce;

places.DetailsResult? startPosition;

bool _directionsClicked = false;
get getDirectionsClicked => _directionsClicked;
set setDirectionsClicked(clicked) {
_directionsClicked = clicked;
notifyListeners();
}

void toggleDirections() {
setDirectionsClicked = !getDirectionsClicked;
notifyListeners();
}

late FocusNode _startFocusNode;
get getStartFocusNode => _startFocusNode;
void setStartFocusNode(focusNode) {
_startFocusNode = focusNode;
}

void getCurrentLocation() async {
Location location = Location();

location.getLocation().then((location) => setCurentLocation = location);

GoogleMapController googleMapController = await _controller.future;

location.onLocationChanged.listen((newLocation) {
setCurentLocation = newLocation;
// googleMapController.animateCamera(
// CameraUpdate.newCameraPosition(
// CameraPosition(
// zoom: 13.5,
// target: LatLng(newLocation.latitude!, newLocation.longitude!),
// ),
// ),
// );
notifyListeners();
});
}

void getStartLocation() async {
GoogleMapController googleMapController = await _controller.future;

googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
zoom: 13.5,
target: LatLng(startPosition!.geometry!.location!.lat!,
startPosition!.geometry!.location!.lng!),
),
),
);
notifyListeners();
}

void getPolyPoint() async {
PolylinePoints polylinePoints = PolylinePoints();

PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
AppConstants.google_api_key,
PointLatLng(startPosition!.geometry!.location!.lat!,
startPosition!.geometry!.location!.lng!),
//PointLatLng(source.latitude, source.longitude),
PointLatLng(destination.latitude, destination.longitude),
);

if (result.points.isNotEmpty) {
result.points.forEach(
(PointLatLng point) => _polylineCoordinates.add(
LatLng(point.latitude, point.longitude),
),
);
notifyListeners();
}
}

// setGooglePlace(places.GooglePlace(AppConstants.google_api_key));

void initializePlaces() {
//calling setGoogle place alone threw an error, so I used mapController to call it.
setGooglePlace(places.GooglePlace(AppConstants.google_api_key));
}

void initializeFocusNode(focusnode) {
setStartFocusNode(focusnode);
}

void onMapCreated(GoogleMapController mapcontroller) {
_controller.complete(mapcontroller);
}

void autoCompleteSearch(String value) async {
var result = await googlePlace.autocomplete.get(value);
if (result != null && result.predictions != null) {
print(result.predictions!.first.description);

predictions = result.predictions!;
notifyListeners();
}
}

void onChanged(value) {
if (_debounce?.isActive ?? false) _debounce!.cancel();
_debounce = Timer(const Duration(milliseconds: 1000), () {
if (value.isNotEmpty) {
//places api
autoCompleteSearch(value);
} else {
//clear out the resut
predictions = [];
startPosition = null;
notifyListeners();
}
});
}

Future onTap(index) async {
final placeId = predictions[index].placeId!;
final details = await googlePlace.details.get(placeId);

if (details != null && details.result != null) {
if (getStartFocusNode.hasFocus) {
startPosition = details.result;
yourlocation_ctrl.text = details.result!.name!;
//clear predictions after user selection
predictions = [];
notifyListeners();
}
//GO BACK
if (startPosition != null) {
getPolyPoint();
AppNavigator.pop();
}
}
}

void clearSearchField() {
predictions = [];
yourlocation_ctrl.clear();
notifyListeners();
}
}


//void setGooglePlace(places.GooglePlace googlePlace) {}
1 change: 1 addition & 0 deletions lib/utils/constants.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
abstract class AppConstants {
static const horizontalPadding = 24.0;
static const google_api_key = "AIzaSyBbvurpUV2c7LU9E43ZfqauESb6BqV-43Q";
}
Loading