Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter: Make all screen scrollable with GridView.builder inside

In my home screen my app shows carousel first then a vertical list of challenges cards retrieved from Cloud Firestore using GridView.builder as follows:

GridView.builder(
        scrollDirection: Axis.vertical,
        itemCount: _challenges.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 1,
          childAspectRatio: MediaQuery.of(context).size.width /
              (MediaQuery.of(context).size.height / 4),
        ),
        itemBuilder: (context, index) {
          return InkWell(
            onTap: () {
              if (_challenges[index]["isLocked"] == "true") {
                showLockedDialog();
              } else {
                checkParticipation(index);
                if (checkPart == true) {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (_) =>
                              ChallengeDetails(_challenges[index])));
                }
                checkPart = true;
              }
            },
            child: Stack(
              children: [
                Center(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(15),
                    child: Image(
                      image: NetworkImage(_challenges[index]["image-path"]),
                      fit: BoxFit.cover,
                      height: 150,
                      width: 350,
                      opacity: _challenges[index]["isLocked"] == "true"
                          ? AlwaysStoppedAnimation(.4)
                          : null,
                    ),
                  ),
                ),
                Center(
                  child: Text(
                    "${_challenges[index]["name"]}\n",
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.bold),
                  ),
                ),
                Center(
                    child: Text(
                  "\n${_challenges[index]["date"]}",
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                      fontWeight: FontWeight.bold),
                  textDirection: TextDirection.ltr,
                )),
                Center(
                  child: SizedBox(
                    height: 130,
                    width: 130,
                    child: _challenges[index]["isLocked"] == "true"
                        ? Image.asset("assets/lock-icon.jpg")
                        : null,
                  ),
                )
              ],
            ),
          );
        });

Everything retrieving fine and it is rendered in my home_screen as follows:

body: Column(
            children: [
              AdsBanner(),
              SizedBox(
                height: 30,
              ),
              Padding(
                padding: const EdgeInsets.only(right: 8, left: 8, bottom: 5),
                child: Row(
                  children: [
                    Text(
                      AppLocalizations.of(context)!.challenges + " ",
                      style: TextStyle(fontSize: 20),
                    ),
                    Text(
                      AppLocalizations.of(context)!.clickToParticipate,
                      style: TextStyle(fontSize: 15),
                    )
                  ],
                ),
              ),
              Expanded(child: ChallengeCard()),
            ],
          ),

The problem is that only the GridView area is scrolling and what am seeking for is to scroll the whole screen with the GridView area, I was trying to use the CustomScrollView() but its not working properly.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ll be thankful for any help.

>Solution :

First in your GridView.builder add these:

GridView.builder(
   physics: NeverScrollableScrollPhysics(),
   shrinkWrap: true,
   ...
)

then in your home_screen wrap your column with SingleChildScrollView:

SingleChildScrollView(
  child: Column(
            children: [
              AdsBanner(),
              SizedBox(
                height: 30,
              ),
              Padding(
      ...
  ),
),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading