Home > database >  The named parameter 'key' is required, but there's no corresponding argument. in flut
The named parameter 'key' is required, but there's no corresponding argument. in flut

Time:09-29

I'm getting this error called The named parameter 'key' is required, but there's no corresponding argument. I'm developing a e-commerce app using flutter, android studio. didn't understand about the error I'm new to flutter. can anyone tell me what to do about this error?

This is the youtube link for the project

This is the github link for the source code

enter image description here

import 'package:flutter/material.dart';
import 'package:shop_app/constants.dart';
import 'package:shop_app/models/Product.dart';
import 'package:shop_app/screens/details/details_screen.dart';
import 'categorries.dart';
import 'item_card.dart';

class Body extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
          child: Text(
            "Women",
            style: Theme.of(context)
                .textTheme
                .headline5
                ?.copyWith(fontWeight: FontWeight.bold),
          ),
        ),
        Categories(),
        Expanded(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
            child: GridView.builder(
                itemCount: products.length,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  mainAxisSpacing: kDefaultPaddin,
                  crossAxisSpacing: kDefaultPaddin,
                  childAspectRatio: 0.75,
                ),
                itemBuilder: (context, index) => ItemCard(
                      product: products[index],
                      press: () => Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => DetailsScreen(
                              product: products[index],
                            ),
                          )),
                    )),
          ),
        ),
      ],
    );
  }
}

CodePudding user response:

Below class Body … and above @override add these lines:

const Body({
Key? Key,
}) : super(key: key);

Key is a default thing you should pass to all Stateless and Stateful Flutter widgets.

CodePudding user response:

Your problem is with the Flutter version. Update the Flutter SDK, download the project from GitHub again and run it.

  • Related