我有一个listview作为脚手架主体和listview的容器,每次滚动listview地图阅读时,我都有Gridview和Google。当我不在列表视图中使用Gridview时,它工作正常,或者我在上面添加了Google地图 Gridview工作正常,但是当我在GridView下面添加地图时,每次滚动时都会重新加载。
我尝试仅在调用Build方法时一次初始化Google地图,但无法正常工作
Dart代码
在状态类中
bool isMapLoaded = false;
if (!isMapLoaded) {
isMapLoaded = true;
googleMap = GoogleMap(
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
..add(Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()))
..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer()))
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())),
mapType: MapType.normal,
zoomGesturesEnabled: true,
markers: Set<Marker>.of(markers.values),
minMaxZoomPreference: MinMaxZoomPreference.unbounded,
initialCameraPosition: _initialCamera,
onMapCreated: (GoogleMapController googleMapController) {
print("Map Created");
_mapController = googleMapController;
_gController.complete(googleMapController);
},
);
isMapLoading = true;
}
Logcat中没有显示错误
我的带有Gridview实现的Listview在这里
//其他控件,例如文本和编辑文本
final itemGridDelegate = new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
crossAxisCount: 2,
childAspectRatio: 5.0);
final propertyTypeGridview = new Container(
child: new Container(
padding: EdgeInsets.only(top: 20.0),
color: Colors.white,
child: GridView.builder(
physics: ClampingScrollPhysics(),
gridDelegate: itemGridDelegate,
shrinkWrap: true,
itemCount: propertyTypeList.length,
itemBuilder: (BuildContext context, int index) {
return _buildPropertyTypeItems(index, context);
},
),
),
);
googleMap = GoogleMap(
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
..add(Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()))
..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer()))
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())),
mapType: MapType.normal,
zoomGesturesEnabled: true,
markers: Set<Marker>.of(markers.values),
minMaxZoomPreference: MinMaxZoomPreference.unbounded,
initialCameraPosition: _initialCamera,
onMapCreated: (GoogleMapController googleMapController) {
print("Map Created");
_mapController = googleMapController;
_gController.complete(googleMapController);
},
);
final mapView = new Container(
height: 200,
width: double.infinity,
margin: EdgeInsets.only(top: 20.0),
child: new ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: googleMap));
// final listview
[![propertyTypeGridview and property featuresGridview are both Gridview
final mainListview = new ListView(
padding: EdgeInsets.all(15.0),
children: <Widget>\[
tvAddImage,
propertyThumbnailList,
tvPropertyAddress,
edPropertyAddress,
tvSuberb,
edPropertySuberb,
tvState,
edState,
tvPostcode,
edPropertyPostcode,
tvSalesPrice,
edPropertySalesPrice,
tvRentalPrice,edTRental,
tvPropertyInfo,
edPropertyInfo,
tvSelect,
propertyTypeGridview,
tvPropertyFeatures,
propertyFeaturesGrid,
mapView,
\],
);
final scaffold = new Scaffold(
body: mainListview,
);][1]][1]
我尝试了以下更改,效果很好。
final mainListview = new ListView(
padding: EdgeInsets.all(15.0),
children: <Widget>[
tvAddImage,
propertyThumbnailList,
tvPropertyAddress,
edPropertyAddress,
tvSuberb,
edPropertySuberb,
tvState,
edState,
tvPostcode,
edPropertyPostcode,
tvSalesPrice,
edPropertySalesPrice,
tvRentalPrice,edTRental,
tvPropertyInfo,
edPropertyInfo,
mapView,
tvSelect,
propertyTypeGridview,
tvPropertyFeatures,
propertyFeaturesGrid,
],
);
但是如果我按照以下提示进行操作将无法正常工作
final mainListview = new ListView(
padding: EdgeInsets.all(15.0),
children: <Widget>[
tvAddImage,
propertyThumbnailList,
tvPropertyAddress,
edPropertyAddress,
tvSuberb,
edPropertySuberb,
tvState,
edState,
tvPostcode,
edPropertyPostcode,
tvSalesPrice,
edPropertySalesPrice,
tvRentalPrice,edTRental,
tvPropertyInfo,
edPropertyInfo,
tvSelect,
propertyTypeGridview,
tvPropertyFeatures,
propertyFeaturesGrid,
mapView,],
);
and I want this screen