title: Flutter Can't define a const constructor for a class with non-final fields
body: <p>I need to use setState in my code if i use its showing that</p>
  <pre><code>The method 'setState' isn't defined for the type 'ProductDetailPage'.
  </code></pre>
  <p>i know whats the issue its because i need to change the statelesswidget to statefullwidget. But there is one more issue if i change the stateless widget to statefull widget its showing error</p>
  <pre><code>Can't define a const constructor for a class with non-final fields.
  </code></pre>
  <p>MY code</p>
  <pre><code>part of '../pages.dart';
  
  class ProductDetailPage extends StatefulWidget {
    @override
    _ProductDetailPageState createState() =&gt; _ProductDetailPageState();
  }
  
  class _ProductDetailPageState extends State&lt;ProductDetailPage&gt; {
  
    final Product product;
  
    const ProductDetailPage({Key key, @required this.product}) : super(key: key); //showing error here
  
  
    @override
    Widget build(BuildContext context) {
  
      double stackWidth = MediaQuery.of(context).size.width;
      double stackHeight = MediaQuery.of(context).size.height;
  
      return Scaffold(
        body: Container(
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                buildCarousel(context),
  
              ],
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton.extended(
          onPressed: () {
            //todo: Get.to(CartPage());
          },
          backgroundColor: kPrimaryColor,
          label: Text(
            'product.addtocart',
            style: Theme.of(context).textTheme.button,
          ).tr(),
        ),
      );
    }
  
  
    SideInAnimation buildCarousel(BuildContext context) {
      double stackWidth = MediaQuery.of(context).size.width;
      double stackHeight = MediaQuery.of(context).size.height;
      return SideInAnimation(
        1,
        child: Container(
          color: kCardImageBCColor,
          child: Column(
            children: [
              SizedBox(
                height: stackHeight * 0.3,
                child: Image.asset(product.images[0]),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ...List.generate(product.images.length,
                          (index) =&gt; buildSmallProductPreview(index, context)),
                ],
              ),
              SizedBox(height: stackHeight * 0.02,)
            ],
          ),
  
        ),
      );
    }
  
    GestureDetector buildSmallProductPreview(int index, BuildContext context) {
      int selectedImage = 0;
      double stackWidth = MediaQuery.of(context).size.width;
      double stackHeight = MediaQuery.of(context).size.height;
      return GestureDetector(
        onTap: () {
          setState(() {
            selectedImage = index;
          });
        },
        child: AnimatedContainer(
          duration: Duration(seconds: 1),
  
          margin: EdgeInsets.only(right: 10),
          height: stackHeight * 0.07,
          width: stackWidth * 0.15,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10),
            border: Border.all(
                color: kPrimaryColor.withOpacity(selectedImage == index ? 1 : 0)),
          ),
          child: Image.asset(product.images[index]),
        ),
      );
    }
  }
  </code></pre>
  <p>I dont know why its showing error if use statefull widget and dont use setState its working fine. But i must need to setState so i must need to go on stateFull widget. And i need to solve error xD</p>