-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Question) how to rebuild every value in BuiltList? #250
Comments
Rebuild should work as you want; I can't see a problem in your code.
e.g.
var newList = old list.rebuild((x) => x.map((v) => v + 1))
to add one to every value in the list.
…On Thu, Aug 19, 2021, 16:35 Lintang Kusuma ***@***.***> wrote:
I'm new to built list, there's this thing I cant understand, so I have a
model called AdressShipmentModel
In that model i have this value (I'm using freezed package)
@freezed
abstract class AdressShipmentModel with _$AdressShipmentModel {
const factory AdressShipmentModel({
required int addrId,
required String label,
required String receiverName,
required String receiverPhone,
required String address,
required String isDefault,
required int locationId,
required String locationName,
required String latlng,
@default(false) @jsonkey(ignore: true) bool isChoosenAddress,
}) = _AdressShipmentModel;
factory AdressShipmentModel.fromJson(Map<String, dynamic> json) => _$AdressShipmentModelFromJson(json);
}
The goal is to modify the model that choose by user is default by
parameter isChoosenAddress
By this code I'm able to modify the choosen address to true if isDefault
parameter is "1".
initialData() {
List<AdressShipmentModel> oldValue = value.toList();
List<AdressShipmentModel> newValue = [];
oldValue.forEach((e) {
if (e.isDefault == "1") {
newValue.add(e.copyWith(isChoosenAddress: true));
} else {
newValue.add(e.copyWith(isChoosenAddress: false));
}
});
return ChoosenAddressEntities._(BuiltList<AdressShipmentModel>(newValue));
}
But this was the old method of modifying list, and there's really no need
for built_collection package if I do it like this.
When I use .rebuild(), it will not modify list as I wanted, both of the
isChoosenAddress was set to false. (Not modified)
[image: image]
<https://user-images.githubusercontent.com/57997512/130087665-e7d9a424-b925-49e1-b685-0ea32fd38227.png>
Is there's something I do wrong? An explanation will be so much
appreciated! Thank you :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#250>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADAZMCU2VY332RM7NNM36FTT5UJDFANCNFSM5COLT5JA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm new to built list, there's this thing I cant understand, so I have a model called
AdressShipmentModel
In that model i have this value (I'm using freezed package)
The goal is to modify the model that choose by user is default by parameter
isChoosenAddress
By this code I'm able to modify the choosen address to
true
ifisDefault
parameter is "1".But this was the old method of modifying list, and there's really no need for built_collection package if I do it like this.
When I use
![image](https://user-images.githubusercontent.com/57997512/130087665-e7d9a424-b925-49e1-b685-0ea32fd38227.png)
.rebuild()
, it will not modify list as I wanted, both of theisChoosenAddress
was set tofalse
. (Not modified)Is there's something I do wrong? Any kind of explanation will be so much appreciated! Thank you :)
This was my full code of logic:
The text was updated successfully, but these errors were encountered: