Bloc: [question]how to update a single property of an object

Created on 9 Jul 2020  路  5Comments  路  Source: felangel/bloc

mentioned in the previous question, but did not get your reply

@immutable
class UserState extends Equatable {
  final String nickname;
  final String address;

  const UserState({@required this.nickname,@required this.address});

  @override
  List<Object> get props => [nickname,address];

  @override
  String toString() => 'UserState { nickname: $nickname ,address: $address }';
}

bloc

only updating the address does not affect nickname

_updateAddress(UpdateAddress event) {
    return UserState(address: event.address); 
  }

whether it can only be used

return UserState(address: event.address, nickname: this.state.nickname);
question

Most helpful comment

Hi, @lihaotian0607

if you use Android studio, it have generate function, default hot key is command + N?

ok, thank you very much for your answer!

All 5 comments

Hi, @lihaotian0607

maybe you can use some extensions/snippets generate copyWith function

Hi, @lihaotian0607

maybe you can use some extensions/snippets generate copyWith function

thanks!! Do you have good suggestions?

Hi, @lihaotian0607

if you use Android studio, it have generate function, default hot key is command + N?

Hi, @lihaotian0607

if you use Android studio, it have generate function, default hot key is command + N?

ok, thank you very much for your answer!

its ok, if the problem is solved, then @felangel
will close this issue.

Was this page helpful?
0 / 5 - 0 ratings