Skip to content

Instantly share code, notes, and snippets.

@Abdulsametileri
Created February 11, 2021 10:08
Show Gist options
  • Save Abdulsametileri/02b044c0ca9e58b362efe213d44d3df8 to your computer and use it in GitHub Desktop.
Save Abdulsametileri/02b044c0ca9e58b362efe213d44d3df8 to your computer and use it in GitHub Desktop.
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