letsar / flutter_staggered_grid_view

A Flutter staggered grid view

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: The getter 'getterName' isn't defined for the class '_MainClass'.

esdan7 opened this issue · comments

commented

Hi,

There seems to be an issue with passing an additional instance like the viewModel below to a Material class, this is the error I get:

Error: The getter 'viewModel' isn't defined for the class '_MainPageState'.

Material Items(IconData icon, String heading, Color cColor) {
    return Material(
        child: InkWell(
          onTap: () {
            if (heading ==
                ('Text')) {
                  showMainDialog(context, viewModel); <- The error
            } else if (heading ==         ^^^^^^^^^
                ('Text1')) {
                  showMainDialog(context, viewModel); <- The error
            }                             ^^^^^^^^^
          },
          child: Center(
            child: Container(
              child:
                  Column(
                    children: <Widget>[
                      Expanded(
                        child: Container(
                          child: Icon(
                            icon,
                            color: cColor,
                          ),
                        ),
                      ),
                      Expanded(    
                        child: Padding(
                          padding: EdgeInsets.only(top:10),
                          child: Text(
                            heading,
                            softWrap: true,
                          ),
                        ),
                      )
                    ],
                  )
            ),
          ),
        ));
  }

  Widget loadMainPage(ViewModel viewModel) {
    return StaggeredGridView.count(
        shrinkWrap: true,
        crossAxisCount: 2,
        crossAxisSpacing: 12.0,
        mainAxisSpacing: 12.0,
        children: <Widget>[
          Items(
              Icons.add,
              ('Text'),
              Colors.green),
          Items(
              Icons.add,
              ('Text1'),
              Colors.red),
        ],
        staggeredTiles: [
          StaggeredTile.extent(1, 150.0),
          StaggeredTile.extent(1, 150.0),
        ],
      );
  }
commented

Finally solved by doing this:

Material Items(IconData icon, String heading, Color cColor, ViewModel viewModel) {
return Material(