'I'm making a method for product images,price etc and i got this error
I'm making a method for product images,price and name.I'm beginner and doin this work my final year project please help me to solve this.
class Singleproduct extends StatelessWidget {
final String? productImage;
final String? productName;
final double? productPrice;
final Function? onTap;
Singleproduct(// this is the error (Use key in widget constructors.)
{@required this.productImage,
@required this.productName,
@required this.productPrice,
this.onTap});
Solution 1:[1]
The error is shown because of this lint rule: https://dart-lang.github.io/linter/lints/use_key_in_widget_constructors.html
DO use key in widget constructors.
It's a good practice to expose the ability to provide a key when creating public widgets.
BAD:
class MyPublicWidget extends StatelessWidget { }
GOOD:
class MyPublicWidget extends StatelessWidget { MyPublicWidget({Key? key}) : super(key: key); }
Also check out this video on what keys are: https://api.flutter.dev/flutter/foundation/Key-class.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Er1 |
