flutterontap

Flutter: Adding inkwell to my gridlist in order to use ontap () is throwing errors


Code is fine until I try and add inkwell()

''' return Scaffold( appBar: AppBar( title: const Text("App Dev and QA process"), centerTitle: true, systemOverlayStyle: SystemUiOverlayStyle.dark), body: AnimationLimiter(

    child: GridView.count(
      physics: const BouncingScrollPhysics(
          parent: AlwaysScrollableScrollPhysics()),
      padding: EdgeInsets.all(_w / 60),
      crossAxisCount: columnCount,

      children: List.generate(
        8,
        (int index) {

InkWell( return AnimationConfiguration.staggeredGrid( position: index, duration: const Duration(milliseconds: 500), columnCount: columnCount, child: ScaleAnimation( duration: const Duration(milliseconds: 900), curve: Curves.fastLinearToSlowEaseIn, child: FadeInAnimation(

                child: Container(
                  margin: EdgeInsets.only(
                      bottom: _w / 30, left: _w / 60, right: _w / 60),
                  decoration: BoxDecoration(
                    color: Colors.blueGrey,
                    borderRadius:
                        const BorderRadius.all(Radius.circular(20)),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.1),
                        blurRadius: 40,
                        spreadRadius: 10,
                      ),
                    ],
                  ),


                  child:  Center(

                    child:  Text(appTodoList[index], textAlign: TextAlign.center, style: GoogleFonts.laila(
                      textStyle: Theme.of(context).textTheme.headlineMedium,
                      fontSize: 30,
                      fontWeight: FontWeight.w900,
                      color: Colors.black54,
                    ),),

                  ),

                ),



              ),

            ),
          ),
          onTap: () {
          if (kDebugMode) {
            print('1 was clicked');
          }
          },
          );
        },

      ),
    ),
  ),
);

'''

I'm trying to add onTap() so each grid block takes me to another page.

Errors are:

  1. The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type.
  2. Unexpected text 'return'.
  3. Too many positional arguments: 0 expected, but 1 found.

Solution

  • Move return outside of Inkwell and add child to it.

    List.generate(
      8,
          (int index) {
        return InkWell(
          child: AnimationConfiguration.staggeredGrid(),
          onTap: () {},
        );
      }
    )