'Object?' 类型的值不能分配给 'SinginCharacter' 类型的变量
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;
});
},
)
],
)
],
),
)
],
),
),
)
],
),
);
}
}
您缺少 Radio 小部件上的类型,如 Radio< SinginCharacter>,如:
Radio<SinginCharacter>(
activeColor: Colors.green[700],
value: SinginCharacter.fill,
groupValue: _character,
onChanged: (value){
setState(() {
_character=value;
});
},
)
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;
});
},
)
],
)
],
),
)
],
),
),
)
],
),
);
}
}
您缺少 Radio 小部件上的类型,如 Radio< SinginCharacter>,如:
Radio<SinginCharacter>(
activeColor: Colors.green[700],
value: SinginCharacter.fill,
groupValue: _character,
onChanged: (value){
setState(() {
_character=value;
});
},
)