Reputation: 1877
When i am passing a list of boolean statically it works perfectly fulfilling my logic, but when i pass the list of boolean from model it is not working fine.
List<bool> colorSelected = [
true,
true,
false,
false,
false,
false,
false
];
This is my model class:
class ProductDetail extends Equatable {
List<bool> repeatOn;
ProductDetail(
{
this.repeatOn
});
@override
List<ProductDetail> get props => productDetailList;
}
final List<ProductDetail> productDetailList = [
ProductDetail(
repeatOn: [false, false, true, false, true, false, true],
];
ProductDetail pd=ProductDetail();
In my statefulwidget, i am initializing it like this in init method
colorSelected=pd.props[0].repeatOn;
But when i am running this it always return me false for all values of colorSelected. But it should return me 3 true boolean values in the list. Can you please guide me where i am doing wrong?
Upvotes: 0
Views: 1389
Reputation: 2355
first of all, you don't need to get props in class
you should create your class like this
class ProductDetail {
List<bool> repeatOn;
ProductDetail({
this.repeatOn
});
}
and when you make an object from your class you should pass it ProductDetail
not a list of ProductDetail
final ProductDetail productDetailList =
ProductDetail(
repeatOn: [false, false, true, false, true, false, true],
);
after all for accessing your list items
colorSelected = productDetailList.repeatOn[0];
Upvotes: 2