skip to Main Content

I need to add a GoogleMap view inside a ListView and want it to get the full available space on screen (without scroll)

How can I do that ?

But always receive the error about infinity height ):

This is what I tried:

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,
                          );
                   ),
                  ],
                ),
            ),
         );

2

Answers


  1. Maybe you can try wrap the listview widget with SizedBox. And then give the
    SizedBox’s height-width value using MediaQuery or just static number.

    Login or Signup to reply.
  2. I have modified your Scaffold variables to run at my end. Make the necessary changes your end. Here’s the solution. Try with this. I have replaced ListView with Column.

     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>{},
                    )),
              ],
            ),
          ),
        );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search