-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement proposal review page
- Loading branch information
1 parent
d2a0f94
commit d5e0363
Showing
14 changed files
with
1,276 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,4 +154,6 @@ void _registerBlocsModule() { | |
dao | ||
), | ||
); | ||
|
||
_registerFactory(() => ProposalCreationBloc()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ProposalCreationModel { | ||
final String? title; | ||
final String? details; | ||
|
||
ProposalCreationModel({this.title, this.details}); | ||
|
||
ProposalCreationModel copyWith(Map<String, dynamic> updates) { | ||
return ProposalCreationModel( | ||
title: updates.containsKey('title') ? updates['title'] : title, | ||
details: updates.containsKey('details') ? updates['details'] : details, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
lib/ui/proposals/creation/components/proposal_review_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'dart:convert'; | ||
import 'package:flutter/cupertino.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/core/network/models/dao_data_model.dart'; | ||
import 'package:hypha_wallet/design/buttons/hypha_app_button.dart'; | ||
import 'package:hypha_wallet/design/dividers/hypha_divider.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/components/proposal_header.dart'; | ||
import 'package:hypha_wallet/ui/proposals/creation/interactor/proposal_creation_bloc.dart'; | ||
|
||
class ProposalReviewView extends StatelessWidget { | ||
const ProposalReviewView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 20), | ||
height: double.infinity, | ||
color: context.isDarkMode ? HyphaColors.darkBlack : HyphaColors.offWhite, | ||
child: SafeArea( | ||
bottom: true, | ||
child: LayoutBuilder( | ||
builder: (context, constraint) { | ||
return SingleChildScrollView( | ||
child: ConstrainedBox( | ||
constraints: BoxConstraints(minHeight: constraint.maxHeight), | ||
child: IntrinsicHeight( | ||
child: BlocBuilder<ProposalCreationBloc, ProposalCreationState>( | ||
builder: (context, state) { | ||
final List<dynamic> jsonData = jsonDecode(state.proposal!.details!); | ||
final Document document = Document.fromDelta(Delta.fromJson(jsonData)); | ||
|
||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const SizedBox(height: 20), | ||
const Row( | ||
children: [ | ||
Expanded( | ||
child: ProposalHeader( | ||
DaoData( | ||
docId: 21345, | ||
detailsDaoName: '', | ||
settingsDaoTitle: 'HyphaDao', | ||
logoIPFSHash: '', | ||
logoType: '', | ||
settingsDaoUrl: '', | ||
), | ||
text: 'Builders', | ||
), | ||
), | ||
SizedBox(width: 10), | ||
Icon(CupertinoIcons.hand_thumbsup, color: HyphaColors.primaryBlu), | ||
], | ||
), | ||
const Padding( | ||
padding: EdgeInsets.only(top: 10, bottom: 20), | ||
child: HyphaDivider(), | ||
), | ||
Text( | ||
'Agreement for', | ||
style: context.hyphaTextTheme.ralMediumSmallNote.copyWith(color: HyphaColors.primaryBlu), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 10, bottom: 20), | ||
child: Text( | ||
state.proposal!.title!, | ||
style: context.hyphaTextTheme.mediumTitles, | ||
), | ||
), | ||
Text( | ||
'Details', | ||
style: context.hyphaTextTheme.ralMediumSmallNote.copyWith(color: HyphaColors.primaryBlu), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 10, bottom: 20), | ||
child: QuillEditor.basic( | ||
controller: QuillController( | ||
document: document, | ||
selection: const TextSelection.collapsed(offset: 0), | ||
readOnly: true, | ||
), | ||
), | ||
), | ||
const Spacer(), | ||
HyphaAppButton( | ||
title: 'Publish', | ||
onPressed: () async { | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
part of 'proposal_creation_bloc.dart'; | ||
|
||
@freezed | ||
class PageCommand with _$PageCommand { | ||
const factory PageCommand.navigateBackToProposals() = _NavigateBackToProposals; | ||
} |
68 changes: 68 additions & 0 deletions
68
lib/ui/proposals/creation/interactor/proposal_creation_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:hypha_wallet/core/network/models/proposal_creation_model.dart'; | ||
import 'package:hypha_wallet/core/network/models/proposal_details_model.dart'; | ||
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart'; | ||
|
||
part 'page_command.dart'; | ||
part 'proposal_creation_bloc.freezed.dart'; | ||
part 'proposal_creation_event.dart'; | ||
part 'proposal_creation_state.dart'; | ||
|
||
class ProposalCreationBloc | ||
extends Bloc<ProposalCreationEvent, ProposalCreationState> { | ||
ProposalCreationBloc() : super(ProposalCreationState(proposal: ProposalCreationModel())) { | ||
on<_UpdateCurrentView>(_updateCurrentView); | ||
on<_UpdateProposal>(_updateProposal); | ||
on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null))); | ||
} | ||
|
||
// TODO(Saif): pass initialPage as parameter | ||
final PageController _pageController = PageController(initialPage: 0); | ||
PageController get pageController => _pageController; | ||
|
||
Future<void> _updateCurrentView(_UpdateCurrentView event, Emitter<ProposalCreationState> emit) async { | ||
if (event.nextViewIndex == -1) { | ||
emit(state.copyWith(command: const PageCommand.navigateBackToProposals())); | ||
} else { | ||
switch (event.nextViewIndex) { | ||
case 0: | ||
navigate(emit, event.nextViewIndex); | ||
break; | ||
case 1: | ||
navigate(emit, event.nextViewIndex); | ||
break; | ||
case 2: | ||
if(state.proposal?.details != null) { | ||
navigate(emit, event.nextViewIndex); | ||
} | ||
break; | ||
case 3: | ||
navigate(emit, event.nextViewIndex); | ||
break; | ||
case 4: | ||
navigate(emit, event.nextViewIndex); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void navigate(Emitter<ProposalCreationState> emit, int nextIndex) { | ||
emit(state.copyWith(currentViewIndex: nextIndex)); | ||
_pageController.animateToPage( | ||
nextIndex, | ||
duration: const Duration(milliseconds: 200), | ||
curve: Curves.easeInOut, | ||
); | ||
} | ||
|
||
Future<void> _updateProposal(_UpdateProposal event, Emitter<ProposalCreationState> emit) async { | ||
final ProposalCreationModel? proposal = state.proposal?.copyWith(event.updates); | ||
if (proposal != null) { | ||
emit(state.copyWith(proposal: proposal)); | ||
} | ||
} | ||
} |
Oops, something went wrong.