Please i need help with Dynamic column

Good morning all. Please help me with this problem.
I’m trying to dynamically create a widget list made up of GridView.count and ListView using a * _document * variable that I update as I go.
The said variable that I integrate has a Column.
Knowing that the GridView is generated dynamically also using the * _articlesWidget * function
Unfortunately the console gives me errors.

Sorry for the English. it’s google translate

  @override
  State<StatefulWidget> createState() {
    return _Home();
  }
}

class _Home extends State {
  ScrollController _controller;
  bool isLoading = false;
  List<Widget> _document = [];
  int count = 0;

  List<ArticlesModel> _items = [
    ArticlesModel(
        "T shirt",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eae9",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/310x430/01_00b39_zr582HgVsz3HuZKxfrJFcLFs.jpeg?1597154519-3384dfd6ddacce84dcbf545bdb585d9ab7d832e2")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Chemise",
        500,
        "M / 38 / 10 ",
        5,
        "#b2d8ea",
        MarquesModel("ABIBAS"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/f800/01_0034c_ZgGq2Jkcpp891KYktfKsbDoL.jpeg?1596567815-4e4a62caac67695412327bd809488438b013fe65")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Chaussures",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eace",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/f800/01_018dd_BnLCFXsaFGWLbK4u9XkLnVJA.jpeg?1597241077-bf3270e27e27770fa97461aff9b3eb5fc3b09f96")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Chapeaux",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eace",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/f800/01_0177c_AcSV4VuBa1YjVq83HTT2ByJR.jpeg?1597240975-300102100b8ba7f36360e49968efd2edbf07b65e")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Cravattes",
        500,
        "M / 38 / 10 ",
        5,
        "#ddb9a8",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/310x430/01_00b39_zr582HgVsz3HuZKxfrJFcLFs.jpeg?1597154519-3384dfd6ddacce84dcbf545bdb585d9ab7d832e2")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Lunettes",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eace",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/310x430/01_00b39_zr582HgVsz3HuZKxfrJFcLFs.jpeg?1597154519-3384dfd6ddacce84dcbf545bdb585d9ab7d832e2")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Blouson",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eace",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/f800/02b72_ubng8f5stCzmfvJFa4NNGtLT.jpeg?1569416037-29e0c347b65cf8bbd5c94286ff2877abc5a14f5f")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
    ArticlesModel(
        "Pantalon",
        500,
        "M / 38 / 10 ",
        5,
        "#c7eace",
        MarquesModel("NIKE"),
        [
          ImageModel(
              "https://images.vinted.net/thumbs/310x430/01_00b39_zr582HgVsz3HuZKxfrJFcLFs.jpeg?1597154519-3384dfd6ddacce84dcbf545bdb585d9ab7d832e2")
        ],
        Owner(
            "pegaSus",
            ImageModel(
                "https://i.pinimg.com/originals/af/7c/8e/af7c8ef9febf74dab108933130b9d48d.jpg"))),
  ];

  @override
  void initState() {
    _controller = ScrollController();
    _setDocument();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: Colors.white));

    final Widget gridWithScrollNotification =
        NotificationListener<ScrollNotification>(
            onNotification: _handleScrollNotification,
            child: Scrollbar(child: Expanded(child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: _document))));


    return MyScaffold(
        title: "",
        body: Scrollbar(
          child: Column(
        children: _document)),
        bottom: BottomNavigationBar(
            fixedColor: MyConstants().primaryColor,
            unselectedItemColor: Colors.grey[900],
            showUnselectedLabels: true,
            currentIndex: 0,
            // this will be set when a new tab is tapped
            items: [
              BottomNavigationBarItem(
                icon: new Icon(Icons.home),
                title: new Text('Accueil'),
              ),
              BottomNavigationBarItem(
                icon: new Icon(Icons.search),
                title: new Text('Chercher'),
              ),
              BottomNavigationBarItem(
                icon: new Icon(Icons.add_circle_outline),
                title: new Text('Vendre'),
              ),
              BottomNavigationBarItem(
                  icon: Icon(Icons.mail_outline), title: Text('Messages')),
              BottomNavigationBarItem(
                  icon: Icon(Icons.person), title: Text('Profil'))
            ]));
  }

  bool _handleScrollNotification(ScrollNotification notification) {
    if (notification is ScrollEndNotification) {
      if (_controller.position.extentAfter == 0) {
        _loadMore();
        setState(() {
          isLoading = true;
        });
      }
    }
    return false;
  }

  Future<Null> _handleRefresh() async {
    setState(() {
      _items = [];
      _loadMore();
    });
  }

  void _loadMore() {
    _setDocument();
  }

  void _setDocument() {
    setState(() {
      if (count == 0) {
        this._document.add(_articlesWidget());
      } else if (count == 1) {
        this._document.add(_showBoutique());
      } else if (count == 3) {
        this._document.add(_articlesWidget());
      } else if (count == 4) {
        this._document.add(_wantMore());
      }
    });
    count++;
  }

  Widget _showBoutique() {
    return    new GridView.count(
      primary: true,
      crossAxisCount: 2,
      children: <Widget>[
        new Image.asset('assets/images/meat.jpg')
      ],
    );
  }

  Widget _wantMore() {
    return    new GridView.count(
      primary: true,
      crossAxisCount: 2,
      children: <Widget>[
        new Image.asset('assets/images/meat.jpg')
      ],
    );
  }

  Widget _articlesWidget() {
    List<Widget> ele = [];
    _items.map((e) => ele.add(Article(e)));

    return new Expanded(
        child: GridView.count(
            shrinkWrap: true,
        childAspectRatio: 310 / (430 + 150),
        controller: _controller,
        padding: EdgeInsets.all(4.0),
        crossAxisCount: 2,
        children: ele));
  }
} ```


```  class Article extends Expanded {
  ArticlesModel _article;

  Article(this._article)
      : super(
    child: Container(
          color: Colors.white,
          padding: EdgeInsets.all(15),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                  padding: EdgeInsets.only(left: 20),
                  child: Row(
                    children: <Widget>[
                      CircleAvatar(
                          radius: 20,
                          backgroundColor: HexColor.fromHex(_article.color),
                          child: CircleAvatar(
                            radius: 20,
                            backgroundImage: NetworkImage(_article.owner.photo.path),
                          )),
                      Padding(padding: EdgeInsets.all(5)),
                      TextNormale(_article.owner.username, Colors.grey[400])
                    ],
                  )),
              MyConstants().space(15),
              Expanded(
                  child: Container(
                decoration:
                    BoxDecoration(color: HexColor.fromHex(_article.color)),
                child: FadeInImage(
                    image: NetworkImage(
                      _article.images[0].path,
                    ),
                    fit: BoxFit.cover,
                    placeholder: AssetImage('images/loading.png')),
              )),
              MyConstants().space(15),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  TextNormale("${_article.price} F CFA", Colors.black, 15,
                      FontWeight.w600),
                  InkWell(
                    child: Row(
                      children: <Widget>[
                        Icon(
                          Icons.thumb_up,
                          color: Colors.grey[300],
                        ),
                        Padding(padding: EdgeInsets.all(5)),
                        TextNormale("${_article.like}")
                      ],
                    ),
                  )
                ],
              ),
              TextNormale(_article.marque.name, Colors.grey, 15),
              TextNormale(_article.descr, Colors.grey, 15),
            ],
          ),
        ));
}

Hi Eric, no need to apologize that’s completely okay.

If you could post the error here that would really help us identify the problem!

Thank you for your concern. I just found this approach that solves my problem.

2 Likes