Skip to content

Commit 60fa649

Browse files
committed
fix errors 4
1 parent e10b766 commit 60fa649

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

lib/screens/preciesly_usa_forest_fire_risk.dart

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,36 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
3737
bool _orbiting = false;
3838
bool _searched = false;
3939

40+
bool isDropdownVisible=false;
41+
4042
LGService get _lgService => GetIt.I<LGService>();
4143

4244
PreciselyService get _preciselyService => GetIt.I<PreciselyService>();
4345
final _addressController = TextEditingController();
46+
FocusNode _focusNodeAddress = FocusNode(); // Adding a FocusNode to manage focus
47+
4448
var uuid = const Uuid();
4549

4650
final String googleApiKey = dotenv.get('GOOGLE_MAPS_APY_KEY');
4751

4852
GoogleMapController? mapController;
4953
LatLng? pickedLocation = const LatLng(37.7749, -122.4194);
5054

51-
TextEditingController controller = TextEditingController();
55+
//TextEditingController controller = TextEditingController();
5256

5357

5458
@override
5559
void initState() {
5660
super.initState();
5761
}
5862

63+
@override
64+
void dispose() {
65+
_addressController.dispose();
66+
_focusNodeAddress.dispose(); // Dispose of the FocusNode when the widget is destroyed
67+
super.dispose();
68+
}
69+
5970

6071
@override
6172
Widget build(BuildContext context) {
@@ -85,7 +96,9 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
8596
children: [
8697
Expanded(
8798
// todo: fer que al seleccionar del mapa es fiqui l'adreça.
88-
child: GooglePlaceAutoCompleteTextField(
99+
child: Visibility(
100+
visible: !isDropdownVisible,
101+
child: GooglePlaceAutoCompleteTextField(
89102
textEditingController: _addressController,
90103
googleAPIKey: googleApiKey,
91104
inputDecoration: const InputDecoration(
@@ -142,7 +155,8 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
142155
);
143156
},
144157
isCrossBtnShown: true,
145-
),
158+
focusNode: _focusNodeAddress,
159+
),),
146160
/*TextFormField(
147161
controller: _addressController,
148162
decoration: const InputDecoration(
@@ -451,6 +465,16 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
451465
loc.Location location = loc.Location();
452466
bool _serviceEnabled;
453467

468+
//FocusScope.of(context).requestFocus(new FocusNode());
469+
// google predictor text input close dropdown
470+
471+
setState(() {
472+
//_addressController.clear(); // Clear the text field
473+
//_focusNodeAddress.unfocus(); // Unfocus to hide the dropdown
474+
isDropdownVisible = true;
475+
});
476+
477+
454478
_serviceEnabled = await location.serviceEnabled();
455479
if (!_serviceEnabled) {
456480
_serviceEnabled = await location.requestService();
@@ -491,6 +515,7 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
491515
},
492516
onTap: (LatLng location) {
493517
setState(() {
518+
isDropdownVisible = false;
494519
pickedLocation = location;
495520
_addressController.text =
496521
'${location.latitude}, ${location.latitude}';
@@ -501,7 +526,12 @@ class _PreciselyUsaForestFireRisk extends State<PreciselyUsaForestFireRisk> {
501526
),
502527
),
503528
),
504-
);
529+
).then((_) {
530+
// This block of code runs after the dialog is dismissed
531+
setState(() {
532+
isDropdownVisible = false;
533+
});
534+
});
505535
}
506536

507537
Widget _buildGoogleMap() {

0 commit comments

Comments
 (0)