在ListView中添加GoogleMaps并填充整个空间



我需要在ListView中添加一个GoogleMap视图,并希望它在屏幕上获得完整的可用空间(没有滚动)

我该怎么做呢?

但总是收到关于无限高的错误):

这是我尝试过的:

Scaffold(
appBar: const CustomAppBar(),
body: NestedScrollView(
physics: const ClampingScrollPhysics()(),
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
floating: false,
pinned: true,
expandedHeight: 80,
collapsedHeight: 56,
backgroundColor: AppColors.black,
flexibleSpace: const FlexibleTitleAppBar(),
),
],
body: ListView(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
children: [
Container(
color: AppColors.black,
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 16, top: 28, bottom: 28),
child: HeaderComponent(),
)
),
Expanded(
flex: 1
child: GoogleMaps(
compassEnabled: false,
initialCameraPosition: cameraPosition,
gestureRecognizers: Set()
..add(
Factory<EagerGestureRecognizer>(
() => EagerGestureRecognizer(),
),
),
markers: markers,
);
),
],
),
),
);

也许你可以尝试用sizebox包装listview小部件。然后给出使用MediaQuery或只是静态数字的sizebox的高度-宽度值。

我已经修改了您的Scaffold变量,以便在我结束时运行。做一些必要的改变。这是解决方案。试试这个。我用Column代替了ListView。

PreferredSizeWidget customAppBar() {
return AppBar(
title: const Text('APPBAR TITLE HERE'),
centerTitle: true,
leading: const Icon(Icons.arrow_back_ios),
);
}
Widget flexibleTitleAppBar() {
return Container(
color: Colors.blue.shade900,
);
}
Widget headerComponent() {
return Container();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: customAppBar(),
body: NestedScrollView(
physics: const ClampingScrollPhysics(),
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
floating: false,
pinned: true,
expandedHeight: 80,
collapsedHeight: 56,
backgroundColor: Colors.black,
flexibleSpace: flexibleTitleAppBar(),
),
],
body: Column(
children: [
Container(
color: Colors.black,
child: Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 28, bottom: 28),
child: headerComponent(),
)),
Expanded(
flex: 1,
child: GoogleMap(
compassEnabled: false,
initialCameraPosition:
const CameraPosition(target: LatLng(0, 0)),
gestureRecognizers: Set()
..add(
Factory<EagerGestureRecognizer>(
() => EagerGestureRecognizer(),
),
),
markers: const <Marker>{},
)),
],
),
),
);