состояние редукции флаттера изменено без диспетчерских действий - PullRequest
1 голос
/ 06 марта 2020

Я использую вместе Redx и Blo c. У меня есть экран редактирования профиля, и я получаю начальное значение из избыточного состояния, а затем изменяю значения в blo c. Но когда изменилось мое состояние blo c, изменилось и избыточное состояние без отправки действий. Я хочу изменить состояние избыточности, когда пользователь отправляет отредактированные значения. Вот моя первая часть метода сборки:

return StoreConnector<AppState, Store<AppState>>(
  converter: (store) => store,
  builder: (context, store) {
    return Scaffold(
      appBar: appBar,
      body: BlocProvider(
        create: (context) => EditUserProfileBloc(
          editEditUserProfileRepository: repository,
        )..add(
            EditUserProfileScreenLoaded(
              userProfile: store.state.userProfile,
            ),
          ),
        child: BlocListener<EditUserProfileBloc, EditUserProfileState>(
          listener: (context, state) async {},
          child: BlocBuilder<EditUserProfileBloc, EditUserProfileState>(
            builder: (context, state) {
              _bloc = BlocProvider.of<EditUserProfileBloc>(context);
                ...

и мой виджет для отображения и изменения изображения:

ImageSelect(
    onSelect: (img) => _bloc.add(
        EditUserProfileImageChanged(imgSrc: img),
    ),
    child: Avatar(imgSrc: state.userProfile.avatar),
),

и мой блок c:

if (event is EditUserProfileImageChanged) {
    UserProfile newUserProfile = state.userProfile;

    yield EditUserProfileBeforeTotalChanged();
    newUserProfile.avatar = event.imgSrc;
    yield EditUserProfileTotalState(userProfile: newUserProfile);
}

здесь, когда я меняю аватар без сохранения, в других местах я тоже использую аватар.

...