-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwelcome.dart
174 lines (154 loc) · 4.58 KB
/
welcome.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_assign1/constants.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_webservice/places.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:android_intent/android_intent.dart';
import 'package:platform/platform.dart' as PlatformManager;
import 'package:geolocation/geolocation.dart' as Geolocation;
class Welcome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return _WelcomePage();
}
}
class _WelcomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _WelcomePageState();
}
}
class _WelcomePageState extends State<_WelcomePage> {
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: Constants.GOOGLE_API_KEY);
String email = "";
GoogleMapController mapController;
List<PlacesSearchResult> places = [];
var displayName = '';
void _onMapCreated(GoogleMapController controller, context) {
setState(() {
mapController = controller;
_checkLocationService();
});
}
_checkLocationService() {
var platform = PlatformManager.LocalPlatform();
if (platform.isAndroid) {
_getLocation(context);
}
}
_openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
_getLocation(context) async {
Geolocation.Geolocation.currentLocation(accuracy: Geolocation.LocationAccuracy.block)
.listen((res) {
if (res.isSuccessful) {
print(res.location.toString());
var center = LatLng(res.location.latitude, res.location.longitude);
mapController.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(
bearing: 270.0,
target: center,
tilt: 30.0,
zoom: 16.0,
),
)).then((animated) {
_getNearbyPlaces(center, context);
}).catchError((err) => print(err));
} else {
print(res.error.toString());
}
});
}
@override
Widget build(BuildContext context) {
FirebaseAuth.instance.currentUser()
.then((user) {
setState(() {
this.displayName = user.displayName;
this.email = user.email;
});
});
return Scaffold(
appBar: AppBar(
title: Text(
"Welcome ${this.displayName}"
),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: GoogleMap(
onMapCreated: (controller) {
_onMapCreated(controller, context);
},
options: GoogleMapOptions(
myLocationEnabled: true,
compassEnabled: true,
zoomGesturesEnabled: true,
),
),
)
],
)
);
}
void _getNearbyPlaces(LatLng center, context) async {
final location = Location(center.latitude, center.longitude);
_places.searchNearbyWithRadius(
location, 1500, keyword: "axis bank"
).then((result) {
if (result.status == "OK") {
this.places = result.results;
LatLng place;
result.results.getRange(0, 1).forEach((f) {
place = LatLng(f.geometry.location.lat, f.geometry.location.lng);
final markerOptions = MarkerOptions(
position: place,
infoWindowText: InfoWindowText(
"${f.name}", "${f.types?.first}"));
mapController.addMarker(markerOptions);
});
_showDialog(place, context);
} else {
print(result.errorMessage);
}
}).catchError((err) =>print(err));
}
_launchURL(url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
_showDialog(place, context) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Navigate?"),
actions: <Widget>[
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text("Navigate"),
onPressed: () {
_launchURL("google.navigation:q=${place.latitude},${place.longitude}");
},
),
],
);
}
);
}
}