Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StaggeredGridView is undefined

import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; //import libray

flutter_staggered_grid_view: ^0.5.0 // package

    Flexible(
      child: Container(
        padding: EdgeInsets.only(top: 16.0, right: 16.0, left: 16.0),
        child: StaggeredGridView.countBuilder(
          physics: NeverScrollableScrollPhysics(),
          padding: EdgeInsets.zero,
          crossAxisCount: 4,
          itemCount: products.length,
          itemBuilder: (BuildContext context, int index) => new ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(5.0)),
            child: InkWell(
              onTap: () => Navigator.of(context).push(MaterialPageRoute(
                  builder: (_) => ProductPage(product: products[index]))),
              child: Container(
                  decoration: BoxDecoration(
                    gradient: RadialGradient(
                        colors: [
                          Colors.grey.withOpacity(0.3),
                          Colors.grey.withOpacity(0.7),
                        ],
                        center: Alignment(0, 0),
                        radius: 0.6,
                        focal: Alignment(0, 0),
                        focalRadius: 0.1),
                  ),
                  child: Hero(
                      tag: products[index].image,
                      child: Image.asset(products[index].image))),
            ),
          ),
          staggeredTileBuilder: (int index) =>
              StaggeredTile.count(2, index.isEven ? 3 : 2),
          mainAxisSpacing: 4.0,
          crossAxisSpacing: 4.0,
        ),
      ),
    ),

Error:

lib/screens/main/components/recommended_list.dart:51:20: Error: The getter 'StaggeredGridView' isn't defined for the class 'RecommendedList'.

  • 'RecommendedList' is from 'package:mobi_zilla/screens/main/components/recommended_list.dart' ('lib/screens/main/components/recommended_list.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'StaggeredGridView'. child: StaggeredGridView.countBuilder( ^^^^^^^^^^^^^^^^^ lib/screens/main/components/recommended_list.dart:79:19: Error: The getter 'StaggeredTile' isn't defined for the class 'RecommendedList'.
  • 'RecommendedList' is from 'package:mobi_zilla/screens/main/components/recommended_list.dart' ('lib/screens/main/components/recommended_list.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'StaggeredTile'. StaggeredTile.count(2, index.isEven ? 3 : 2), ^^^^^^^^^^^^^
like image 386
Saad Bin Zia Avatar asked Apr 14 '26 17:04

Saad Bin Zia


2 Answers

Use Version:

dependencies:
  flutter_staggered_grid_view: ^0.4.0
like image 103
Tasnuva Tavasum oshin Avatar answered Apr 16 '26 06:04

Tasnuva Tavasum oshin


The pub.dev documentation for the plugin doesn't suggest anything about the method being deprecated or scrapped in the latest version i.e flutter_staggered_grid_view 0.6.1. I tried using flutter_staggered_grid_view: ^0.4.0 but that didn't work either. The workaround seems to be to use version 0.3.1 which then recognized the StaggeredGridView method.

like image 37
coolhack7 Avatar answered Apr 16 '26 07:04

coolhack7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!