0
votes

I'm new with Flutter and I got stuck building a layout with ListView.

The top section is working nice, with horizontal scroll. But I want, a GridView below that scroll with all the whole page, not individually. It only works if I scroll on the edges.

Someone can help me, please? Here is the code.

This is the widget that I'm in trouble

import 'package:flutter/material.dart';
import 'package:ubaia/components/titulo.dart';

class Categorias extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Titulo(title: "Categorias"),
        ),
        GridView.count(
          shrinkWrap: true,
          crossAxisCount: 2,
          scrollDirection: Axis.vertical,
          children: List.generate(8, (index) {
            return Center(
              child: Container(
                height: 130,
                width: 130,
                color: Colors.brown,
              ),
            );
          }),
        )
      ],
    );
  }
}

This is the page that i'm landing the widget

//Homepage

import 'package:flutter/material.dart';
import 'package:ubaia/components/comprados_rencentemente.dart';
import 'package:ubaia/components/categorias.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          actions: <Widget>[
            Padding(
              padding: const EdgeInsets.only(right: 16.0),
              child: Icon(Icons.person),
            ),
          ],
        ),
        body: Container(
          child: ListView(
            padding: EdgeInsets.all(16.0),
            children: <Widget>[
              CompradosRecentemente(), //This is the widget that works nice
              Categorias(),
            ],
          ),
        ),
        bottomSheet: Container(
          height: 50,
          color: Colors.brown,
          child: Center(
              child: Text(
            "Minha Cesta",
            style: TextStyle(color: Colors.white),
          )),
        ));
  }
}
1

1 Answers

0
votes

In your Code - add - physics: ClampingScrollPhysics() in GridView.count

GridView.count(
          shrinkWrap: true,
          crossAxisCount: 2,
          physics: ClampingScrollPhysics(), // Add this line