Created
February 11, 2021 10:08
-
-
Save Abdulsametileri/02b044c0ca9e58b362efe213d44d3df8 to your computer and use it in GitHub Desktop.
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
import 'package:infinite_scroll/service/card_service_interface.dart'; | |
import 'package:mobx/mobx.dart'; | |
import '../model/card_model.dart'; | |
import '../service/card_service.dart'; | |
import '../model/pagination_model.dart'; | |
part 'cards_view_model.g.dart'; | |
class CardsViewModel = _CardsViewModel with _$CardsViewModel; | |
abstract class _CardsViewModel with Store { | |
CardServiceInterface _service; | |
bool isFetchData = false; | |
int _page = 1; | |
int _limit = 5; | |
void init() { | |
_service = CardService(); | |
} | |
ObservableList<CardModel> cards = ObservableList<CardModel>(); | |
Future fetchCards() async { | |
if (isFetchData) { | |
return; | |
} | |
isFetchData = true; | |
print(_page); | |
var paginate = PaginationModel(page: _page, limit: _limit); | |
var res = await _service.fetchCards(paginate); | |
if (res != null && res.isNotEmpty) { | |
cards.addAll(res); | |
_page++; | |
} | |
isFetchData = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment