Skip to content

Commit

Permalink
added google maps component
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach committed Jul 19, 2021
1 parent d081b2c commit 01d5ea2
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.pub-cache/
.pub/
/build/
config.dart

# Web related
lib/generated_plugin_registrant.dart
Expand Down
6 changes: 5 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def googleMapsApiKey = localProperties.getProperty('segment.googleMapsApiKey');

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
Expand All @@ -35,10 +37,12 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.clonetra"
minSdkVersion 16
minSdkVersion 20
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

manifestPlaceholders = [googleMapsApiKey: googleMapsApiKey]
}

buildTypes {
Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clonetra">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:label="clonetra"
android:icon="@mipmap/ic_launcher">
Expand Down Expand Up @@ -37,5 +41,9 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${googleMapsApiKey}"/>
</application>
</manifest>
1 change: 1 addition & 0 deletions lib/views/home/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clonetra/constants/icons.dart';
import 'package:clonetra/constants/images.dart';
import 'package:flutter/material.dart';
import 'package:location/location.dart';

import 'widgets/locations.dart';
import 'widgets/nearby.dart';
Expand Down
7 changes: 7 additions & 0 deletions lib/views/trip/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clonetra/constants/icons.dart';
import 'package:clonetra/theme/colors.dart';
import 'package:flutter/material.dart';
import 'widgets/map.dart';

class TripView extends StatefulWidget {

Expand Down Expand Up @@ -84,6 +85,12 @@ class _TripViewState extends State<TripView> {
)
),
],
),
Padding(
padding: EdgeInsets.only(
top: 8
),
child: ClonetraMap(),
)
],
)
Expand Down
151 changes: 151 additions & 0 deletions lib/views/trip/widgets/map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import 'package:clonetra/theme/colors.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';

class ClonetraMap extends StatefulWidget {

_ClonetraMapState createState()=> _ClonetraMapState();
}

class _ClonetraMapState extends State<ClonetraMap> {

CameraPosition? _initialPosition;

Location? _location;

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

@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: 300,
child: _initialPosition != null ? Stack(
children: [
Positioned.fill(
child: GoogleMap(
initialCameraPosition: _initialPosition!,
mapType: MapType.normal,
zoomControlsEnabled: false,
myLocationButtonEnabled: false,
myLocationEnabled: true,
),
),
Positioned(
top: 12,
left: 12,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("Handle Favorite Button"),
child: Material(
elevation: 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)
),
color: ClonetraColors.white,
child: Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Icon(
Icons.favorite_outline,
color: ClonetraColors.darkGray,
),
),
),
),
),
Positioned(
top: 12,
right: 12,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("Handle Current Location"),
child: Material(
elevation: 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)
),
color: ClonetraColors.white,
child: Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Icon(
Icons.location_searching,
color: ClonetraColors.darkGray,
),
),
),
),
),
Positioned(
bottom: 12,
right: 12,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("Handle Route Button"),
child: Material(
elevation: 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)
),
color: ClonetraColors.buttonBlue,
child: Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Icon(
Icons.arrow_back_rounded,
color: ClonetraColors.white,
),
),
),
),
),
],
) : Container(),
);
}

void _setIntialLocation() async {
try{
_location = new Location();
bool _locationEnabled = await _location?.serviceEnabled() ?? false;
if(!_locationEnabled){
throw "Location Disabled";
}

PermissionStatus _permission = await _location!.hasPermission();
if(_permission == PermissionStatus.denied){
_permission = await _location!.requestPermission();
if(_permission != PermissionStatus.granted){
throw "Location Permission Denied";
}
}

LocationData _locationData = await _location!.getLocation();
_initialPosition = new CameraPosition(
target: LatLng(
_locationData.latitude!,
_locationData.longitude!
),
zoom: 17.25,
);
setState(() {});
}
catch(e){
print("Error setting location");
_initialPosition = new CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 20,
);
setState(() {});
}
}
}
76 changes: 76 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,72 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
google_maps_flutter:
dependency: "direct main"
description:
name: google_maps_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
google_maps_flutter_platform_interface:
dependency: transitive
description:
name: google_maps_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
location:
dependency: "direct main"
description:
name: location
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.0"
location_platform_interface:
dependency: transitive
description:
name: location_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
location_web:
dependency: transitive
description:
name: location_web
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
matcher:
dependency: transitive
description:
Expand All @@ -88,6 +149,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -114,6 +182,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -151,3 +226,4 @@ packages:
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ dependencies:

cupertino_icons: ^1.0.2

google_maps_flutter: ^2.0.6

location: ^4.3.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 01d5ea2

Please sign in to comment.