A value of type 'Object?' can't be assigned to a variable of type 'SinginCharacter'

import 'package:flutter/material.dart';
import 'package:foodcorner/color/colors.dart';



  enum SinginCharacter {fill,outline}

class ProductDetails extends StatefulWidget {
  const ProductDetails({Key? key}) : super(key: key);

  @override
  _ProductDetailsState createState() => _ProductDetailsState();
}

class _ProductDetailsState extends State<ProductDetails> {


  SinginCharacter _character = SinginCharacter.fill;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: IconThemeData(color: textColor),
        title: Text(
          'Product Details',
          style: TextStyle(color: textColor),
        ),
        backgroundColor: primaryColor,
      ),
      bottomNavigationBar: Row(children: [
        Expanded(
          child: Material(
            color: Colors.deepOrangeAccent,
            child: InkWell(
              onTap: () {
                //print('called on tap');
              },
              child: SizedBox(
                height: kToolbarHeight,
                width: double.infinity,
                child: Center(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(Icons.favorite_border_outlined),
                      SizedBox(
                        width: 5,
                      ),
                      Text(
                        'Add To WishList',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
        Expanded(
          child: Material(
            color: Colors.amberAccent,
            child: InkWell(
              onTap: () {
                //print('called on tap');
              },
              child: SizedBox(
                height: kToolbarHeight,
                width: double.infinity,
                child: Center(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(Icons.shop_outlined),
                      SizedBox(
                        width: 5,
                      ),
                      Text(
                        'Add To Cart',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        )
      ]),
      body: Column(
        children: [
          Expanded(
            flex: 2,
            child: Container(
              width: double.infinity,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.only(top: 20, left: 15),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          'fresh Basil',
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 25),
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        Text(
                          '\ 50Tak',
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 25),
                        ),
                      ],
                    ),
                  ),
                  Container(
                      height: 250,
                      margin: EdgeInsets.all(40),
                      child: Center(
                        child: Image.network(
                            'http://assets.stickpng.com/images/58bf1e2ae443f41d77c734ab.png'),
                      )),
                  Padding(
                    padding: const EdgeInsets.only(left: 15),
                    child: Container(
                      width: double.infinity,
                      child: Text(
                        'Available Option',
                        style: TextStyle(
                            fontWeight: FontWeight.w600, fontSize: 20),
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 10),
                    child: Row(
                      children: [
                        Row(
                          children: [

                            CircleAvatar(
                              radius: 3,
                              backgroundColor: Colors.green[700],
                            ),


           //A value of type 'Object?' can't be assigned to a variable of type 'SinginCharacter'.

                            Radio(
                              activeColor: Colors.green[700],
                              value: SinginCharacter.fill,
                              groupValue: _character,
                              onChanged: (value){
                                setState(() {
                                  _character=value;
                                });
                              },

                            )


                          ],
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You’re missing the type on the Radio widget, as in Radio< SinginCharacter>, as in:


Radio<SinginCharacter>(
 activeColor: Colors.green[700],
 value: SinginCharacter.fill,
 groupValue: _character,
 onChanged: (value){
   setState(() {
     _character=value;
   });
 },
)

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply