我有一个基于Google Map的flutter应用程序,该应用程序中有一个位置的底部列表,还有一个标记,用于显示地图中的位置,当我单击该标记时,直接显示特定的列表项,并用老虎钳反之亦然,这也意味着当您单击列表项时,会向我显示与此位置相关的标记。
一切正常,但是当我使用导航器转到该页面的地图时,向我显示此错误:
注意:我想知道在此屏幕中午餐我的应用程序并使用导航器转到它之间有什么区别,因为在第一种情况下,它是可行的,并且在导航器中显示了此问题 widget由小部件库捕获的异常═════════════════════════════════════ ══════════════════ 构建AnimatedBuilder时引发以下断言(动画:PageController#8776c(2个客户端),脏状态:_AnimatedState#3f7db): ScrollController附加到多个滚动视图。 'package:flutter / src / widgets / scroll_controller.dart': 断言失败:第113行pos 12:'_ positions.length == 1'
The relevant error-causing widget was:
AnimatedBuilder file:///H:/mafqood/lib/ui/widgets/places_bottom_list_widget.dart:79:12
When the exception was thrown, this was the stack:
#2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:113:12)
#3 PlacesListState.tile.<anonymous closure> (package:mafqood/ui/widgets/places_bottom_list_widget.dart:83:28)
#4 AnimatedBuilder.build (package:flutter/src/widgets/transitions.dart:1443:19)
#5 _AnimatedState.build (package:flutter/src/widgets/transitions.dart:181:48)
#6 StatefulElement.build (package:flutter/src/widgets/framework.dart:4744:28)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ (2) Exception caught by widgets library ═══════════════════════════════════════════════════
ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 113 pos 12: '_positions.length == 1'
The relevant error-causing widget was:
AnimatedBuilder file:///H:/mafqood/lib/ui/widgets/places_bottom_list_widget.dart:79:12
════════════════════════════════════════════════════════════════════════════════════════════════════
id在名为(config.dart)的单独文件中定义PageControler:
PageController pageController;
,然后在另一个文件中使用它:
class PlacesListState extends State<PlacesList> {
GetPlacesBloc getPlacesBloc;
double offset = 0.0 ;
@override
void initState() {
pageController = PageController(initialPage: 1, viewportFraction: 0.8)..addListener(() {
setState(() {
offset = PageController().offset;
});
});
getPlacesBloc = BlocProvider.of<GetPlacesBloc>(context);
super.initState();
}
@override
void dispose() {
getPlacesBloc.close();
pageController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Positioned(
bottom: 36.0,
child: Container(
height: 150.0,
width: MediaQuery.of(context).size.width,
child: BlocBuilder<GetPlacesBloc, GetPlacesStates>(
builder: (context, state) {
if (state is GetPlacesLoadingState) {
return LoadingIndicator(
message: state.message,
);
} else if (state is GetPlacesSuccessState) {
return PageView.builder(
controller: pageController,
itemCount: state != null ? state.places.length : 0,
itemBuilder: (BuildContext context, int index) {
return tile(context, state.places[index], index);
},
);
} else if (state is GetPlacesErrorState) {
return Text(state.message);
} else {
return Container(
width: 0,
height: 0,
);
}
},
)),
);
}
tile(BuildContext context, PlaceModel place, int index) {
return AnimatedBuilder(
animation: pageController,
builder: (BuildContext context, Widget widget) {
double value = 1;
if (pageController.position.haveDimensions) {
value = pageController.page - index;
value = (1 - (value.abs() * 0.3) + 0.06).clamp(0.0, 1.0);
}
,其中带有标记:
void tileScrollTo(int i) {
pageController.animateToPage(
i,
duration: Duration(seconds: 1),
curve: Curves.easeInOutCubic,
);
}
/////////////
getAllMarkers(List<PlaceModel> places) {
for(int i =0; i < places.length; i++) {
markers.add(
Marker(
markerId: MarkerId('${places[i].pid}'),
position: LatLng(double.parse(places[i].lat), double.parse(places[i].lon)),
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure),
infoWindow: InfoWindow(title: '${places[i].title}', snippet: '${places[i].details}'),
onTap: () => tileScrollTo(i),
),
);
}
}