Skip to content
Permalink
Browse files

Added map screen with public transport services slide up

  • Loading branch information...
tattwei46 committed Dec 16, 2018
1 parent faec914 commit 942e96bdf90cb4e9495bc8e0de4fb4fc553d2cc8
@@ -6,6 +6,7 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
@@ -16,6 +17,8 @@
android:name="io.flutter.app.FlutterApplication"
android:label="mallsyok"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCsq5t2lFdV9R8LonLVTB5OcZKTNNSN7fA"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
@@ -263,10 +263,12 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
"${PODS_ROOT}/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Resources/GoogleMaps.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/gRPC/gRPCCertificates.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleMaps.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gRPCCertificates.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1,10 +1,12 @@
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSServices provideAPIKey:@"AIzaSyCsq5t2lFdV9R8LonLVTB5OcZKTNNSN7fA"];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
@@ -2,6 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
@@ -6,6 +6,7 @@ import 'package:mallsyok/screen/mall_list_screen.dart';
import 'package:mallsyok/screen/outlet_list_screen.dart';
import 'package:mallsyok/screen/promotion_screen.dart';
import 'package:mallsyok/screen/mall_details_screen.dart';
import 'package:mallsyok/screen/direction_screen.dart';

class PlatformDrawer extends StatelessWidget {
final Mall mall;
@@ -72,7 +73,11 @@ class PlatformDrawer extends StatelessWidget {
leading: const Icon(
FontAwesomeIcons.mapMarkedAlt,
),
onTap: () {},
onTap: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) => DirectionScreen(mall: mall)));

},
),
Divider(),
ListTile(
@@ -6,6 +6,7 @@ class Mall {
String mallPhone;
String mallAddress;
String mallWebsite;
String mallCoordinates;
String openingHours;
String mallImagePath;
String parkingLost;
@@ -19,6 +20,7 @@ class Mall {
this.mallName,
this.mallPhone,
this.mallAddress,
this.mallCoordinates,
this.mallWebsite,
this.openingHours,
this.mallImagePath,
@@ -36,6 +38,7 @@ class Mall {
mallPhone = snapshot.data["mallPhone"],
mallAddress = snapshot.data["mallAddress"],
mallWebsite = snapshot.data["mallWebsite"],
mallCoordinates = snapshot.data["mallCoordinates"],
openingHours = snapshot.data["openingHours"],
mallImagePath = snapshot.data["mallImagePath"],
parkingLost = snapshot.data["parkingLost"],
@@ -26,6 +26,9 @@ class AppConfig {
static const String TEXT_INFORMATION = "Information";
static const String TEXT_PARKING = "Parking";
static const String TEXT_OPENING_HOURS = "Opening Hours";
static const String TEXT_SERVICE_BUS = "Bus Service";
static const String TEXT_SERVICE_RAIL = "Rail Service";
static const String TEXT_SERVICE_MORE = "More Information";
static const String TEXT_CATEGORY_ALL = "All Category";
static const String TEXT_CATEGORY_DEPARTMENT = "Departmental Store";
static const String TEXT_CATEGORY_BEAUTY = "Beauty & Hair Salon";
@@ -0,0 +1,243 @@
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:mallsyok/res/app_config.dart';
import 'package:mallsyok/model/mall.dart';
import 'package:mallsyok/common_widget/platform_drawer.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:location/location.dart' as LocationManager;

class DirectionScreen extends StatefulWidget {
final Mall mall;

const DirectionScreen({Key key, this.mall}) : super(key: key);

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

class _DirectionScreenState extends State<DirectionScreen> {
GoogleMapController mapController;
LatLng mallLatLng;

LatLng parseLatLng(String coordinates) {
String searchText = ",";
int index = coordinates.indexOf(searchText, 0);
double long = 0.0;
double lat = 0.0;
lat = double.parse(coordinates.substring(0, index));
long = double.parse(coordinates.substring(index + 1, coordinates.length).trim());
LatLng latLng = new LatLng(lat, long);
print(latLng.latitude.toString() + "," + latLng.longitude.toString());
return latLng;
}

Widget buildBody(double appBarHeight) {
double mapHeight = MediaQuery.of(context).size.height - appBarHeight - 30.0;
return Column(
children: <Widget>[
Container(
child: SizedBox(
height: mapHeight,
child: GoogleMap(
onMapCreated: (GoogleMapController controller) {
mapController = controller;
final markerOptions = MarkerOptions(
position: LatLng(mallLatLng.latitude, mallLatLng.longitude),
infoWindowText: InfoWindowText(widget.mall.mallName, ""),
);
controller.addMarker(markerOptions);
},
options: GoogleMapOptions(
cameraPosition: CameraPosition(
target: LatLng(mallLatLng.latitude, mallLatLng.longitude),
zoom: 15.0,
),
),
)),
),
],
);
}

String fixEndline(String inputString) {
String searchText = "\; ";
// Check how many endlines in the input string
int numOfOccurences = searchText.allMatches(inputString).length;

int endLineIndexTempString = 0;
int endLineIndexInputString = 0;
String temp;
String outputString = "";
if (numOfOccurences > 0) {
for (int i = 0; i < numOfOccurences; i++) {
// Get a working string to scan for endline
temp =
inputString.substring(endLineIndexInputString, inputString.length);
// Get endline index
endLineIndexTempString = temp.indexOf(searchText, 0);
// Trim from starting point to endline index and add to output string
outputString =
outputString + temp.substring(0, endLineIndexTempString) + "\n";
// Keep track of endline position in input string
endLineIndexInputString =
endLineIndexInputString + endLineIndexTempString + 2;
}

// We add the last section of the string to output
temp = inputString.substring(endLineIndexInputString, inputString.length);
outputString = outputString + temp.substring(0, temp.length);

return outputString;
} else
return inputString;
}

Widget buildTitle() {
return Text(
AppConfig.TEXT_GETTING_THERE,
textAlign: TextAlign.center,
style: new TextStyle(fontSize: 25.0, fontWeight: FontWeight.bold),
);
}

Widget buildEmpty() {
return Container(
height: 0.0,
width: 0.0,
);
}

void goToUserLocation() async {
final getLocation = await getUserLocation();
final markerOptions = MarkerOptions(
position: getLocation == null ? LatLng(0, 0) : getLocation,
infoWindowText: InfoWindowText("Current location", ""),
);
mapController.addMarker(markerOptions);
mapController.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target: getLocation == null ? LatLng(0, 0) : getLocation, zoom: 15.0)));
}

Future<LatLng> getUserLocation() async {
var currentLocation = <String, double>{};
final location = LocationManager.Location();
try {
currentLocation = await location.getLocation();
final lat = currentLocation["latitude"];
final lng = currentLocation["longitude"];
final center = LatLng(lat, lng);
return center;
} on Exception {
currentLocation = null;
return null;
}
}

Widget buildDetails(String header, String body, IconData iconData) {
if (body != null && body.length > 0) {
body = fixEndline(body);
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 30.0, 0.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
header,
textAlign: TextAlign.center,
style: new TextStyle(
fontSize: 18.0, fontWeight: FontWeight.bold),
),
Padding(
padding: EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 0.0),
child: Icon(iconData),
)
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 20.0, 0.0, 0.0),
child: GestureDetector(
onTap: () {},
child: Text(
body,
textAlign: TextAlign.left,
style: new TextStyle(fontSize: 16.0),
),
))
],
);
} else
return buildEmpty();
}

@override
void initState() {
double lat = parseLatLng(widget.mall.mallCoordinates).latitude;
double long = parseLatLng(widget.mall.mallCoordinates).longitude;
mallLatLng = new LatLng(lat, long);
super.initState();
}

Future<Widget> _servicesSlideUp() async {
return showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: ListView(
children: <Widget>[
buildTitle(),
buildDetails(AppConfig.TEXT_SERVICE_BUS,
widget.mall.directionBus, FontAwesomeIcons.bus),
buildDetails(AppConfig.TEXT_SERVICE_RAIL,
widget.mall.directionRail, FontAwesomeIcons.train),
buildDetails(AppConfig.TEXT_SERVICE_MORE,
widget.mall.directionService, FontAwesomeIcons.info),
],
),
),
);
});
}

@override
Widget build(BuildContext context) {
AppBar appBar = AppBar(
backgroundColor: kAppThemeColor,
title: new Text(
widget.mall.mallName,
style: new TextStyle(color: Colors.white),
),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.info,
size: 30.0,
),
tooltip: "Get more information",
onPressed: () {
_servicesSlideUp();
},
),
],
);

return new Scaffold(
appBar: appBar,
body: buildBody(appBar.preferredSize.height),
drawer: PlatformDrawer(
mall: widget.mall,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
goToUserLocation();
},
tooltip: "Get current location",
child: new Icon(Icons.my_location),
),
);
}
}
@@ -132,7 +132,7 @@ class _MallDetailsScreenState extends State<MallDetailsScreen> {
// Get a working string to scan for endline
temp = inputString.substring(endLineIndexInputString, inputString.length);
// Get endline index
endLineIndexTempString = temp.indexOf("\\n", 0);
endLineIndexTempString = temp.indexOf(searchText, 0);
// Trim from starting point to endline index and add to output string
outputString = outputString + temp.substring(0, endLineIndexTempString) +
"\n";
@@ -25,6 +25,9 @@ dependencies:
font_awesome_flutter: ^8.2.0
draggable_scrollbar: ^0.0.4
url_launcher: ^4.0.2
google_maps_flutter: ^0.0.3+3
location: ^1.4.1
flutter_google_places: ^0.1.4

dev_dependencies:
flutter_test:

0 comments on commit 942e96b

Please sign in to comment.
You can’t perform that action at this time.