-
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.
- Loading branch information
1 parent
095ac10
commit eb63b27
Showing
11 changed files
with
538 additions
and
14 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
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,20 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:hypha_wallet/core/network/models/proposal_model.dart'; | ||
import 'package:hypha_wallet/ui/proposals/list/components/hypha_proposals_action_card.dart'; | ||
|
||
class ProposalsList extends StatelessWidget { | ||
final List<ProposalModel> proposals; | ||
|
||
const ProposalsList(this.proposals, {super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListView.separated( | ||
padding: const EdgeInsets.only(bottom: 22), | ||
itemBuilder: (BuildContext context, int index) => HyphaProposalsActionCard(proposals[index]), | ||
separatorBuilder: (BuildContext context, int index) { | ||
return const SizedBox(height: 16); | ||
}, | ||
itemCount: proposals.length); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
lib/ui/proposals/history/components/proposals_history_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,35 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:hypha_wallet/design/hypha_colors.dart'; | ||
import 'package:hypha_wallet/ui/proposals/components/proposals_list.dart'; | ||
import 'package:hypha_wallet/ui/proposals/history/interactor/proposals_history_bloc.dart'; | ||
import 'package:hypha_wallet/ui/shared/hypha_body_widget.dart'; | ||
|
||
class ProposalsHistoryView extends StatelessWidget { | ||
const ProposalsHistoryView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
backgroundColor: context.isDarkMode ? HyphaColors.darkBlack : HyphaColors.offWhite, | ||
appBar: AppBar( | ||
title: const Text('Proposals History'), | ||
), | ||
body: RefreshIndicator( | ||
onRefresh: () async { | ||
context.read<ProposalsHistoryBloc>().add(const ProposalsHistoryEvent.initial(refresh: true)); | ||
}, | ||
child: BlocBuilder<ProposalsHistoryBloc, ProposalsHistoryState>( | ||
builder: (context, state) { | ||
return HyphaBodyWidget(pageState: state.pageState, success: (context) { | ||
return Container( | ||
padding: const EdgeInsets.all(20), | ||
child: ProposalsList(state.proposals), | ||
); | ||
}); | ||
}), | ||
) | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/ui/proposals/history/interactor/proposals_history_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,39 @@ | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:hypha_wallet/core/error_handler/error_handler_manager.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/proposal_model.dart'; | ||
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart'; | ||
import 'package:hypha_wallet/ui/architecture/result/result.dart'; | ||
import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_status.dart'; | ||
import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case.dart'; | ||
|
||
part 'proposals_history_bloc.freezed.dart'; | ||
part 'proposals_history_event.dart'; | ||
part 'proposals_history_state.dart'; | ||
|
||
class ProposalsHistoryBloc extends Bloc<ProposalsHistoryEvent, ProposalsHistoryState> { | ||
final GetProposalsUseCase _getProposalsUseCase; | ||
final ErrorHandlerManager _errorHandlerManager; | ||
final DaoData _dao; | ||
|
||
ProposalsHistoryBloc(this._getProposalsUseCase, this._errorHandlerManager, this._dao) : super(const ProposalsHistoryState()) { | ||
on<_Initial>(_initial); | ||
} | ||
|
||
Future<void> _initial(_Initial event, Emitter<ProposalsHistoryState> emit) async { | ||
if (!event.refresh) { | ||
emit(state.copyWith(pageState: PageState.loading)); | ||
} | ||
|
||
final Result<List<ProposalModel>, HyphaError> proposalsResult = await _getProposalsUseCase.run([_dao], FilterStatus.past); | ||
|
||
if (proposalsResult.isValue) { | ||
emit(state.copyWith(pageState: PageState.success, proposals: proposalsResult.asValue!.value)); | ||
} else { | ||
await _errorHandlerManager.handlerError(proposalsResult.asError!.error); | ||
emit(state.copyWith(pageState: PageState.failure)); | ||
} | ||
} | ||
} |
Oops, something went wrong.