@@ -29,6 +29,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
2929 var selectedLocationID;
3030 var selectedLocationQuantity;
3131 var selectedLocationMarkerId;
32+ String selectedLocationName;
3233
3334 bool loginStatus;
3435
@@ -75,6 +76,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
7576 setState (() {
7677 selectedLocationID = null ;
7778 selectedLocationQuantity = null ;
79+ selectedLocationName = null ;
7880 });
7981 },
8082 ):
@@ -85,7 +87,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
8587 Padding (
8688 padding: const EdgeInsets .all (20.0 ),
8789 child: Align (
88- alignment: Alignment .bottomRight ,
90+ alignment: Alignment .bottomCenter ,
8991 child: FloatingActionButton .extended (
9092 onPressed: () {
9193 if (loginStatus && email!= null ){
@@ -111,14 +113,18 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
111113 ),
112114 ),
113115 (selectedLocationID != null && loginStatus) ? Padding (
114- padding: const EdgeInsets .all ( 20.0 ),
116+ padding: const EdgeInsets .fromLTRB ( 0 , 0 , 0 , 80 ),
115117 child: Align (
116- alignment: Alignment .bottomLeft ,
118+ alignment: Alignment .bottomCenter ,
117119 child: FloatingActionButton .extended (
118120 onPressed: () {
119- _showQuantityModal (context,selectedLocationID,selectedLocationQuantity,selectedLocationMarkerId);
121+ if (email == adminEmail){
122+ _showQuantityModal (context,selectedLocationID,selectedLocationQuantity,selectedLocationName,selectedLocationMarkerId);
123+ }else {
124+ _showDialog ("Admin Permission needed" );
125+ }
120126 },
121- label: Text ('Update: $selectedLocationQuantity ' ),
127+ label: Text ('Update: $selectedLocationName ' ),
122128 icon: Icon (Icons .edit),
123129 backgroundColor: Colors .yellow[800 ],
124130 ),
@@ -149,8 +155,9 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
149155 _lastMapPosition = position.target;
150156 }
151157 // ------------------- View Functions ------------------------
152- void _addMarker (orgName,quantity,dataType,location,Timestamp timestamp,[documentID]) {
158+ void _addMarker (orgName,quantity,String locationName, dataType,location,Timestamp timestamp,[documentID]) {
153159 quantity= quantity.toString ();
160+ locationName= locationName.toString ();
154161 var date = timestamp.toDate ();
155162 var dateString = date.toString ();
156163 if (location == null ){
@@ -163,14 +170,15 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
163170 markerId: MarkerId (location.toString ()),
164171 position: location,
165172 infoWindow: InfoWindow (
166- title: 'Data Source: $orgName , Entry: $dataType ' ,
173+ title: 'Location: $ locationName Data Source: $orgName , Entry: $dataType ' ,
167174 snippet: ' Number of infected: $quantity ,Date: $dateString ' ,
168175 ),
169176 icon: BitmapDescriptor .defaultMarkerWithHue (20 ),
170177 onTap: (){
171178 setState (() {
172179 selectedLocationID = documentID;
173180 selectedLocationQuantity = quantity;
181+ selectedLocationName = locationName;
174182 selectedLocationMarkerId = location;
175183 });
176184
@@ -204,19 +212,53 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
204212 });
205213
206214 }
207- _showQuantityModal (context,[updateLocationID,updateLocationQuantity,updateLocationMarkerId] ){
215+ _showQuantityModal (context,[updateLocationID,updateLocationQuantity,String updateLocationName, updateLocationMarkerId] ){
208216 final _formKey = GlobalKey <FormState >();
209217 int _quantity;
210- showModalBottomSheet (context: context,
218+ String _locationName;
219+ if (updateLocationID != null ){
220+ _quantity= int .parse (updateLocationQuantity);
221+ _locationName= updateLocationName;
222+ }
223+ showModalBottomSheet (context: context,
224+ isScrollControlled: true ,
211225 builder: (context)=> Container (
212226 color: Colors .red[50 ],
213- height: 180 ,
227+ height: 380 ,
214228 child: Stack (
215229 children: < Widget > [
216230 Form (
217231 key: _formKey,
218232 child: Column (
219233 children: < Widget > [
234+ Padding (
235+ padding: const EdgeInsets .all (10.0 ),
236+ child: Align (
237+ alignment: Alignment .topCenter,
238+ child: TextFormField (
239+ initialValue: updateLocationName,
240+ decoration: const InputDecoration (
241+ hintText: 'Enter new Location Name' ,
242+ icon: Icon (Icons .add_location),
243+ ),
244+ keyboardType: TextInputType .text,
245+ inputFormatters: < TextInputFormatter > [
246+ ],
247+ validator: (value) {
248+ if (value.isEmpty) {
249+ return 'Please enter name for this location' ;
250+ }
251+ return null ;
252+ },
253+ onChanged: (value){
254+ setState (() {
255+ // _quantity = int.parse(updateLocationQuantity);
256+ _locationName = value;
257+ });
258+ },
259+ ),
260+ ),
261+ ),
220262 Padding (
221263 padding: const EdgeInsets .all (10.0 ),
222264 child: Align (
@@ -240,13 +282,14 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
240282 onChanged: (value){
241283 setState (() {
242284 _quantity = int .parse (value);
285+ // _locationName = updateLocationName;
243286 });
244287 },
245288 ),
246289 ),
247290 ),
248291 Padding (
249- padding: const EdgeInsets .symmetric (vertical: 25 .0 ,horizontal: 140.0 ),
292+ padding: const EdgeInsets .symmetric (vertical: 55 .0 ,horizontal: 140.0 ),
250293 child: Align (
251294 alignment: Alignment .center,
252295 child: RaisedButton .icon (
@@ -265,20 +308,21 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
265308 if (_formKey.currentState.validate ()) {
266309 // Process data.
267310 if (updateLocationID == null ){
268- createInfectedRecord ("IEDCR" ,_quantity,"manual" );
269- _addMarker ("IEDCR" ,_quantity,"manual" ,null ,Timestamp .now ());
311+ createInfectedRecord ("IEDCR" ,_quantity,_locationName, "manual" );
312+ _addMarker ("IEDCR" ,_quantity,_locationName, "manual" ,null ,Timestamp .now ());
270313 _addHeatmap (_quantity,null );
271314 }else {
272315 print ("record updated" );
273- updateInfectedRecord (updateLocationID,_quantity);
316+ updateInfectedRecord (updateLocationID,_quantity,_locationName );
274317 setState (() {
275318 selectedLocationQuantity = null ;
319+ selectedLocationName = null ;
276320 selectedLocationID = null ;
277321 _markers.removeWhere ((m) {
278322 return m.markerId.value == updateLocationMarkerId.toString ();
279323 });
280324 });
281- _addMarker ("IEDCR" ,_quantity,"manual" ,null ,Timestamp .now ());
325+ _addMarker ("IEDCR" ,_quantity,_locationName, "manual" ,null ,Timestamp .now ());
282326 }
283327 Navigator .pop (context);
284328 }
@@ -332,24 +376,28 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
332376 });
333377 }
334378 // reference https://medium.com/@atul.sharma_94062/how-to-use-cloud-firestore-with-flutter-e6f9e8821b27
335- void createInfectedRecord (name,quantity,dataType) async {
379+ void createInfectedRecord (name,quantity,locationName, dataType) async {
336380 Timestamp time = Timestamp .now ();
337381 CollectionReference reliefCollection = databaseReference.collection ("infected" );
338382 await reliefCollection.document ().setData ({
339383 'name' : name,
340384 'quantity' : quantity,
385+ 'location_name' : locationName,
341386 'location' : GeoPoint (_lastMapPosition.latitude,_lastMapPosition.longitude),
342387 'data_type' : dataType,
343388 'time' : time,
344389 'submitted_by' : email
345390 });
346391 }
347- void updateInfectedRecord (documentId,quantity) {
392+ void updateInfectedRecord (documentId,quantity,locationName ) {
348393 try {
349394 databaseReference
350395 .collection ('infected' )
351396 .document ('$documentId ' )
352- .updateData ({'quantity' : quantity});
397+ .updateData ({
398+ 'quantity' : quantity,
399+ 'location_name' : locationName,
400+ });
353401 } catch (e) {
354402 print (e.toString ());
355403 }
@@ -364,7 +412,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
364412 // Ref https://fireship.io/lessons/flutter-realtime-geolocation-firebase/
365413 GeoPoint pos = f.data['location' ];
366414 LatLng latLng = new LatLng (pos.latitude, pos.longitude);
367- _addMarker (f.data['name' ],f.data['quantity' ],f.data['data_type' ],latLng,f.data['time' ],f.documentID);
415+ _addMarker (f.data['name' ],f.data['quantity' ],f.data['location_name' ],f.data[ ' data_type' ],latLng,f.data['time' ],f.documentID);
368416 _addHeatmap (f.data['quantity' ],latLng);
369417
370418 });
0 commit comments