Skip to content

Commit

Permalink
minor location chip UI changes, error handling, and code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanics committed Nov 8, 2018
1 parent 9fc05f8 commit 458ffc4
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions lib/upload_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:image/image.dart' as Im;
import 'package:path_provider/path_provider.dart';
import 'dart:math' as Math;
import 'location.dart';
import 'package:geocoder/geocoder.dart';

class Uploader extends StatefulWidget {
_Uploader createState() => new _Uploader();
Expand All @@ -18,12 +19,7 @@ class Uploader extends StatefulWidget {
class _Uploader extends State<Uploader> {
File file;
//Strings required to save address
String featureName;
String subLocality;
String locality;
String subAdminArea;
String adminArea;
String country;
Address address;

Map<String, double> currentLocation = new Map();
TextEditingController descriptionController = new TextEditingController();
Expand All @@ -43,20 +39,15 @@ class _Uploader extends State<Uploader> {
//variables with location assigned as 0.0
currentLocation['latitude'] = 0.0;
currentLocation['longitude'] = 0.0;
initPlatformState();//method to call location
initPlatformState(); //method to call location
super.initState();
}

//method to get Location and save into variables
initPlatformState() async {
var first = await getUserLocation();
Address first = await getUserLocation();
setState(() {
featureName = first.featureName;
subLocality = first.subLocality;
locality = first.locality;
subAdminArea = first.subAdminArea;
adminArea = first.adminArea;
country = first.countryName;
address = first;
});
}

Expand Down Expand Up @@ -95,47 +86,57 @@ class _Uploader extends State<Uploader> {
locationController: locationController,
loading: uploading,
),
new Divider(),//scroll view where we will show location to users
new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
buildLocationButton(featureName),
buildLocationButton(subLocality),
buildLocationButton(locality),
buildLocationButton(subAdminArea),
buildLocationButton(adminArea),
buildLocationButton(country),
],
),
),
new Divider(), //scroll view where we will show location to users
(address == null)
? Container()
: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.only(right: 5.0, left: 5.0),
child: Row(
children: <Widget>[
buildLocationButton(address.featureName),
buildLocationButton(address.subLocality),
buildLocationButton(address.locality),
buildLocationButton(address.subAdminArea),
buildLocationButton(address.adminArea),
buildLocationButton(address.countryName),
],
),
),
(address == null) ? Container() : Divider(),
],
));
}

//method to build buttons with location.
buildLocationButton(String locationName) {
return InkWell(
onTap: () {
locationController.text = locationName;
},
child: new Container(
//width: 100.0,
height: 40.0,
decoration: new BoxDecoration(
color: Colors.grey[350],
border: new Border.all(color: Colors.white, width: 2.0),
borderRadius: new BorderRadius.circular(10.0),
),
padding: EdgeInsets.only(left: 5.0, right: 5.0),
child: new Center(
child: new Text(
locationName,
style: new TextStyle(color: Colors.black),
if (locationName != null ?? locationName.isNotEmpty) {
return InkWell(
onTap: () {
locationController.text = locationName;
},
child: Center(
child: new Container(
//width: 100.0,
height: 30.0,
padding: EdgeInsets.only(left: 8.0, right: 8.0),
margin: EdgeInsets.only(right: 3.0, left: 3.0),
decoration: new BoxDecoration(
color: Colors.grey[200],
borderRadius: new BorderRadius.circular(5.0),
),
child: new Center(
child: new Text(
locationName,
style: new TextStyle(color: Colors.grey),
),
),
),
),
),
);
);
} else {
return Container();
}
}

_selectImage() async {
Expand Down Expand Up @@ -180,7 +181,7 @@ class _Uploader extends State<Uploader> {
}

void compressImage() async {
print('startin');
print('starting compression');
final tempDir = await getTemporaryDirectory();
final path = tempDir.path;
int rand = new Math.Random().nextInt(10000);
Expand Down Expand Up @@ -211,7 +212,7 @@ class _Uploader extends State<Uploader> {
uploading = true;
});
compressImage();
Future<String> upload = uploadImage(file).then((String data) {
uploadImage(file).then((String data) {
postToFireStore(
mediaUrl: data,
description: descriptionController.text,
Expand Down

0 comments on commit 458ffc4

Please sign in to comment.