import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:muaawana/config/provider.dart'; import '../../../config/size.dart'; import '../../../providers/map_provider.dart'; class SearchResults extends StatefulWidget { final int? count; const SearchResults({Key? key, this.count}) : super(key: key); @override State createState() => _SearchResultsState(); } class _SearchResultsState extends State { bool chosen = false; @override Widget build(BuildContext context) { final tm = SizeConfig.textMultiplier; final hm = SizeConfig.heightMultiplier; final wm = SizeConfig.widthMultiplier; return ListView.builder( padding: EdgeInsetsDirectional.only(start: wm * 4, end: wm * 4, top: hm * 5), physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, itemCount: context.watch().places.isNotEmpty ? context.watch().places.length : 0, itemBuilder: (context, i) { return context.watch().places[i].description != null ? //Text("${context.watch().places[i].address.district!=null ?context.watch().places[i].address.district+" , ":""+context.watch().places[i].address.street!=null?context.watch().places[i].address.street+" , ":""+context.watch().places[i].address.city!=null?context.watch().places[i].address.city+" , ":""+context.watch().places[i].address.countryName!=null?context.watch().places[i].address.countryName:""}"): GestureDetector( child: SizedBox( child: Padding( padding: const EdgeInsets.all(8.0), child: Text( context .watch() .places[i] .description != null ? context .watch() .places[i] .description! : "", textAlign: TextAlign.start, style: TextStyle( height: 1.2, color: Colors.black, fontSize: tm * 1.7, fontFamily: 'medium', ), ), ), ), onTap: () async { if (chosen == false) { if (context.read().places[i].placeId != null) { setState(() { chosen = true; }); final position = await context .read() .getPlaceById(context .read() .places[i] .placeId!); if (position != null && position.location != null && position.location!.lat != null && position.location!.lng != null) { LatLng pos = LatLng( position.location!.lat!, position.location!.lng!); await context .read() .getAddressFromCoordinates( context, pos, widget.count); setState(() { chosen = false; }); context.read().onCameraMove(pos); context.read().disposePlaces(); FocusScope.of(context).unfocus(); Navigator.pop(context); } else { setState(() { chosen = false; }); Navigator.pop(context); // popup(context,"Ok",title: "Something went wrong",description:"This data is invalid please try again"); } } else { Navigator.pop(context); setState(() { chosen = false; }); // popup(context,"Ok",title: "Something went wrong",description:"This data is invalid please try again"); } } }, ) : const SizedBox(); }); } }