I have Two Class in same page first Class name (Colords) and second Class name(ColorDott) I want to pass value from second Class to first class use InkWell onTap
//Pass value from here
and retrieve the value in the Class Colords extends StatefulWidget{
// receive value here }... I made a lot of attempts, but unfortunately it was unsuccessful,All attempts were showing me a phrase null.
class Body extends StatefulWidget{
final Product product;
Body({Key key, this.product}) : super(key: key);
@override
Sa createState() => Sa();
}
class Sa extends State<Body> {
@override
Widget build(BuildContext context) {
return ListView(
children: [
ProductImages(product: widget.product),
TopRoundedContainer(
color: Colors.white,
child: Column(
children: [
ProductDescription(
product: widget.product,
pressOnSeeMore: () {},
),
TopRoundedContainer(
color: Color(0xFFF6F7F9),
child: Column(
children: [
Colords(product: widget.product),
],
),
),
],
),
),
],
);
}
}
.Colords class
class Colords extends StatefulWidget{
final Product product;
//retrieve value here
Colords({Key key,this.product}) : super(key: key);
@override
Colr createState() => Colr();
}
class Colr extends State<Colords> {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
int numOfItems = 1;
@override
Widget build(BuildContext context) {
return Padding(
padding:
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(20)),
child:Column(
children:[ Row(
children: [
...List.generate(
widget.product.colors.length,
(index) => ColorDott(
color: widget.product.colors[index],
// isSelected: index == selectedColor,
count:index ,
),
),
Spacer(),
RoundedIconBtn(
icon: Icons.remove,
press: () {
if (numOfItems > 1) {
setState(() {
numOfItems--;
});
}
},
),
//SizedBox(width: getProportionateScreenWidth(7)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0 / 2),
child: Text(
numOfItems.toString().padLeft(2, "0"),
style: Theme.of(context).textTheme.headline6,
),
),
RoundedIconBtn(
icon: Icons.add,
showShadow: true,
press: () {
setState(() {
numOfItems++;
});
},
),
],
),
// Expanded(),
Row(
children: [
Expanded(
child:TopRoundedContainer(
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(
left: SizeConfig.screenWidth * 0.15,
right: SizeConfig.screenWidth * 0.15,
bottom: getProportionateScreenWidth(40),
top: getProportionateScreenWidth(15),
),
child: DefaultButton(
text: "Add To Cart",
press: () {
setState(() {
// widget.message='hgjh';
print(widget.message.toString());
});
},
),
),
),
)
],
),
]
),
);
}
}
ColorDott class
class ColorDott extends StatefulWidget{
@override
Colre createState() => Colre();
}
class Colre extends State<ColorDott> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
setState(() {
//send value
});
},
);
}
}
thank you.
I sloved by using sharedpreference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.