From 976f9081736e9d45f5ee5e2339b0952451a87704 Mon Sep 17 00:00:00 2001 From: Zied Dahmani Date: Wed, 20 Nov 2024 16:09:33 +0100 Subject: [PATCH 1/2] refactor: adjust proposal creation --- .../components/proposal_content_view.dart | 8 + .../interactor/proposal_creation_bloc.dart | 19 +-- .../proposal_creation_bloc.freezed.dart | 153 ------------------ .../interactor/proposal_creation_event.dart | 1 - .../creation/proposal_creation_page.dart | 10 +- .../components/proposal_details_view.dart | 10 +- .../history/proposals_history_page.dart | 0 7 files changed, 22 insertions(+), 179 deletions(-) delete mode 100644 lib/ui/proposals/history/proposals_history_page.dart diff --git a/lib/ui/proposals/creation/components/proposal_content_view.dart b/lib/ui/proposals/creation/components/proposal_content_view.dart index 08f9aaa8..4cf70130 100644 --- a/lib/ui/proposals/creation/components/proposal_content_view.dart +++ b/lib/ui/proposals/creation/components/proposal_content_view.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_quill/flutter_quill.dart'; +import 'package:flutter_quill/quill_delta.dart'; import 'package:get/get_utils/src/extensions/context_extensions.dart'; import 'package:hypha_wallet/design/hypha_colors.dart'; import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; @@ -27,6 +28,13 @@ class _ProposalContentViewState extends State { void initState() { super.initState(); + _titleController.text = context.read().state.proposal!.title ?? ''; + final String? details = context.read().state.proposal!.details; + if (details!= null) { + final List jsonData = jsonDecode(details); + _quillController.document = Document.fromDelta(Delta.fromJson(jsonData)); + } + _titleController.addListener(() { context.read().add(ProposalCreationEvent.updateProposal({'title': _titleController.text.isEmpty ? null : _titleController.text})); }); diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart index 22facbbb..3d0f9dd5 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart @@ -21,26 +21,21 @@ class ProposalCreationBloc extends Bloc(_initialize); on<_UpdateCurrentView>(_updateCurrentView); on<_UpdateProposal>(_updateProposal); on<_PublishProposal>(_publishProposal); on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null))); _pageController = PageController(initialPage: daos.length > 1 ? 0 : 1); + if (daos.length == 1) { + add(ProposalCreationEvent.updateProposal({'dao': daos.first})); + } } late final PageController _pageController; PageController get pageController => _pageController; - void _initialize(_Initialize event, Emitter emit) { - - if (daos.length == 1) { - emit(state.copyWith(proposal: state.proposal!.copyWith({'dao': daos.first}))); - } - } - void _updateCurrentView(_UpdateCurrentView event, Emitter emit) { if (event.nextViewIndex == -1) { emit(state.copyWith(command: const PageCommand.navigateBackToProposals())); @@ -77,13 +72,9 @@ class ProposalCreationBloc extends Bloc emit) { - _updateProposalFields(event.updates, emit); + final ProposalCreationModel proposal = state.proposal!.copyWith(event.updates); + emit(state.copyWith(proposal: proposal)); } Future _publishProposal(_PublishProposal event, Emitter emit) async { diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart index 7b11a1f0..a0cd4f57 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart @@ -476,7 +476,6 @@ abstract class _NavigateToFailurePage implements PageCommand { mixin _$ProposalCreationEvent { @optionalTypeArgs TResult when({ - required TResult Function() initialize, required TResult Function(int nextViewIndex) updateCurrentView, required TResult Function(Map updates) updateProposal, required TResult Function() publishProposal, @@ -485,7 +484,6 @@ mixin _$ProposalCreationEvent { throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ - TResult? Function()? initialize, TResult? Function(int nextViewIndex)? updateCurrentView, TResult? Function(Map updates)? updateProposal, TResult? Function()? publishProposal, @@ -494,7 +492,6 @@ mixin _$ProposalCreationEvent { throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ - TResult Function()? initialize, TResult Function(int nextViewIndex)? updateCurrentView, TResult Function(Map updates)? updateProposal, TResult Function()? publishProposal, @@ -504,7 +501,6 @@ mixin _$ProposalCreationEvent { throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ - required TResult Function(_Initialize value) initialize, required TResult Function(_UpdateCurrentView value) updateCurrentView, required TResult Function(_UpdateProposal value) updateProposal, required TResult Function(_PublishProposal value) publishProposal, @@ -513,7 +509,6 @@ mixin _$ProposalCreationEvent { throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, TResult? Function(_UpdateCurrentView value)? updateCurrentView, TResult? Function(_UpdateProposal value)? updateProposal, TResult? Function(_PublishProposal value)? publishProposal, @@ -522,7 +517,6 @@ mixin _$ProposalCreationEvent { throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ - TResult Function(_Initialize value)? initialize, TResult Function(_UpdateCurrentView value)? updateCurrentView, TResult Function(_UpdateProposal value)? updateProposal, TResult Function(_PublishProposal value)? publishProposal, @@ -554,129 +548,6 @@ class _$ProposalCreationEventCopyWithImpl<$Res, /// with the given fields replaced by the non-null parameter values. } -/// @nodoc -abstract class _$$InitializeImplCopyWith<$Res> { - factory _$$InitializeImplCopyWith( - _$InitializeImpl value, $Res Function(_$InitializeImpl) then) = - __$$InitializeImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitializeImplCopyWithImpl<$Res> - extends _$ProposalCreationEventCopyWithImpl<$Res, _$InitializeImpl> - implements _$$InitializeImplCopyWith<$Res> { - __$$InitializeImplCopyWithImpl( - _$InitializeImpl _value, $Res Function(_$InitializeImpl) _then) - : super(_value, _then); - - /// Create a copy of ProposalCreationEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitializeImpl implements _Initialize { - const _$InitializeImpl(); - - @override - String toString() { - return 'ProposalCreationEvent.initialize()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitializeImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initialize, - required TResult Function(int nextViewIndex) updateCurrentView, - required TResult Function(Map updates) updateProposal, - required TResult Function() publishProposal, - required TResult Function() clearPageCommand, - }) { - return initialize(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initialize, - TResult? Function(int nextViewIndex)? updateCurrentView, - TResult? Function(Map updates)? updateProposal, - TResult? Function()? publishProposal, - TResult? Function()? clearPageCommand, - }) { - return initialize?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initialize, - TResult Function(int nextViewIndex)? updateCurrentView, - TResult Function(Map updates)? updateProposal, - TResult Function()? publishProposal, - TResult Function()? clearPageCommand, - required TResult orElse(), - }) { - if (initialize != null) { - return initialize(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initialize value) initialize, - required TResult Function(_UpdateCurrentView value) updateCurrentView, - required TResult Function(_UpdateProposal value) updateProposal, - required TResult Function(_PublishProposal value) publishProposal, - required TResult Function(_ClearPageCommand value) clearPageCommand, - }) { - return initialize(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, - TResult? Function(_UpdateCurrentView value)? updateCurrentView, - TResult? Function(_UpdateProposal value)? updateProposal, - TResult? Function(_PublishProposal value)? publishProposal, - TResult? Function(_ClearPageCommand value)? clearPageCommand, - }) { - return initialize?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initialize value)? initialize, - TResult Function(_UpdateCurrentView value)? updateCurrentView, - TResult Function(_UpdateProposal value)? updateProposal, - TResult Function(_PublishProposal value)? publishProposal, - TResult Function(_ClearPageCommand value)? clearPageCommand, - required TResult orElse(), - }) { - if (initialize != null) { - return initialize(this); - } - return orElse(); - } -} - -abstract class _Initialize implements ProposalCreationEvent { - const factory _Initialize() = _$InitializeImpl; -} - /// @nodoc abstract class _$$UpdateCurrentViewImplCopyWith<$Res> { factory _$$UpdateCurrentViewImplCopyWith(_$UpdateCurrentViewImpl value, @@ -747,7 +618,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult when({ - required TResult Function() initialize, required TResult Function(int nextViewIndex) updateCurrentView, required TResult Function(Map updates) updateProposal, required TResult Function() publishProposal, @@ -759,7 +629,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function()? initialize, TResult? Function(int nextViewIndex)? updateCurrentView, TResult? Function(Map updates)? updateProposal, TResult? Function()? publishProposal, @@ -771,7 +640,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function()? initialize, TResult Function(int nextViewIndex)? updateCurrentView, TResult Function(Map updates)? updateProposal, TResult Function()? publishProposal, @@ -787,7 +655,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult map({ - required TResult Function(_Initialize value) initialize, required TResult Function(_UpdateCurrentView value) updateCurrentView, required TResult Function(_UpdateProposal value) updateProposal, required TResult Function(_PublishProposal value) publishProposal, @@ -799,7 +666,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, TResult? Function(_UpdateCurrentView value)? updateCurrentView, TResult? Function(_UpdateProposal value)? updateProposal, TResult? Function(_PublishProposal value)? publishProposal, @@ -811,7 +677,6 @@ class _$UpdateCurrentViewImpl implements _UpdateCurrentView { @override @optionalTypeArgs TResult maybeMap({ - TResult Function(_Initialize value)? initialize, TResult Function(_UpdateCurrentView value)? updateCurrentView, TResult Function(_UpdateProposal value)? updateProposal, TResult Function(_PublishProposal value)? publishProposal, @@ -914,7 +779,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult when({ - required TResult Function() initialize, required TResult Function(int nextViewIndex) updateCurrentView, required TResult Function(Map updates) updateProposal, required TResult Function() publishProposal, @@ -926,7 +790,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function()? initialize, TResult? Function(int nextViewIndex)? updateCurrentView, TResult? Function(Map updates)? updateProposal, TResult? Function()? publishProposal, @@ -938,7 +801,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function()? initialize, TResult Function(int nextViewIndex)? updateCurrentView, TResult Function(Map updates)? updateProposal, TResult Function()? publishProposal, @@ -954,7 +816,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult map({ - required TResult Function(_Initialize value) initialize, required TResult Function(_UpdateCurrentView value) updateCurrentView, required TResult Function(_UpdateProposal value) updateProposal, required TResult Function(_PublishProposal value) publishProposal, @@ -966,7 +827,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, TResult? Function(_UpdateCurrentView value)? updateCurrentView, TResult? Function(_UpdateProposal value)? updateProposal, TResult? Function(_PublishProposal value)? publishProposal, @@ -978,7 +838,6 @@ class _$UpdateProposalImpl implements _UpdateProposal { @override @optionalTypeArgs TResult maybeMap({ - TResult Function(_Initialize value)? initialize, TResult Function(_UpdateCurrentView value)? updateCurrentView, TResult Function(_UpdateProposal value)? updateProposal, TResult Function(_PublishProposal value)? publishProposal, @@ -1046,7 +905,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult when({ - required TResult Function() initialize, required TResult Function(int nextViewIndex) updateCurrentView, required TResult Function(Map updates) updateProposal, required TResult Function() publishProposal, @@ -1058,7 +916,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function()? initialize, TResult? Function(int nextViewIndex)? updateCurrentView, TResult? Function(Map updates)? updateProposal, TResult? Function()? publishProposal, @@ -1070,7 +927,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function()? initialize, TResult Function(int nextViewIndex)? updateCurrentView, TResult Function(Map updates)? updateProposal, TResult Function()? publishProposal, @@ -1086,7 +942,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult map({ - required TResult Function(_Initialize value) initialize, required TResult Function(_UpdateCurrentView value) updateCurrentView, required TResult Function(_UpdateProposal value) updateProposal, required TResult Function(_PublishProposal value) publishProposal, @@ -1098,7 +953,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, TResult? Function(_UpdateCurrentView value)? updateCurrentView, TResult? Function(_UpdateProposal value)? updateProposal, TResult? Function(_PublishProposal value)? publishProposal, @@ -1110,7 +964,6 @@ class _$PublishProposalImpl implements _PublishProposal { @override @optionalTypeArgs TResult maybeMap({ - TResult Function(_Initialize value)? initialize, TResult Function(_UpdateCurrentView value)? updateCurrentView, TResult Function(_UpdateProposal value)? updateProposal, TResult Function(_PublishProposal value)? publishProposal, @@ -1169,7 +1022,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult when({ - required TResult Function() initialize, required TResult Function(int nextViewIndex) updateCurrentView, required TResult Function(Map updates) updateProposal, required TResult Function() publishProposal, @@ -1181,7 +1033,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function()? initialize, TResult? Function(int nextViewIndex)? updateCurrentView, TResult? Function(Map updates)? updateProposal, TResult? Function()? publishProposal, @@ -1193,7 +1044,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function()? initialize, TResult Function(int nextViewIndex)? updateCurrentView, TResult Function(Map updates)? updateProposal, TResult Function()? publishProposal, @@ -1209,7 +1059,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult map({ - required TResult Function(_Initialize value) initialize, required TResult Function(_UpdateCurrentView value) updateCurrentView, required TResult Function(_UpdateProposal value) updateProposal, required TResult Function(_PublishProposal value) publishProposal, @@ -1221,7 +1070,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(_Initialize value)? initialize, TResult? Function(_UpdateCurrentView value)? updateCurrentView, TResult? Function(_UpdateProposal value)? updateProposal, TResult? Function(_PublishProposal value)? publishProposal, @@ -1233,7 +1081,6 @@ class _$ClearPageCommandImpl implements _ClearPageCommand { @override @optionalTypeArgs TResult maybeMap({ - TResult Function(_Initialize value)? initialize, TResult Function(_UpdateCurrentView value)? updateCurrentView, TResult Function(_UpdateProposal value)? updateProposal, TResult Function(_PublishProposal value)? publishProposal, diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_event.dart b/lib/ui/proposals/creation/interactor/proposal_creation_event.dart index 7ef1a257..134efd3f 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_event.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_event.dart @@ -2,7 +2,6 @@ part of 'proposal_creation_bloc.dart'; @freezed class ProposalCreationEvent with _$ProposalCreationEvent { - const factory ProposalCreationEvent.initialize() = _Initialize; const factory ProposalCreationEvent.updateCurrentView(int nextViewIndex) = _UpdateCurrentView; const factory ProposalCreationEvent.updateProposal(Map updates) = _UpdateProposal; const factory ProposalCreationEvent.publishProposal() = _PublishProposal; diff --git a/lib/ui/proposals/creation/proposal_creation_page.dart b/lib/ui/proposals/creation/proposal_creation_page.dart index 6fbff9d8..a94851b1 100644 --- a/lib/ui/proposals/creation/proposal_creation_page.dart +++ b/lib/ui/proposals/creation/proposal_creation_page.dart @@ -1,12 +1,9 @@ -// ignore_for_file: unused_import - import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get/get.dart'; import 'package:get_it/get_it.dart'; import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; import 'package:hypha_wallet/core/network/models/dao_data_model.dart'; -import 'package:hypha_wallet/core/network/models/outcome_model.dart'; import 'package:hypha_wallet/design/hypha_colors.dart'; import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; import 'package:hypha_wallet/ui/proposals/creation/components/dao_selection_view.dart'; @@ -18,9 +15,8 @@ import 'package:hypha_wallet/ui/sign_transaction/success/sign_transaction_succes import 'package:smooth_page_indicator/smooth_page_indicator.dart'; class ProposalCreationPage extends StatelessWidget { - const ProposalCreationPage(this.daos, {super.key}); - final List daos; + const ProposalCreationPage(this.daos, {super.key}); @override Widget build(BuildContext context) { @@ -88,6 +84,10 @@ class ProposalCreationPage extends StatelessWidget { onTap: () { final nextIndex = state.currentViewIndex + (index == 0 ? -1 : 1); if (nextIndex >= -1) { + if(state.currentViewIndex == 1) { + FocusManager.instance.primaryFocus?.unfocus(); + } + context.read().add(ProposalCreationEvent.updateCurrentView(nextIndex)); } }, diff --git a/lib/ui/proposals/details/components/proposal_details_view.dart b/lib/ui/proposals/details/components/proposal_details_view.dart index 6500f4ab..013b0963 100644 --- a/lib/ui/proposals/details/components/proposal_details_view.dart +++ b/lib/ui/proposals/details/components/proposal_details_view.dart @@ -106,12 +106,12 @@ class _ProposalDetailsViewState extends State { ), const SizedBox(height: 30), + // TODO(Zied): check this /// Details Section if (_proposalDetailsModel.description != null) ...[ Text( 'Proposal Details', - style: context.hyphaTextTheme.ralMediumSmallNote - .copyWith(color: HyphaColors.midGrey), + style: context.hyphaTextTheme.ralMediumSmallNote.copyWith(color: HyphaColors.midGrey), ), ValueListenableBuilder( valueListenable: _isExpandedNotifier, @@ -123,8 +123,7 @@ class _ProposalDetailsViewState extends State { padding: const EdgeInsets.only(top: 10), child: Text( _proposalDetailsModel.description ?? '', - style: - context.hyphaTextTheme.ralMediumBody, + style: context.hyphaTextTheme.ralMediumBody, maxLines: isExpanded ? null : 3, overflow: isExpanded ? TextOverflow.visible @@ -132,8 +131,7 @@ class _ProposalDetailsViewState extends State { ), ), Padding( - padding: const EdgeInsets.symmetric( - vertical: 20), + padding: const EdgeInsets.symmetric(vertical: 20), child: Row( children: [ const Expanded(child: HyphaDivider()), diff --git a/lib/ui/proposals/history/proposals_history_page.dart b/lib/ui/proposals/history/proposals_history_page.dart deleted file mode 100644 index e69de29b..00000000 From 4d016a73d3f0511dc9ca56ca8647260e55bcf0f5 Mon Sep 17 00:00:00 2001 From: Zied Dahmani Date: Thu, 21 Nov 2024 11:00:55 +0100 Subject: [PATCH 2/2] refactor: make proposal non-optional --- .../components/dao_selection_view.dart | 4 +-- .../components/outcome_selection_view.dart | 4 +-- .../components/proposal_content_view.dart | 4 +-- .../components/proposal_review_view.dart | 6 ++-- .../interactor/proposal_creation_bloc.dart | 10 +++--- .../proposal_creation_bloc.freezed.dart | 36 +++++++++---------- .../interactor/proposal_creation_state.dart | 14 ++++++-- .../creation/proposal_creation_page.dart | 4 +-- 8 files changed, 44 insertions(+), 38 deletions(-) diff --git a/lib/ui/proposals/creation/components/dao_selection_view.dart b/lib/ui/proposals/creation/components/dao_selection_view.dart index a613c84b..c9c85195 100644 --- a/lib/ui/proposals/creation/components/dao_selection_view.dart +++ b/lib/ui/proposals/creation/components/dao_selection_view.dart @@ -26,7 +26,7 @@ class _DaoSelectionViewState extends State { daos = GetIt.I.get().daos; final ProposalCreationBloc proposalCreationBloc = context.read(); - if (proposalCreationBloc.state.proposal?.dao == null) { + if (proposalCreationBloc.state.proposal.dao == null) { selectedDaoIndexNotifier = ValueNotifier(0); proposalCreationBloc.add( ProposalCreationEvent.updateProposal( @@ -35,7 +35,7 @@ class _DaoSelectionViewState extends State { ); } else { selectedDaoIndexNotifier = ValueNotifier( - daos.indexOf(proposalCreationBloc.state.proposal!.dao!)); + daos.indexOf(proposalCreationBloc.state.proposal.dao!)); } } diff --git a/lib/ui/proposals/creation/components/outcome_selection_view.dart b/lib/ui/proposals/creation/components/outcome_selection_view.dart index 160d59e6..3083e14d 100644 --- a/lib/ui/proposals/creation/components/outcome_selection_view.dart +++ b/lib/ui/proposals/creation/components/outcome_selection_view.dart @@ -42,7 +42,7 @@ class _OutcomeSelectionViewState extends State { void initState() { super.initState(); final ProposalCreationBloc proposalCreationBloc = context.read(); - if (proposalCreationBloc.state.proposal?.type == null) { + if (proposalCreationBloc.state.proposal.type == null) { selectedTypeIndexNotifier = ValueNotifier(0); context.read().add( ProposalCreationEvent.updateProposal( @@ -51,7 +51,7 @@ class _OutcomeSelectionViewState extends State { ); } else { selectedTypeIndexNotifier = ValueNotifier( - outcomeTypes.indexWhere((outcome) => outcome.type.label == proposalCreationBloc.state.proposal?.type.name)); + outcomeTypes.indexWhere((outcome) => outcome.type.label == proposalCreationBloc.state.proposal.type.name)); } } diff --git a/lib/ui/proposals/creation/components/proposal_content_view.dart b/lib/ui/proposals/creation/components/proposal_content_view.dart index 4cf70130..d5990390 100644 --- a/lib/ui/proposals/creation/components/proposal_content_view.dart +++ b/lib/ui/proposals/creation/components/proposal_content_view.dart @@ -28,8 +28,8 @@ class _ProposalContentViewState extends State { void initState() { super.initState(); - _titleController.text = context.read().state.proposal!.title ?? ''; - final String? details = context.read().state.proposal!.details; + _titleController.text = context.read().state.proposal.title ?? ''; + final String? details = context.read().state.proposal.details; if (details!= null) { final List jsonData = jsonDecode(details); _quillController.document = Document.fromDelta(Delta.fromJson(jsonData)); diff --git a/lib/ui/proposals/creation/components/proposal_review_view.dart b/lib/ui/proposals/creation/components/proposal_review_view.dart index d68b9ddd..86f1a590 100644 --- a/lib/ui/proposals/creation/components/proposal_review_view.dart +++ b/lib/ui/proposals/creation/components/proposal_review_view.dart @@ -31,7 +31,7 @@ class ProposalReviewView extends StatelessWidget { child: IntrinsicHeight( child: BlocBuilder( builder: (context, state) { - final List jsonData = jsonDecode(state.proposal!.details!); + final List jsonData = jsonDecode(state.proposal.details!); final Document document = Document.fromDelta(Delta.fromJson(jsonData)); return Column( @@ -39,7 +39,7 @@ class ProposalReviewView extends StatelessWidget { children: [ const SizedBox(height: 20), ProposalHeader( - state.proposal!.dao, + state.proposal.dao, text: 'Builders', ), const Padding( @@ -53,7 +53,7 @@ class ProposalReviewView extends StatelessWidget { Padding( padding: const EdgeInsets.only(top: 10, bottom: 20), child: Text( - state.proposal!.title!, + state.proposal.title!, style: context.hyphaTextTheme.mediumTitles, ), ), diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart index 3d0f9dd5..063b8085 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart @@ -20,7 +20,7 @@ class ProposalCreationBloc extends Bloc(_updateCurrentView); on<_UpdateProposal>(_updateProposal); on<_PublishProposal>(_publishProposal); @@ -45,7 +45,7 @@ class ProposalCreationBloc extends Bloc emit) { - final ProposalCreationModel proposal = state.proposal!.copyWith(event.updates); + final ProposalCreationModel proposal = state.proposal.copyWith(event.updates); emit(state.copyWith(proposal: proposal)); } Future _publishProposal(_PublishProposal event, Emitter emit) async { emit(state.copyWith(pageState: PageState.loading)); - final Result result = await _publishProposalUseCase.run(state.proposal!); + final Result result = await _publishProposalUseCase.run(state.proposal); if (result.isValue) { emit(state.copyWith(pageState: PageState.success, command: const PageCommand.navigateToSuccessPage())); diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart index a0cd4f57..d62bf5ab 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_bloc.freezed.dart @@ -1102,7 +1102,7 @@ abstract class _ClearPageCommand implements ProposalCreationEvent { mixin _$ProposalCreationState { PageState get pageState => throw _privateConstructorUsedError; int get currentViewIndex => throw _privateConstructorUsedError; - ProposalCreationModel? get proposal => throw _privateConstructorUsedError; + ProposalCreationModel get proposal => throw _privateConstructorUsedError; PageCommand? get command => throw _privateConstructorUsedError; /// Create a copy of ProposalCreationState @@ -1121,7 +1121,7 @@ abstract class $ProposalCreationStateCopyWith<$Res> { $Res call( {PageState pageState, int currentViewIndex, - ProposalCreationModel? proposal, + ProposalCreationModel proposal, PageCommand? command}); $PageCommandCopyWith<$Res>? get command; @@ -1145,7 +1145,7 @@ class _$ProposalCreationStateCopyWithImpl<$Res, $Res call({ Object? pageState = null, Object? currentViewIndex = null, - Object? proposal = freezed, + Object? proposal = null, Object? command = freezed, }) { return _then(_value.copyWith( @@ -1157,10 +1157,10 @@ class _$ProposalCreationStateCopyWithImpl<$Res, ? _value.currentViewIndex : currentViewIndex // ignore: cast_nullable_to_non_nullable as int, - proposal: freezed == proposal + proposal: null == proposal ? _value.proposal : proposal // ignore: cast_nullable_to_non_nullable - as ProposalCreationModel?, + as ProposalCreationModel, command: freezed == command ? _value.command : command // ignore: cast_nullable_to_non_nullable @@ -1195,7 +1195,7 @@ abstract class _$$ProposalCreationStateImplCopyWith<$Res> $Res call( {PageState pageState, int currentViewIndex, - ProposalCreationModel? proposal, + ProposalCreationModel proposal, PageCommand? command}); @override @@ -1218,7 +1218,7 @@ class __$$ProposalCreationStateImplCopyWithImpl<$Res> $Res call({ Object? pageState = null, Object? currentViewIndex = null, - Object? proposal = freezed, + Object? proposal = null, Object? command = freezed, }) { return _then(_$ProposalCreationStateImpl( @@ -1230,10 +1230,10 @@ class __$$ProposalCreationStateImplCopyWithImpl<$Res> ? _value.currentViewIndex : currentViewIndex // ignore: cast_nullable_to_non_nullable as int, - proposal: freezed == proposal + proposal: null == proposal ? _value.proposal : proposal // ignore: cast_nullable_to_non_nullable - as ProposalCreationModel?, + as ProposalCreationModel, command: freezed == command ? _value.command : command // ignore: cast_nullable_to_non_nullable @@ -1246,19 +1246,17 @@ class __$$ProposalCreationStateImplCopyWithImpl<$Res> class _$ProposalCreationStateImpl implements _ProposalCreationState { const _$ProposalCreationStateImpl( - {this.pageState = PageState.initial, - this.currentViewIndex = 0, - this.proposal, + {required this.pageState, + required this.currentViewIndex, + required this.proposal, this.command}); @override - @JsonKey() final PageState pageState; @override - @JsonKey() final int currentViewIndex; @override - final ProposalCreationModel? proposal; + final ProposalCreationModel proposal; @override final PageCommand? command; @@ -1297,9 +1295,9 @@ class _$ProposalCreationStateImpl implements _ProposalCreationState { abstract class _ProposalCreationState implements ProposalCreationState { const factory _ProposalCreationState( - {final PageState pageState, - final int currentViewIndex, - final ProposalCreationModel? proposal, + {required final PageState pageState, + required final int currentViewIndex, + required final ProposalCreationModel proposal, final PageCommand? command}) = _$ProposalCreationStateImpl; @override @@ -1307,7 +1305,7 @@ abstract class _ProposalCreationState implements ProposalCreationState { @override int get currentViewIndex; @override - ProposalCreationModel? get proposal; + ProposalCreationModel get proposal; @override PageCommand? get command; diff --git a/lib/ui/proposals/creation/interactor/proposal_creation_state.dart b/lib/ui/proposals/creation/interactor/proposal_creation_state.dart index 6e36ad7a..0df149ec 100644 --- a/lib/ui/proposals/creation/interactor/proposal_creation_state.dart +++ b/lib/ui/proposals/creation/interactor/proposal_creation_state.dart @@ -3,9 +3,17 @@ part of 'proposal_creation_bloc.dart'; @freezed class ProposalCreationState with _$ProposalCreationState { const factory ProposalCreationState({ - @Default(PageState.initial) PageState pageState, - @Default(0) int currentViewIndex, - ProposalCreationModel? proposal, + required PageState pageState, + required int currentViewIndex, + required ProposalCreationModel proposal, PageCommand? command, }) = _ProposalCreationState; + + factory ProposalCreationState.initial() { + return ProposalCreationState( + pageState: PageState.initial, + currentViewIndex: 0, + proposal: ProposalCreationModel(), + ); + } } diff --git a/lib/ui/proposals/creation/proposal_creation_page.dart b/lib/ui/proposals/creation/proposal_creation_page.dart index a94851b1..c859a47e 100644 --- a/lib/ui/proposals/creation/proposal_creation_page.dart +++ b/lib/ui/proposals/creation/proposal_creation_page.dart @@ -29,7 +29,7 @@ class ProposalCreationPage extends StatelessWidget { Get.back(); }, navigateToSuccessPage: () { - Get.to(() => SignTransactionSuccessPage(transactionType: SignSuccessTransactionType.published, proposalId: state.proposal!.id)); + Get.to(() => SignTransactionSuccessPage(transactionType: SignSuccessTransactionType.published, proposalId: state.proposal.id)); }, navigateToFailurePage: (HyphaError hyphaError) { Get.to(() => BlocProvider.value( @@ -92,7 +92,7 @@ class ProposalCreationPage extends StatelessWidget { } }, child: Opacity( - opacity: index == 1 && (state.currentViewIndex == 1 && (state.proposal?.details == null || state.proposal?.title == null)) ? .25 : 1, + opacity: index == 1 && (state.currentViewIndex == 1 && (state.proposal.details == null || state.proposal.title == null)) ? .25 : 1, child: Container( margin: const EdgeInsets.only(left: 10), height: 40,