From 1f2b230a643c5423d85bf313dcb7a9018cc515c5 Mon Sep 17 00:00:00 2001 From: sachin Date: Mon, 9 Nov 2020 13:17:38 +0530 Subject: [PATCH] remove location permissions --- android/app/build.gradle | 20 +- lib/page/screen/case_details_map_screen.dart | 468 +++++++++---------- lib/page/screen/case_details_screen.dart | 456 +++++++++--------- lib/page/screen/case_list_screen.dart | 462 +++++++++--------- lib/page/screen/dashboard_screen.dart | 6 +- lib/page/screen/qr_scan_screen.dart | 7 +- 6 files changed, 712 insertions(+), 707 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 409211c..1239693 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -59,18 +59,18 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } - // signingConfigs { - // release { - // keyAlias keystoreProperties['keyAlias'] - // keyPassword keystoreProperties['keyPassword'] - // storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null - // storePassword keystoreProperties['storePassword'] - // } - // } + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword keystoreProperties['storePassword'] + } + } buildTypes { release { - // signingConfig signingConfigs.release - signingConfig signingConfigs.debug + signingConfig signingConfigs.release + // signingConfig signingConfigs.debug } } } diff --git a/lib/page/screen/case_details_map_screen.dart b/lib/page/screen/case_details_map_screen.dart index eefaa47..16dfdc0 100644 --- a/lib/page/screen/case_details_map_screen.dart +++ b/lib/page/screen/case_details_map_screen.dart @@ -1,234 +1,234 @@ -import 'dart:async'; -import 'dart:convert'; -import 'package:async/async.dart'; -import 'package:clustering_google_maps/clustering_google_maps.dart'; -import 'package:geolocator/geolocator.dart'; -import 'package:http/http.dart'; -import 'package:intl/intl.dart'; - -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:selftrackingapp/models/location.dart'; -import 'package:selftrackingapp/models/reported_case.dart'; -import 'package:selftrackingapp/networking/api_client.dart'; -import 'package:selftrackingapp/widgets/case_item_map_detail.dart'; - -DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss"); - -class CaseListMapDetailScreen extends StatefulWidget { - const CaseListMapDetailScreen({Key key}) : super(key: key); - - @override - _CaseListMapDetailScreenState createState() => - _CaseListMapDetailScreenState(); -} - -class _CaseListMapDetailScreenState extends State { - ClusteringHelper clusteringHelper; - static const MethodChannel _channel = MethodChannel('location'); - ReportedCase selectedCase; - - Completer _controller = Completer(); - Position _currentLocation; - double pinPillPosition = -1000; - - List locationMarkers = []; - List mapMakerList = []; - Map caseListMapWithId = Map(); - bool ready = false; - - Future _fetchCases() async { - List _cases = []; - int id = await ApiClient().getLastCaseId(); - if (id == -1) { - return _cases; - } - - for (int i = id; i > 0; i--) { - ReportedCase reportedCase = - await ApiClient().getCase(i, forceUpdate: false); - if (reportedCase != null && reportedCase.locations != null) { - Location l = reportedCase.locations[0]; - var latLan = LatLngAndGeohash(LatLng(l.latitude, l.longitude)); - setState(() { - caseListMapWithId[latLan.geohash] = reportedCase; - mapMakerList.add(latLan); - }); - } - - setState(() { - clusteringHelper = ClusteringHelper.forMemory( - list: mapMakerList, - bitmapAssetPathForSingleMarker: "assets/images/suspected_icon.png", - updateMarkers: (Set markers) { - setState(() { - locationMarkers = markers.map((marker) { - int count = int.parse(marker.infoWindow.title); - if (count == 1) { - LatLng l = marker.position; - ReportedCase reportedCase = caseListMapWithId[ - "${LatLngAndGeohash(LatLng(l.latitude, l.longitude)).geohash}"]; - return Marker( - icon: marker.icon, - alpha: 0.5, - markerId: marker.markerId, - position: LatLng(l.latitude, l.longitude), - onTap: () { - setState(() { - selectedCase = reportedCase; - pinPillPosition = - MediaQuery.of(context).size.height / 10; - }); - }); - } - return Marker( - icon: marker.icon, - alpha: 0.8, - markerId: marker.markerId, - position: marker.position, - onTap: () { - setState(() { - pinPillPosition = -MediaQuery.of(context).size.height; - }); - }); - ; - }).toList(); - }); - }, - aggregationSetup: AggregationSetup(markerSize: 150)); - }); - } - setState(() { - ready = true; - }); - - print("Cases found Retreived: ${_cases.length}"); - } - - @override - void initState() { - super.initState(); - _fetchCases(); - } - - @override - void dispose() { - super.dispose(); -// if (_locationTimer != null) _locationTimer.cancel(); -// if (_currentLoctimer != null) _currentLoctimer.cancel(); - print("CANCELLING timers"); - } - - @override - Widget build(BuildContext context) { - return Container( - child: getMapView(), //initially this will be empty - ); - } - - Widget getMapView() { - return Scaffold( - body: clusteringHelper != null && ready - ? Stack( - children: [ - GoogleMap( - mapType: MapType.terrain, - markers: getMapEntries(), - initialCameraPosition: CameraPosition( - target: _currentLocation != null - ? LatLng(_currentLocation.latitude, - _currentLocation.longitude) - : LatLng(6.9271, 79.8612), - zoom: 12, - ), - mapToolbarEnabled: true, - myLocationButtonEnabled: true, - myLocationEnabled: true, - onMapCreated: (GoogleMapController controller) async { - _controller.complete(controller); - clusteringHelper.mapController = controller; - clusteringHelper.updateMap(); - }, - onCameraMove: (position) { - clusteringHelper.onCameraMove(position, forceUpdate: true); - }, - onCameraIdle: clusteringHelper.onMapIdle, - onTap: (LatLng location) { - setState(() { - pinPillPosition = -MediaQuery.of(context).size.height; - }); - }, - ), - AnimatedPositioned( - bottom: pinPillPosition, - right: 0, - left: 0, - duration: Duration(milliseconds: 300), - child: Align( - alignment: Alignment.bottomCenter, - child: Container( - margin: EdgeInsets.all(4), - width: MediaQuery.of(context).size.width * 7 / 8, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(16)), - boxShadow: [ - BoxShadow( - blurRadius: 20, - offset: Offset.zero, - color: Colors.grey.withOpacity(0.5)) - ]), - child: selectedCase != null - ? Padding( - padding: const EdgeInsets.all(8.0), - child: CaseItemMapInfo(selectedCase, () { - print("Click Card"); - setState(() { - pinPillPosition = - -MediaQuery.of(context).size.height; - }); - }), - ) - : Container(), - )), - ) - ], - ) - : Container( - child: Center( - child: Text("Loading..."), - ), - ), - ); - } - - Widget getListView(List entries) { - return ListView.builder( - padding: const EdgeInsets.all(8), - itemCount: entries.length, - itemBuilder: (BuildContext context, int index) { - return Text( - 'Entry ${entries[index].longitude},${entries[index].latitude},${entries[index].date}'); - }); - } - - Future> getLocationUpdate() async { - try { - final List locations = - await _channel.invokeMethod('getLocation'); - print("locations $locations"); - - return locations - .map((v) => Location.fromBackgroundJson(json.decode(v))) - .toList(); - } on Exception catch (e) { - print(e); - } - return null; - } - - getMapEntries() { - return locationMarkers.toSet(); - } -} +// import 'dart:async'; +// import 'dart:convert'; +// import 'package:async/async.dart'; +// import 'package:clustering_google_maps/clustering_google_maps.dart'; +// import 'package:geolocator/geolocator.dart'; +// import 'package:http/http.dart'; +// import 'package:intl/intl.dart'; + +// import 'package:flutter/material.dart'; +// import 'package:flutter/services.dart'; +// import 'package:google_maps_flutter/google_maps_flutter.dart'; +// import 'package:selftrackingapp/models/location.dart'; +// import 'package:selftrackingapp/models/reported_case.dart'; +// import 'package:selftrackingapp/networking/api_client.dart'; +// import 'package:selftrackingapp/widgets/case_item_map_detail.dart'; + +// DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss"); + +// class CaseListMapDetailScreen extends StatefulWidget { +// const CaseListMapDetailScreen({Key key}) : super(key: key); + +// @override +// _CaseListMapDetailScreenState createState() => +// _CaseListMapDetailScreenState(); +// } + +// class _CaseListMapDetailScreenState extends State { +// ClusteringHelper clusteringHelper; +// static const MethodChannel _channel = MethodChannel('location'); +// ReportedCase selectedCase; + +// Completer _controller = Completer(); +// Position _currentLocation; +// double pinPillPosition = -1000; + +// List locationMarkers = []; +// List mapMakerList = []; +// Map caseListMapWithId = Map(); +// bool ready = false; + +// Future _fetchCases() async { +// List _cases = []; +// int id = await ApiClient().getLastCaseId(); +// if (id == -1) { +// return _cases; +// } + +// for (int i = id; i > 0; i--) { +// ReportedCase reportedCase = +// await ApiClient().getCase(i, forceUpdate: false); +// if (reportedCase != null && reportedCase.locations != null) { +// Location l = reportedCase.locations[0]; +// var latLan = LatLngAndGeohash(LatLng(l.latitude, l.longitude)); +// setState(() { +// caseListMapWithId[latLan.geohash] = reportedCase; +// mapMakerList.add(latLan); +// }); +// } + +// setState(() { +// clusteringHelper = ClusteringHelper.forMemory( +// list: mapMakerList, +// bitmapAssetPathForSingleMarker: "assets/images/suspected_icon.png", +// updateMarkers: (Set markers) { +// setState(() { +// locationMarkers = markers.map((marker) { +// int count = int.parse(marker.infoWindow.title); +// if (count == 1) { +// LatLng l = marker.position; +// ReportedCase reportedCase = caseListMapWithId[ +// "${LatLngAndGeohash(LatLng(l.latitude, l.longitude)).geohash}"]; +// return Marker( +// icon: marker.icon, +// alpha: 0.5, +// markerId: marker.markerId, +// position: LatLng(l.latitude, l.longitude), +// onTap: () { +// setState(() { +// selectedCase = reportedCase; +// pinPillPosition = +// MediaQuery.of(context).size.height / 10; +// }); +// }); +// } +// return Marker( +// icon: marker.icon, +// alpha: 0.8, +// markerId: marker.markerId, +// position: marker.position, +// onTap: () { +// setState(() { +// pinPillPosition = -MediaQuery.of(context).size.height; +// }); +// }); +// ; +// }).toList(); +// }); +// }, +// aggregationSetup: AggregationSetup(markerSize: 150)); +// }); +// } +// setState(() { +// ready = true; +// }); + +// print("Cases found Retreived: ${_cases.length}"); +// } + +// @override +// void initState() { +// super.initState(); +// _fetchCases(); +// } + +// @override +// void dispose() { +// super.dispose(); +// // if (_locationTimer != null) _locationTimer.cancel(); +// // if (_currentLoctimer != null) _currentLoctimer.cancel(); +// print("CANCELLING timers"); +// } + +// @override +// Widget build(BuildContext context) { +// return Container( +// child: getMapView(), //initially this will be empty +// ); +// } + +// Widget getMapView() { +// return Scaffold( +// body: clusteringHelper != null && ready +// ? Stack( +// children: [ +// GoogleMap( +// mapType: MapType.terrain, +// markers: getMapEntries(), +// initialCameraPosition: CameraPosition( +// target: _currentLocation != null +// ? LatLng(_currentLocation.latitude, +// _currentLocation.longitude) +// : LatLng(6.9271, 79.8612), +// zoom: 12, +// ), +// mapToolbarEnabled: true, +// myLocationButtonEnabled: true, +// myLocationEnabled: true, +// onMapCreated: (GoogleMapController controller) async { +// _controller.complete(controller); +// clusteringHelper.mapController = controller; +// clusteringHelper.updateMap(); +// }, +// onCameraMove: (position) { +// clusteringHelper.onCameraMove(position, forceUpdate: true); +// }, +// onCameraIdle: clusteringHelper.onMapIdle, +// onTap: (LatLng location) { +// setState(() { +// pinPillPosition = -MediaQuery.of(context).size.height; +// }); +// }, +// ), +// AnimatedPositioned( +// bottom: pinPillPosition, +// right: 0, +// left: 0, +// duration: Duration(milliseconds: 300), +// child: Align( +// alignment: Alignment.bottomCenter, +// child: Container( +// margin: EdgeInsets.all(4), +// width: MediaQuery.of(context).size.width * 7 / 8, +// decoration: BoxDecoration( +// color: Colors.white, +// borderRadius: BorderRadius.all(Radius.circular(16)), +// boxShadow: [ +// BoxShadow( +// blurRadius: 20, +// offset: Offset.zero, +// color: Colors.grey.withOpacity(0.5)) +// ]), +// child: selectedCase != null +// ? Padding( +// padding: const EdgeInsets.all(8.0), +// child: CaseItemMapInfo(selectedCase, () { +// print("Click Card"); +// setState(() { +// pinPillPosition = +// -MediaQuery.of(context).size.height; +// }); +// }), +// ) +// : Container(), +// )), +// ) +// ], +// ) +// : Container( +// child: Center( +// child: Text("Loading..."), +// ), +// ), +// ); +// } + +// Widget getListView(List entries) { +// return ListView.builder( +// padding: const EdgeInsets.all(8), +// itemCount: entries.length, +// itemBuilder: (BuildContext context, int index) { +// return Text( +// 'Entry ${entries[index].longitude},${entries[index].latitude},${entries[index].date}'); +// }); +// } + +// Future> getLocationUpdate() async { +// try { +// final List locations = +// await _channel.invokeMethod('getLocation'); +// print("locations $locations"); + +// return locations +// .map((v) => Location.fromBackgroundJson(json.decode(v))) +// .toList(); +// } on Exception catch (e) { +// print(e); +// } +// return null; +// } + +// getMapEntries() { +// return locationMarkers.toSet(); +// } +// } diff --git a/lib/page/screen/case_details_screen.dart b/lib/page/screen/case_details_screen.dart index a17677f..b016786 100644 --- a/lib/page/screen/case_details_screen.dart +++ b/lib/page/screen/case_details_screen.dart @@ -1,228 +1,228 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:typed_data'; -import 'package:geolocator/geolocator.dart'; -import 'package:intl/intl.dart'; -import 'dart:ui' as ui; - -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:selftrackingapp/models/location.dart'; -import 'package:selftrackingapp/widgets/custom_text.dart'; - -DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss"); - -class CaseDetailScreen extends StatefulWidget { - @override - State createState() => CaseDetailScreenState(); -} - -class CaseDetailScreenState extends State { - static const MethodChannel _channel = MethodChannel('location'); - - Completer _controller = Completer(); - - Position currentLocation; - List entries = List(); - List hospitalLocations = List(); - Timer _locationTimer; - - Timer _currentLoctimer; - bool _isInitialLocationAdded = false; - - Future updateLocation() async { - List newEntries = await getLocationUpdate(); - print("LOCATIONS Fetched: ${newEntries.length}"); - if (this.mounted) { - setState(() { -// entries.clear(); - newEntries.forEach((e) { - if (!entries.contains(e)) { - entries.add(e); - //location id should be used here to prevent duplicate locations from being added - } - }); - print("POLLED locations: ${newEntries.length}"); - }); - } - } - - Future getBytesFromAsset(String path, int width) async { - ByteData data = await rootBundle.load(path); - ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), - targetWidth: width); - ui.FrameInfo fi = await codec.getNextFrame(); - return (await fi.image.toByteData(format: ui.ImageByteFormat.png)) - .buffer - .asUint8List(); - } - - @override - void initState() { - super.initState(); - updateLocation(); - - parseJsonFromAssets("assets/hospitals.json").then((data) async { - final Uint8List markerIcon = - await getBytesFromAsset('assets/images/hospital_sign_map.png', 100); - - for (var h in data["hospitals"]) { - setState(() { - hospitalLocations.add(Marker( - icon: BitmapDescriptor.fromBytes(markerIcon), - markerId: MarkerId("${h["id"]}_id"), - infoWindow: InfoWindow(title: "${h["name"]}"), - position: LatLng(h["lon"], h["lat"]))); - }); - } - }); - - WidgetsBinding.instance.addPostFrameCallback((_) { - _channel.invokeMethod('requestLocationPermission').then((res) { - _channel.invokeMethod('openLocationService').then((res) {}); - }); - - _locationTimer = Timer.periodic(Duration(minutes: 5), (timer) async { - print("POLLING the locations"); - await updateLocation(); - }); - - _currentLoctimer = Timer.periodic(Duration(seconds: 2), (_) { - Geolocator() - .getCurrentPosition(desiredAccuracy: LocationAccuracy.best) - .then((position) { - if (this.mounted) { - setState(() { - if (!_isInitialLocationAdded) { - Location location = new Location( - longitude: position.longitude, - latitude: position.latitude, - date: position.timestamp, - from: position.timestamp, - to: position.timestamp, - address: 'Current Location'); - _isInitialLocationAdded = true; - entries.add(location); - moveMapToCurrentLoc(); - } - currentLocation = position; - }); - } - }); - print("Current Location Updated"); - }); - }); - } - - Future> parseJsonFromAssets(String assetsPath) async { - print('--- Parse json from: $assetsPath'); - return rootBundle - .loadString(assetsPath) - .then((jsonStr) => jsonDecode(jsonStr)); - } - - void moveMapToCurrentLoc() async { - final GoogleMapController controller = await _controller.future; - final CameraPosition _camPos = CameraPosition( - zoom: 15.0, - target: LatLng(currentLocation.latitude, currentLocation.longitude)); - controller.animateCamera(CameraUpdate.newCameraPosition(_camPos)); - } - - @override - void dispose() { - super.dispose(); - if (_locationTimer != null) _locationTimer.cancel(); - if (_currentLoctimer != null) _currentLoctimer.cancel(); - print("CANCELLING timers"); - } - - @override - Widget build(BuildContext context) { - return Container( - child: getMapView(entries), //initially this will be empty - ); - } - - Widget getMapView(List entries) { - return GoogleMap( - mapType: MapType.normal, - markers: hospitalLocations.toSet(), - circles: entries.map((l) { - return Circle( - circleId: CircleId("${l.date.millisecondsSinceEpoch}"), - fillColor: Colors.blue.withOpacity(0.2), - strokeColor: Colors.blue, - strokeWidth: 1, - center: LatLng(l.latitude, l.longitude), - radius: 150, - consumeTapEvents: true, - onTap: () { - _showDialog(l); - }); - }).toSet(), - initialCameraPosition: CameraPosition( - target: currentLocation != null - ? LatLng(currentLocation.latitude, currentLocation.longitude) - : LatLng(6.9271, 79.8612), - zoom: 12, - ), - myLocationButtonEnabled: true, - trafficEnabled: true, -// myLocationEnabled: true, - onMapCreated: (GoogleMapController controller) { - _controller.complete(controller); - }, - ); - } - - void _showDialog(Location location) { - // flutter defined function - showDialog( - context: context, - builder: (BuildContext context) { - // return object of type Dialog - return AlertDialog( - title: new Text("Your location"), - content: - new Text("You were here at ${dateFormat.format(location.date)}"), - actions: [ - // usually buttons at the bottom of the dialog - new FlatButton( - child: new Text("Close"), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - } - - Widget getListView(List entries) { - return ListView.builder( - padding: const EdgeInsets.all(8), - itemCount: entries.length, - itemBuilder: (BuildContext context, int index) { - return Text( - 'Entry ${entries[index].longitude},${entries[index].latitude},${entries[index].date}'); - }); - } - - Future> getLocationUpdate() async { - try { - final List locations = - await _channel.invokeMethod('getLocation'); - print("locations $locations"); - - return locations - .map((v) => Location.fromBackgroundJson(json.decode(v))) - .toList(); - } on Exception catch (e) { - print(e); - } - return null; - } -} +// import 'dart:async'; +// import 'dart:convert'; +// import 'dart:typed_data'; +// import 'package:geolocator/geolocator.dart'; +// import 'package:intl/intl.dart'; +// import 'dart:ui' as ui; + +// import 'package:flutter/material.dart'; +// import 'package:flutter/services.dart'; +// import 'package:google_maps_flutter/google_maps_flutter.dart'; +// import 'package:selftrackingapp/models/location.dart'; +// import 'package:selftrackingapp/widgets/custom_text.dart'; + +// DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss"); + +// class CaseDetailScreen extends StatefulWidget { +// @override +// State createState() => CaseDetailScreenState(); +// } + +// class CaseDetailScreenState extends State { +// static const MethodChannel _channel = MethodChannel('location'); + +// Completer _controller = Completer(); + +// Position currentLocation; +// List entries = List(); +// List hospitalLocations = List(); +// Timer _locationTimer; + +// Timer _currentLoctimer; +// bool _isInitialLocationAdded = false; + +// Future updateLocation() async { +// List newEntries = await getLocationUpdate(); +// print("LOCATIONS Fetched: ${newEntries.length}"); +// if (this.mounted) { +// setState(() { +// // entries.clear(); +// newEntries.forEach((e) { +// if (!entries.contains(e)) { +// entries.add(e); +// //location id should be used here to prevent duplicate locations from being added +// } +// }); +// print("POLLED locations: ${newEntries.length}"); +// }); +// } +// } + +// Future getBytesFromAsset(String path, int width) async { +// ByteData data = await rootBundle.load(path); +// ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), +// targetWidth: width); +// ui.FrameInfo fi = await codec.getNextFrame(); +// return (await fi.image.toByteData(format: ui.ImageByteFormat.png)) +// .buffer +// .asUint8List(); +// } + +// @override +// void initState() { +// super.initState(); +// updateLocation(); + +// parseJsonFromAssets("assets/hospitals.json").then((data) async { +// final Uint8List markerIcon = +// await getBytesFromAsset('assets/images/hospital_sign_map.png', 100); + +// for (var h in data["hospitals"]) { +// setState(() { +// hospitalLocations.add(Marker( +// icon: BitmapDescriptor.fromBytes(markerIcon), +// markerId: MarkerId("${h["id"]}_id"), +// infoWindow: InfoWindow(title: "${h["name"]}"), +// position: LatLng(h["lon"], h["lat"]))); +// }); +// } +// }); + +// WidgetsBinding.instance.addPostFrameCallback((_) { +// _channel.invokeMethod('requestLocationPermission').then((res) { +// _channel.invokeMethod('openLocationService').then((res) {}); +// }); + +// _locationTimer = Timer.periodic(Duration(minutes: 5), (timer) async { +// print("POLLING the locations"); +// await updateLocation(); +// }); + +// _currentLoctimer = Timer.periodic(Duration(seconds: 2), (_) { +// Geolocator() +// .getCurrentPosition(desiredAccuracy: LocationAccuracy.best) +// .then((position) { +// if (this.mounted) { +// setState(() { +// if (!_isInitialLocationAdded) { +// Location location = new Location( +// longitude: position.longitude, +// latitude: position.latitude, +// date: position.timestamp, +// from: position.timestamp, +// to: position.timestamp, +// address: 'Current Location'); +// _isInitialLocationAdded = true; +// entries.add(location); +// moveMapToCurrentLoc(); +// } +// currentLocation = position; +// }); +// } +// }); +// print("Current Location Updated"); +// }); +// }); +// } + +// Future> parseJsonFromAssets(String assetsPath) async { +// print('--- Parse json from: $assetsPath'); +// return rootBundle +// .loadString(assetsPath) +// .then((jsonStr) => jsonDecode(jsonStr)); +// } + +// void moveMapToCurrentLoc() async { +// final GoogleMapController controller = await _controller.future; +// final CameraPosition _camPos = CameraPosition( +// zoom: 15.0, +// target: LatLng(currentLocation.latitude, currentLocation.longitude)); +// controller.animateCamera(CameraUpdate.newCameraPosition(_camPos)); +// } + +// @override +// void dispose() { +// super.dispose(); +// if (_locationTimer != null) _locationTimer.cancel(); +// if (_currentLoctimer != null) _currentLoctimer.cancel(); +// print("CANCELLING timers"); +// } + +// @override +// Widget build(BuildContext context) { +// return Container( +// child: getMapView(entries), //initially this will be empty +// ); +// } + +// Widget getMapView(List entries) { +// return GoogleMap( +// mapType: MapType.normal, +// markers: hospitalLocations.toSet(), +// circles: entries.map((l) { +// return Circle( +// circleId: CircleId("${l.date.millisecondsSinceEpoch}"), +// fillColor: Colors.blue.withOpacity(0.2), +// strokeColor: Colors.blue, +// strokeWidth: 1, +// center: LatLng(l.latitude, l.longitude), +// radius: 150, +// consumeTapEvents: true, +// onTap: () { +// _showDialog(l); +// }); +// }).toSet(), +// initialCameraPosition: CameraPosition( +// target: currentLocation != null +// ? LatLng(currentLocation.latitude, currentLocation.longitude) +// : LatLng(6.9271, 79.8612), +// zoom: 12, +// ), +// myLocationButtonEnabled: true, +// trafficEnabled: true, +// // myLocationEnabled: true, +// onMapCreated: (GoogleMapController controller) { +// _controller.complete(controller); +// }, +// ); +// } + +// void _showDialog(Location location) { +// // flutter defined function +// showDialog( +// context: context, +// builder: (BuildContext context) { +// // return object of type Dialog +// return AlertDialog( +// title: new Text("Your location"), +// content: +// new Text("You were here at ${dateFormat.format(location.date)}"), +// actions: [ +// // usually buttons at the bottom of the dialog +// new FlatButton( +// child: new Text("Close"), +// onPressed: () { +// Navigator.of(context).pop(); +// }, +// ), +// ], +// ); +// }, +// ); +// } + +// Widget getListView(List entries) { +// return ListView.builder( +// padding: const EdgeInsets.all(8), +// itemCount: entries.length, +// itemBuilder: (BuildContext context, int index) { +// return Text( +// 'Entry ${entries[index].longitude},${entries[index].latitude},${entries[index].date}'); +// }); +// } + +// Future> getLocationUpdate() async { +// try { +// final List locations = +// await _channel.invokeMethod('getLocation'); +// print("locations $locations"); + +// return locations +// .map((v) => Location.fromBackgroundJson(json.decode(v))) +// .toList(); +// } on Exception catch (e) { +// print(e); +// } +// return null; +// } +// } diff --git a/lib/page/screen/case_list_screen.dart b/lib/page/screen/case_list_screen.dart index f3f3729..a4d8ef9 100644 --- a/lib/page/screen/case_list_screen.dart +++ b/lib/page/screen/case_list_screen.dart @@ -1,237 +1,237 @@ -import 'package:async/async.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:selftrackingapp/app_localizations.dart'; -import 'package:selftrackingapp/models/reported_case.dart'; -import 'package:selftrackingapp/networking/api_client.dart'; -import 'package:selftrackingapp/notifiers/registered_cases_model.dart'; -import 'package:selftrackingapp/page/screen/user_register_screen.dart'; -import 'package:selftrackingapp/utils/tracker_colors.dart'; -import 'package:selftrackingapp/widgets/case_item.dart'; -import 'package:selftrackingapp/widgets/custom_text.dart'; +// import 'package:async/async.dart'; +// import 'package:flutter/material.dart'; +// import 'package:provider/provider.dart'; +// import 'package:selftrackingapp/app_localizations.dart'; +// import 'package:selftrackingapp/models/reported_case.dart'; +// import 'package:selftrackingapp/networking/api_client.dart'; +// import 'package:selftrackingapp/notifiers/registered_cases_model.dart'; +// import 'package:selftrackingapp/page/screen/user_register_screen.dart'; +// import 'package:selftrackingapp/utils/tracker_colors.dart'; +// import 'package:selftrackingapp/widgets/case_item.dart'; +// import 'package:selftrackingapp/widgets/custom_text.dart'; -class CaseListScreen extends StatefulWidget { - @override - _CaseListScreenState createState() => _CaseListScreenState(); -} +// class CaseListScreen extends StatefulWidget { +// @override +// _CaseListScreenState createState() => _CaseListScreenState(); +// } -class _CaseListScreenState extends State { - String _searchKey = ""; - final AsyncMemoizer> _memorizer = AsyncMemoizer(); +// class _CaseListScreenState extends State { +// String _searchKey = ""; +// final AsyncMemoizer> _memorizer = AsyncMemoizer(); - @override - void initState() { - super.initState(); - } +// @override +// void initState() { +// super.initState(); +// } - Future> _fetchCases() async { - return this._memorizer.runOnce(() async { - List _cases = []; - int id = await ApiClient().getLastCaseId(); - if (id == -1) { - return _cases; - } - for (int i = id; i > 0; i--) { - ReportedCase reportedCase = - await ApiClient().getCase(i, forceUpdate: false); - if (reportedCase != null) _cases.add(reportedCase); - } - print("Cases found Retreived: ${_cases.length}"); - return _cases; - }); - } +// Future> _fetchCases() async { +// return this._memorizer.runOnce(() async { +// List _cases = []; +// int id = await ApiClient().getLastCaseId(); +// if (id == -1) { +// return _cases; +// } +// for (int i = id; i > 0; i--) { +// ReportedCase reportedCase = +// await ApiClient().getCase(i, forceUpdate: false); +// if (reportedCase != null) _cases.add(reportedCase); +// } +// print("Cases found Retreived: ${_cases.length}"); +// return _cases; +// }); +// } - @override - Widget build(BuildContext context) { - print(Provider.of(context).reportedCases.length); - return Container( - child: CustomScrollView( - slivers: [ - SliverAppBar( - backgroundColor: Colors.white, - floating: true, - snap: true, - expandedHeight: 100.0, - flexibleSpace: Container( - margin: const EdgeInsets.all(20.0), - child: TextFormField( - decoration: InputDecoration( - labelStyle: TextStyle(color: TrackerColors.primaryColor), - labelText: AppLocalizations.of(context) - .translate("case_list_screen_search"), - border: OutlineInputBorder(), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(15.0), - borderSide: BorderSide( - color: TrackerColors.primaryColor, - ), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: TrackerColors.primaryColor, width: 1.0), - ), - suffixIcon: Icon( - Icons.search, - color: TrackerColors.primaryColor, - ), - ), - onChanged: (value) { - setState(() { - _searchKey = value; - }); - }, - ), - ), - ), - Provider.of(context).reportedCases.length > 0 - ? SliverAppBar( - backgroundColor: Colors.white, - pinned: true, - bottom: PreferredSize( - preferredSize: Size.fromHeight(10.0), - child: Text(''), // Add this code - ), - flexibleSpace: Container( - child: Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - mainAxisSize: MainAxisSize.max, - children: [ - FlatButton( - onPressed: () { - setState(() { - Provider.of(context, - listen: false) - .reportedCases - .clear(); - }); - }, - child: Text(AppLocalizations.of(context) - .translate('case_list_screen_remove_text')), - ), - RaisedButton( - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.all(Radius.circular(20.0))), - color: TrackerColors.primaryColor, - onPressed: () { - RegisteredCasesModel model = - Provider.of(context, - listen: false); +// @override +// Widget build(BuildContext context) { +// print(Provider.of(context).reportedCases.length); +// return Container( +// child: CustomScrollView( +// slivers: [ +// SliverAppBar( +// backgroundColor: Colors.white, +// floating: true, +// snap: true, +// expandedHeight: 100.0, +// flexibleSpace: Container( +// margin: const EdgeInsets.all(20.0), +// child: TextFormField( +// decoration: InputDecoration( +// labelStyle: TextStyle(color: TrackerColors.primaryColor), +// labelText: AppLocalizations.of(context) +// .translate("case_list_screen_search"), +// border: OutlineInputBorder(), +// enabledBorder: OutlineInputBorder( +// borderRadius: BorderRadius.circular(15.0), +// borderSide: BorderSide( +// color: TrackerColors.primaryColor, +// ), +// ), +// focusedBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: TrackerColors.primaryColor, width: 1.0), +// ), +// suffixIcon: Icon( +// Icons.search, +// color: TrackerColors.primaryColor, +// ), +// ), +// onChanged: (value) { +// setState(() { +// _searchKey = value; +// }); +// }, +// ), +// ), +// ), +// Provider.of(context).reportedCases.length > 0 +// ? SliverAppBar( +// backgroundColor: Colors.white, +// pinned: true, +// bottom: PreferredSize( +// preferredSize: Size.fromHeight(10.0), +// child: Text(''), // Add this code +// ), +// flexibleSpace: Container( +// child: Center( +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceEvenly, +// mainAxisSize: MainAxisSize.max, +// children: [ +// FlatButton( +// onPressed: () { +// setState(() { +// Provider.of(context, +// listen: false) +// .reportedCases +// .clear(); +// }); +// }, +// child: Text(AppLocalizations.of(context) +// .translate('case_list_screen_remove_text')), +// ), +// RaisedButton( +// shape: RoundedRectangleBorder( +// borderRadius: +// BorderRadius.all(Radius.circular(20.0))), +// color: TrackerColors.primaryColor, +// onPressed: () { +// RegisteredCasesModel model = +// Provider.of(context, +// listen: false); - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => ChangeNotifierProvider.value( - value: model, - child: UserRegisterScreen(), - ), - )); - }, - child: Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - AppLocalizations.of(context) - .translate("cse_list_screen_see-text") + - "(${Provider.of(context).reportedCases.length})", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - color: Colors.white), - ), - ), - Icon(Icons.keyboard_arrow_right, - color: Colors.white), - ], - ), - ), - ], - ))), - ) - : SliverToBoxAdapter( - child: Container(), - ), - FutureBuilder>( - future: _fetchCases(), - builder: (BuildContext context, - AsyncSnapshot> snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.none: - return SliverToBoxAdapter( - child: Center( - child: - Text("Error getting the cases, try again later.")), - ); - break; - case ConnectionState.waiting: - return SliverToBoxAdapter( - child: Container( - child: Center(child: CircularProgressIndicator()), - padding: const EdgeInsets.all(30.0)), - ); - break; - case ConnectionState.active: - return SliverToBoxAdapter( - child: Center( - child: - Text("Error getting the cases, try again later.")), - ); - break; - case ConnectionState.done: - // print('DATA: ${snapshot.data}'); - if (snapshot.hasData) { - List _cases = List(); - print("Error here ${snapshot.data}"); - if (snapshot.data != null) - _cases = snapshot.data - .where((_) => _.locations - .where((location) => location.address - .toLowerCase() - .contains(_searchKey.toLowerCase())) - .isNotEmpty) - .toList(); - else - return SliverToBoxAdapter( - child: Padding( - padding: const EdgeInsets.all(30.0), - child: Center(child: Text("No cases found there.")), - ), - ); - if (_cases.length > 0) { - return SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return CaseItem(_cases[index]); - }, childCount: _cases.length), - ); - } else { - return SliverToBoxAdapter( - child: Padding( - padding: const EdgeInsets.all(30.0), - child: Center(child: Text("No cases found there.")), - ), - ); - } - } else { - return SliverToBoxAdapter( - child: Padding( - padding: const EdgeInsets.all(30.0), - child: Center(child: Text("No cases found.")), - ), - ); - } - break; - default: - return SliverToBoxAdapter( - child: Center(child: Text("")), - ); - } - }, - ), - ], - ), - ); - } -} +// Navigator.of(context).push(MaterialPageRoute( +// builder: (context) => ChangeNotifierProvider.value( +// value: model, +// child: UserRegisterScreen(), +// ), +// )); +// }, +// child: Row( +// mainAxisSize: MainAxisSize.min, +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Padding( +// padding: const EdgeInsets.all(8.0), +// child: Text( +// AppLocalizations.of(context) +// .translate("cse_list_screen_see-text") + +// "(${Provider.of(context).reportedCases.length})", +// textAlign: TextAlign.center, +// style: TextStyle( +// fontWeight: FontWeight.bold, +// color: Colors.white), +// ), +// ), +// Icon(Icons.keyboard_arrow_right, +// color: Colors.white), +// ], +// ), +// ), +// ], +// ))), +// ) +// : SliverToBoxAdapter( +// child: Container(), +// ), +// FutureBuilder>( +// future: _fetchCases(), +// builder: (BuildContext context, +// AsyncSnapshot> snapshot) { +// switch (snapshot.connectionState) { +// case ConnectionState.none: +// return SliverToBoxAdapter( +// child: Center( +// child: +// Text("Error getting the cases, try again later.")), +// ); +// break; +// case ConnectionState.waiting: +// return SliverToBoxAdapter( +// child: Container( +// child: Center(child: CircularProgressIndicator()), +// padding: const EdgeInsets.all(30.0)), +// ); +// break; +// case ConnectionState.active: +// return SliverToBoxAdapter( +// child: Center( +// child: +// Text("Error getting the cases, try again later.")), +// ); +// break; +// case ConnectionState.done: +// // print('DATA: ${snapshot.data}'); +// if (snapshot.hasData) { +// List _cases = List(); +// print("Error here ${snapshot.data}"); +// if (snapshot.data != null) +// _cases = snapshot.data +// .where((_) => _.locations +// .where((location) => location.address +// .toLowerCase() +// .contains(_searchKey.toLowerCase())) +// .isNotEmpty) +// .toList(); +// else +// return SliverToBoxAdapter( +// child: Padding( +// padding: const EdgeInsets.all(30.0), +// child: Center(child: Text("No cases found there.")), +// ), +// ); +// if (_cases.length > 0) { +// return SliverList( +// delegate: SliverChildBuilderDelegate( +// (BuildContext context, int index) { +// return CaseItem(_cases[index]); +// }, childCount: _cases.length), +// ); +// } else { +// return SliverToBoxAdapter( +// child: Padding( +// padding: const EdgeInsets.all(30.0), +// child: Center(child: Text("No cases found there.")), +// ), +// ); +// } +// } else { +// return SliverToBoxAdapter( +// child: Padding( +// padding: const EdgeInsets.all(30.0), +// child: Center(child: Text("No cases found.")), +// ), +// ); +// } +// break; +// default: +// return SliverToBoxAdapter( +// child: Center(child: Text("")), +// ); +// } +// }, +// ), +// ], +// ), +// ); +// } +// } diff --git a/lib/page/screen/dashboard_screen.dart b/lib/page/screen/dashboard_screen.dart index c55d45d..fa620bb 100644 --- a/lib/page/screen/dashboard_screen.dart +++ b/lib/page/screen/dashboard_screen.dart @@ -66,9 +66,9 @@ class _DashboardScreenState extends State } }); - _channel.invokeMethod('requestLocationPermission').then((res) { - _channel.invokeMethod('openLocationService').then((res) {}); - }); + // _channel.invokeMethod('requestLocationPermission').then((res) { + // _channel.invokeMethod('openLocationService').then((res) {}); + // }); } Future fetchArticles() async { diff --git a/lib/page/screen/qr_scan_screen.dart b/lib/page/screen/qr_scan_screen.dart index f60fd26..a2aea75 100644 --- a/lib/page/screen/qr_scan_screen.dart +++ b/lib/page/screen/qr_scan_screen.dart @@ -74,11 +74,16 @@ class _QrScanScreenState extends State { } void _onQRViewCreated(QRViewController controller) { + print("called"); this.controller = controller; controller.scannedDataStream.listen((scanData) { setState(() { qrText = scanData; - _handleURLButtonPress(context, qrText); + + if (qrText != "") { + controller.pauseCamera(); + _handleURLButtonPress(context, qrText); + } }); }); }