diff --git a/ResponseApp/lib/main.dart b/ResponseApp/lib/main.dart index 413dbfd..93c36c6 100644 --- a/ResponseApp/lib/main.dart +++ b/ResponseApp/lib/main.dart @@ -1,18 +1,16 @@ import 'dart:io'; -import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; -// import 'views/DetailedNewsPage.dart'; -// import 'views/HomePage.dart'; -// import 'views/MapsBody.dart'; -// import 'views/NewsBody.dart'; -// import 'views/OnboardingScreen.dart'; -// import 'views/SOS.dart'; -// import 'views/SOSselect.dart'; -// import 'views/WhatToDoBody.dart'; -// import 'package:response/views/Flood.dart'; +import 'views/DetailedNewsPage.dart'; +import 'views/HomePage.dart'; +import 'views/MapsBody.dart'; +import 'views/NewsBody.dart'; +import 'views/OnboardingScreen.dart'; +import 'views/SOS.dart'; +import 'views/SOSselect.dart'; +import 'views/WhatToDoBody.dart'; +import 'package:response/views/Flood.dart'; void main() { SystemChrome.setSystemUIOverlayStyle( @@ -32,55 +30,29 @@ void main() { runApp(ResponseApp()); } -class ResponseApp extends StatefulWidget { - @override - _ResponseAppState createState() => _ResponseAppState(); -} - -class _ResponseAppState extends State { - Completer _controller = Completer(); - - static const LatLng _center = const LatLng(45.521563, -122.677433); - - void _onMapCreated(GoogleMapController controller) { - _controller.complete(controller); - } - +class ResponseApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, - // initialRoute: HomePage.id, - // routes: { - // OnboardingScreen.id: (context) => OnboardingScreen(), - // - // //Home Screens - // HomePage.id: (context) => HomePage(), - // WhatToDoBody.id: (context) => WhatToDoBody(), - // NewsBody.id: (context) => NewsBody(), - // MapsBody.id: (context) => MapsBody(), - // Flood.id: (context) => Flood(), - // - // //SOS page - // SOS.id: (context) => SOS(), - // SOSselect.id: (context) => SOSselect(), - // - // //Detailed Screens - // DetailedNewsPage.id: (context) => DetailedNewsPage(), - // }, - home: Scaffold( - appBar: AppBar( - title: Text('Maps Sample App'), - backgroundColor: Colors.green[700], - ), - body: GoogleMap( - onMapCreated: _onMapCreated, - initialCameraPosition: CameraPosition( - target: _center, - zoom: 11.0, - ), - ), - ), + initialRoute: HomePage.id, + routes: { + OnboardingScreen.id: (context) => OnboardingScreen(), + + //Home Screens + HomePage.id: (context) => HomePage(), + WhatToDoBody.id: (context) => WhatToDoBody(), + NewsBody.id: (context) => NewsBody(), + MapsBody.id: (context) => MapsBody(), + Flood.id: (context) => Flood(), + + //SOS page + SOS.id: (context) => SOS(), + SOSselect.id: (context) => SOSselect(), + + //Detailed Screens + DetailedNewsPage.id: (context) => DetailedNewsPage(), + }, ); } } diff --git a/ResponseApp/lib/utilities/LocationService.dart b/ResponseApp/lib/utilities/LocationService.dart index 9cc43b4..8aba1d2 100644 --- a/ResponseApp/lib/utilities/LocationService.dart +++ b/ResponseApp/lib/utilities/LocationService.dart @@ -1,5 +1,6 @@ import 'package:geolocator/geolocator.dart'; import 'package:geocoder/geocoder.dart'; +import 'dart:async'; class LocationService { String _userLocation = 'INDIA'; @@ -7,9 +8,14 @@ class LocationService { double longitude; Future getLocation() async { + GeolocationStatus geolocationStatus = + await Geolocator().checkGeolocationPermissionStatus(); + try { Position position = await Geolocator() - .getCurrentPosition(desiredAccuracy: LocationAccuracy.medium); + .getCurrentPosition(desiredAccuracy: LocationAccuracy.high); + + // Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium); final coordinates = Coordinates(position.latitude, position.longitude); var addresses = @@ -46,8 +52,10 @@ class LocationService { Position position = await Geolocator() .getCurrentPosition(desiredAccuracy: LocationAccuracy.low); + print("here ${position.latitude}"); return position.latitude; } catch (e) { + print(e); return 20.5937; } } diff --git a/ResponseApp/lib/views/MapsBody.dart b/ResponseApp/lib/views/MapsBody.dart index 4fa6ccb..f442a45 100644 --- a/ResponseApp/lib/views/MapsBody.dart +++ b/ResponseApp/lib/views/MapsBody.dart @@ -55,8 +55,8 @@ class _MapsBodyState extends State { markerId: MarkerId(_lastMapPosition.toString()), position: _lastMapPosition, infoWindow: InfoWindow( - title: 'Really cool place', - snippet: '5 Star Rating', + title: 'Your Current Location', + snippet: "Mumbai", ), icon: BitmapDescriptor.defaultMarker, )); @@ -73,11 +73,8 @@ class _MapsBodyState extends State { @override void initState() { - // getLocationData(); - + getLocationData(); super.initState(); - - //map code } @override diff --git a/ResponseApp/lib/views/NewsBody.dart b/ResponseApp/lib/views/NewsBody.dart index b5b8398..5f3269d 100644 --- a/ResponseApp/lib/views/NewsBody.dart +++ b/ResponseApp/lib/views/NewsBody.dart @@ -21,7 +21,7 @@ class _NewsBodyState extends State { String _isClicked = 'national'; LocationService locationService = LocationService(); - var userLocation; + var userLocation = "MUMBAI"; //New firestore instance final _firestore = Firestore.instance; @@ -31,13 +31,15 @@ class _NewsBodyState extends State { @override void initState() { - super.initState(); getLocationData(); + super.initState(); } - void getLocationData() async { + //Needs to be future! + Future getLocationData() async { // Fetching _userLocation userLocation = await locationService.getLocation(); + setState(() {}); } @override @@ -49,8 +51,6 @@ class _NewsBodyState extends State { allowFontScaling: true, ); - print(userLocation); - return Column( children: [ CustomAppBar(), @@ -167,10 +167,7 @@ class _NewsBodyState extends State { : news.data['location']); String newsLocation = location.toUpperCase(); - - //TODO: userLocation giving null - var temp = "MUMBAI"; - if (temp.contains(newsLocation)) { + if (userLocation.contains(newsLocation)) { //date conversion DateTime myDateTime = DateTime.parse(news.data['date'].toDate().toString()); diff --git a/ResponseApp/pubspec.yaml b/ResponseApp/pubspec.yaml index aeeef33..1d226d0 100644 --- a/ResponseApp/pubspec.yaml +++ b/ResponseApp/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: intl: geolocator: ^5.3.2+2 geocoder: ^0.2.1 +# permission_handler: ^5.0.1+1 # Google Services: provider: ^4.3.1