Skip to content

Commit

Permalink
🎉 tada: Complete Add Coin History (#273)
Browse files Browse the repository at this point in the history
* Add coin and coin history model

* Add preview coin

* Add coin history bloc

* Add coin history listing

* Complete coin history ui and logic
  • Loading branch information
tvc12 authored Jun 26, 2020
1 parent 7f53a1c commit 5c7bf9f
Show file tree
Hide file tree
Showing 24 changed files with 501 additions and 112 deletions.
1 change: 1 addition & 0 deletions lib/module/dev_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class DevModule extends AbstractModule {
bind(MyPostBloc).to(MyPostBloc());
bind(FavoritePostBloc).to(FavoritePostBloc());
bind(RescueListingBloc).to(RescueListingBloc());
bind(CoinHistoryBloc).to(CoinHistoryBloc());
}
}
8 changes: 6 additions & 2 deletions lib/pet_feed/widget/post/post_money_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class PostMoneyWidget extends StatelessWidget {
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
if (money != null && money > 0) {
FlutterMoneyFormatter formatter = FlutterMoneyFormatter(amount: money);
return Text(
'${formatter.output.withoutFractionDigits} $typeMoney',
'${formatMoney(money)} $typeMoney',
style: _buildTextStyle(theme),
overflow: TextOverflow.ellipsis,
);
Expand All @@ -39,3 +38,8 @@ class PostMoneyWidget extends StatelessWidget {
);
}
}

String formatMoney(double money) {
FlutterMoneyFormatter formatter = FlutterMoneyFormatter(amount: money);
return formatter.output.withoutFractionDigits;
}
1 change: 0 additions & 1 deletion lib/post/post_detail/widget/widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library petisland.post.screen.widget;

import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/profile/bloc/bloc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library petisland.profile.bloc;

export 'coin_history/coin_history.dart';
export 'favorite_post/favorite_post.dart';
export 'my_post/my_post.dart';
9 changes: 9 additions & 0 deletions lib/profile/bloc/coin_history/coin_history.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library petisland.profile.bloc.coin_history;

import 'package:ddi/ddi.dart';
import 'package:flutter_template/main_bloc/main_bloc.dart';
import 'package:petisland_core/petisland_core.dart';

part 'coin_history_bloc.dart';
part 'coin_history_event.dart';
part 'coin_history_state.dart';
46 changes: 46 additions & 0 deletions lib/profile/bloc/coin_history/coin_history_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
part of petisland.profile.bloc.coin_history;

class CoinHistoryBloc extends TBloc<CoinHistoryEvent, CoinHistoryState> {
final coinHistories = <CoinHistory>[];
@override
Stream<CoinHistoryState> errorToState(BaseErrorEvent event) async* {}

@override
Stream<CoinHistoryState> eventToState(BaseEvent event) async* {
switch (event.runtimeType) {
case LoadCoinHistory:
final loadCoinHistoryEvent = event as LoadCoinHistory;
yield* _loadCoinHistory(
from: loadCoinHistoryEvent.from,
limit: loadCoinHistoryEvent.limit,
clearOldData: loadCoinHistoryEvent.clearOldData,
);
break;
default:
}
}

@override
CoinHistoryState get initialState => ReloadCoinHisotryListing(true);

Stream<CoinHistoryState> _loadCoinHistory(
{int from, int limit, bool clearOldData}) async* {
final accountService =
DI.get<AccountService>(DevModuleCore.account_service_authenticated);
final coinHistories = await accountService.getCoinHistory(from, limit);
if (coinHistories.isNotEmpty) {
if (clearOldData == true) this.coinHistories.clear();
this.coinHistories.addAll(coinHistories);
yield ReloadCoinHisotryListing(true);
} else
yield ReloadCoinHisotryListing(false);
}

void loadMore() {
add(LoadCoinHistory(from: coinHistories.length));
}

void refresh() {
add(LoadCoinHistory(from: 0, clearOldData: true));
}
}
11 changes: 11 additions & 0 deletions lib/profile/bloc/coin_history/coin_history_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
part of petisland.profile.bloc.coin_history;

abstract class CoinHistoryEvent extends BaseEvent {}

class LoadCoinHistory extends CoinHistoryEvent {
final int from;
final int limit;
final bool clearOldData;

LoadCoinHistory({this.clearOldData = false, this.from = 0, this.limit = 10});
}
9 changes: 9 additions & 0 deletions lib/profile/bloc/coin_history/coin_history_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
part of petisland.profile.bloc.coin_history;

abstract class CoinHistoryState extends BaseState {}

class ReloadCoinHisotryListing extends CoinHistoryState {
final bool canLoadMore;

ReloadCoinHisotryListing(this.canLoadMore);
}
28 changes: 28 additions & 0 deletions lib/profile/screen/coin_history_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
part of petisland.profile.screen;

class CoinHistoryScreen extends StatelessWidget {
static const String name = '/CoinHistoryScreen';
final CoinHistoryBloc coinHistoryBloc = DI.get(CoinHistoryBloc);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Coin History',
style: TTextStyles.bold(
fontSize: 18,
color: TColors.white,
),
),
centerTitle: true,
elevation: 1,
automaticallyImplyLeading: false,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios, color: TColors.white),
onPressed: () => Navigator.pop(context),
),
),
body: CoinHistoryListingWidget(bloc: coinHistoryBloc),
);
}
}
2 changes: 1 addition & 1 deletion lib/profile/screen/favorite_post_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class _FavoritePostScreenState extends State<FavoritePostScreen> {
onPressed: () => Navigator.pop(context),
),
),
body: FavoritePostComponent(),
body: FavoritePostWidget(),
);
}
}
Loading

0 comments on commit 5c7bf9f

Please sign in to comment.