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

feat:display events on gmaps #44

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
android:label="campusbuddy"
android:icon="@mipmap/ic_launcher">

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBvOUZLZcHsE6vp-DUewP74GN0H87xbeXQ" />

<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
Expand Down
8 changes: 6 additions & 2 deletions lib/Posts/PostList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class _PostListState extends State<PostList>
null,
snapshot.data.docs[index]['description'],
snapshot.data.docs[index]['image'],
snapshot.data.docs[index]['created_by']);
snapshot.data.docs[index]['created_by'],
snapshot.data.docs[index]['latitude'],
snapshot.data.docs[index]['longitude']);
return dropdownValue == "None"
? getCard(postDeets, postedAt, postSelect, index)
: (dropdownValue == postDeets.group)
Expand Down Expand Up @@ -254,7 +256,9 @@ class _PostListState extends State<PostList>
snapshot.data.docs[index]['venue'],
snapshot.data.docs[index]['description'],
snapshot.data.docs[index]['image'],
snapshot.data.docs[index]['created_by']);
snapshot.data.docs[index]['created_by'],
snapshot.data.docs[index]['longitude'],
snapshot.data.docs[index]['latitude']);

if (totEvent > bets && bets != 0) {
eventSelect = true;
Expand Down
68 changes: 42 additions & 26 deletions lib/post_screen/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import 'package:campusbuddy/notification.dart';
import 'package:campusbuddy/calendar.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'dart:async';
import 'gmaps.dart';

//Class that fetches and stores all details of added Events and Posts from Firestore.
class Deets {
String title, venue, desc, imgURL, group;
double longitude, latitude; //in console use double values, i.e: use 2.0 not 2
DateTime time;
Deets(this.title, this.time, this.venue, this.desc, this.imgURL, this.group);
Deets(this.title, this.time, this.venue, this.desc, this.imgURL, this.group,
this.longitude, this.latitude);
}

class Events extends StatefulWidget {
Expand Down Expand Up @@ -41,34 +44,34 @@ class _EventsState extends State<Events> {
expandedHeight: 210.0,
backgroundColor: indigo,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Padding(
padding: const EdgeInsets.fromLTRB(20, 2, 20, 2),
child: Text(
'${deets.group}',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
fontFamily: 'Roboto',
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
centerTitle: true,
title: Padding(
padding: const EdgeInsets.fromLTRB(20, 2, 20, 2),
child: Text(
'${deets.group}',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
fontFamily: 'Roboto',
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
),
background: Center(
child: Container(
width: 120,
height: 120,
decoration: (deets.imgURL == null || deets.imgURL == '')
? new BoxDecoration()
: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(deets.imgURL),
)),
),
),
background: Center(
child: Container(
width: 120,
height: 120,
decoration: (deets.imgURL == null || deets.imgURL == '')
? new BoxDecoration()
: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(deets.imgURL),
)),
),
),
),
),
SliverToBoxAdapter(
Expand Down Expand Up @@ -127,6 +130,19 @@ class _EventsState extends State<Events> {
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
// print(deets.latitude);
// print(deets.longitude);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Gmaps(
latitude: deets.latitude, longitude: deets.longitude)));
},
label: const Text('Map'),
icon: const Icon(Icons.map),
),
bottomNavigationBar: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
76 changes: 76 additions & 0 deletions lib/post_screen/gmaps.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'events.dart';

Set<Marker> _createMarker(double latitude, double longitude) {
return <Marker>[
Marker(
markerId: MarkerId("destination"),
position: LatLng(latitude, longitude),
icon: BitmapDescriptor.defaultMarker,
)
].toSet();
}

class Gmaps extends StatefulWidget {
double longitude;
double latitude;

Gmaps({Key key, this.latitude, this.longitude}) : super(key: key);

@override
_GmapsState createState() => _GmapsState();
}

class _GmapsState extends State<Gmaps> {
GoogleMapController myController;
final LatLng _center = const LatLng(29.864553512846367, 77.89656284648702);

void _onMapCreated(GoogleMapController controller) {
myController = controller;
}

MapType _currentMapType = MapType.normal;

void _onMapTypeButtonPressed() {
setState(() {
_currentMapType = _currentMapType == MapType.normal
? MapType.satellite
: MapType.normal;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Map'),
),
body: Stack(
children: <Widget>[
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 16.0,
),
mapType: _currentMapType,
markers: _createMarker(widget.latitude, widget.longitude),
),
Padding(
padding: const EdgeInsets.all(14.0),
child: Align(
alignment: Alignment.topRight,
child: FloatingActionButton(
onPressed: _onMapTypeButtonPressed,
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.green,
child: Icon(Icons.map, size: 30.0),
),
),
),
],
),
);
}
}
28 changes: 28 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_screenutil:
dependency: "direct main"
description:
Expand Down Expand Up @@ -268,6 +275,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
google_maps_flutter:
dependency: "direct main"
description:
name: google_maps_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
google_maps_flutter_platform_interface:
dependency: transitive
description:
name: google_maps_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -483,6 +504,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
11 changes: 6 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
flutter_local_notifications: ^5.0.0
add_2_calendar: ^2.0.1
shared_preferences: ^2.0.5
google_maps_flutter: ^2.0.3

dev_dependencies:
flutter_test:
Expand All @@ -60,7 +61,7 @@ flutter:
# the material Icons class.
uses-material-design: true
assets:
- assets/
- assets/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
Expand All @@ -80,10 +81,10 @@ flutter:
fonts:


- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Medium.ttf
weight: 300
- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Medium.ttf
weight: 300

# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages