import 'package:flutter/material.dart';
import 'package:location/location.dart';
import '../helpers/location_helper.dart';
class LocationInput extends StatefulWidget {
final double latitude;
final double longitude;
LocationInput({
required this.latitude,
required this.longitude
});
_LocationInputState createState() => _LocationInputState();
}
class _LocationInputState extends State<LocationInput> {
double? lat;
double? lng;
String _previewUrl = '';
void initState() {
lat = widget.latitude;
lng = widget.longitude;
final staticMapImgUrl = LocationHelper.generateLocationPreview(latitude: lat!, longitude: lng!);
setState(() {
_previewUrl = staticMapImgUrl;
});
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
height: 170,
width: double.infinity,
alignment: Alignment.center,
child: _previewUrl == ''
? const Text (
'No location found',
textAlign: TextAlign.center,
)
: Image.network(
_previewUrl,
fit: BoxFit.cover,
width: double.infinity
),
),
]
);
}
}