generated from tvc12/flutter_template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 tada: Complete Add Coin History (#273)
* 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
Showing
24 changed files
with
501 additions
and
112 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
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 |
---|---|---|
@@ -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'; |
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,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'; |
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,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)); | ||
} | ||
} |
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,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}); | ||
} |
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,9 @@ | ||
part of petisland.profile.bloc.coin_history; | ||
|
||
abstract class CoinHistoryState extends BaseState {} | ||
|
||
class ReloadCoinHisotryListing extends CoinHistoryState { | ||
final bool canLoadMore; | ||
|
||
ReloadCoinHisotryListing(this.canLoadMore); | ||
} |
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,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), | ||
); | ||
} | ||
} |
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
Oops, something went wrong.