当我从谷歌地图位置自动完成中选择一个地方时,建议列表不会消失,请查看我的代码并在其中建议一些编辑
class FormDetail2 extends StatefulWidget {
const FormDetail2(
{Key? key, required this.onNext2, required this.onPrevious1})
: super(key: key);
final VoidCallback onNext2;
final VoidCallback onPrevious1;
@override
State<FormDetail2> createState() => _FormDetail2State();
}
class _FormDetail2State extends State<FormDetail2> {
final citySearch = TextEditingController();
final areaSearch = TextEditingController();
late FocusNode cityFocus;
late FocusNode areaFocus;
@override
void initState() {
cityFocus = FocusNode();
areaFocus = FocusNode();
super.initState();
}
@override
void dispose() {
super.dispose();
cityFocus.dispose();
areaFocus.dispose();
}
@override
Widget build(BuildContext context) {
final applicationBloc = Provider.of<ApplicationBloc>(context);
final name = Provider.of<FlatDetail1>(context);
print(name.id1);
return Scaffold(
body: (applicationBloc.currentLocation == null)
? Center(
child: CircularProgressIndicator(),
)
: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: TextField(
controller: citySearch,
autofocus: false,
focusNode: cityFocus,
decoration: InputDecoration(
hintText: 'Enter Location',
suffixIcon: Icon(Icons.search),
),
onChanged: (value) =>
applicationBloc.searchPlacesCity(value),
),
),
Stack(children :[
if (applicationBloc.searchResultsCity != null &&
applicationBloc.searchResultsCity!.isNotEmpty
)
Container(
height: 300,
child: ListView.builder(
itemCount:
applicationBloc.searchResultsCity?.length,
itemBuilder: ((context, index) {
return ListTile(
title: Text(
applicationBloc
.searchResultsCity![index].description
.toString(),
style: TextStyle(
color: Colors.black,
),
),
onTap: () async {
List<Location> locations =
await locationFromAddress(
applicationBloc
.searchResultsCity![index].description
.toString(),
);
final lat = locations.last.latitude;
final cityTapped = applicationBloc
.searchResultsCity![index].description
.toString();
setState(() {
citySearch.text = cityTapped;
applicationBloc.searchResultsCity =[];
});
},
);
}),
),
),
],
),[
请建议我对代码进行任何编辑以解决此问题,谢谢。我附上了代码截图输出