-
Notifications
You must be signed in to change notification settings - Fork 58
fix: Removed network call to backend server when transitioning from "Member Profile" to "Send Request" screen. #138
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ import './bloc.dart'; | |
class MembersPageBloc extends Bloc<MembersPageEvent, MembersPageState> { | ||
final UserRepository userRepository; | ||
int pageNumber = 1; | ||
MembersPageBloc({@required this.userRepository}) : assert(userRepository != null); | ||
MembersPageBloc({@required this.userRepository}) | ||
: assert(userRepository != null); | ||
@override | ||
MembersPageState get initialState => MembersPageInitial(); | ||
|
||
|
@@ -25,47 +26,66 @@ class MembersPageBloc extends Bloc<MembersPageEvent, MembersPageState> { | |
} | ||
} | ||
|
||
Stream<MembersPageState> _mapEventToMembersShowed(MembersPageEvent event) async* { | ||
Stream<MembersPageState> _mapEventToMembersShowed( | ||
MembersPageEvent event) async* { | ||
final currentState = state; | ||
|
||
if (event is MembersPageShowed && !_hasReachedMax(currentState)) { | ||
try { | ||
if (currentState is MembersPageInitial) { | ||
yield MembersPageLoading(); | ||
final List<User> users = await userRepository.getVerifiedUsers(pageNumber); | ||
yield MembersPageSuccess(users: users, hasReachedMax: false); | ||
final List<User> users = | ||
await userRepository.getVerifiedUsers(pageNumber); | ||
final User currentUser = await userRepository.getCurrentUser(); | ||
yield MembersPageSuccess( | ||
users: users, | ||
hasReachedMax: false, | ||
currentUser: currentUser, | ||
); | ||
} | ||
if (currentState is MembersPageSuccess) { | ||
final users = | ||
await userRepository.getVerifiedUsers((currentState.users.length ~/ 10) + 1); | ||
final users = await userRepository | ||
.getVerifiedUsers((currentState.users.length ~/ 10) + 1); | ||
final User currentUser = await userRepository.getCurrentUser(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yashhalgaonkar I'm talking about this line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the event added when the user scrolls to the end of the page to load more users There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I am looking into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I use sqflite to store the current user info in local storage? This will make it easy to get current user info in all other parts of app as well, solving the problem once and for all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, give it a try |
||
yield users.isEmpty | ||
? currentState.copyWith(hasReachedMax: true) | ||
: MembersPageSuccess( | ||
users: currentState.users + users, | ||
hasReachedMax: false, | ||
currentUser: currentUser, | ||
); | ||
} | ||
} on Failure catch (failure) { | ||
Logger.root.severe("MembersPageBloc: Failure catched: $failure.message"); | ||
Logger.root | ||
.severe("MembersPageBloc: Failure catched: $failure.message"); | ||
yield MembersPageFailure(failure.message); | ||
} | ||
} | ||
} | ||
|
||
Stream<MembersPageState> _mapEventToMembersRefresh(MembersPageEvent event) async* { | ||
Stream<MembersPageState> _mapEventToMembersRefresh( | ||
MembersPageEvent event) async* { | ||
final currentState = state; | ||
|
||
if (event is MembersPageRefresh) { | ||
try { | ||
yield MembersPageLoading(); | ||
final List<User> users = await userRepository.getVerifiedUsers(pageNumber); | ||
yield MembersPageSuccess(users: users, hasReachedMax: false); | ||
final List<User> users = | ||
await userRepository.getVerifiedUsers(pageNumber); | ||
final User currentUser = await userRepository.getCurrentUser(); | ||
yield MembersPageSuccess( | ||
users: users, | ||
hasReachedMax: false, | ||
currentUser: currentUser, | ||
); | ||
} on Failure catch (failure) { | ||
Logger.root.severe("MembersPageBloc: Failure catched: $failure.message"); | ||
Logger.root | ||
.severe("MembersPageBloc: Failure catched: $failure.message"); | ||
yield state; | ||
} | ||
} | ||
} | ||
} | ||
|
||
bool _hasReachedMax(MembersPageState state) => state is MembersPageSuccess && state.hasReachedMax; | ||
bool _hasReachedMax(MembersPageState state) => | ||
state is MembersPageSuccess && state.hasReachedMax; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This network call will be made when the state is MembersPageInitial. This is a necessary call.