56 lines
1.4 KiB
Dart
56 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
|
import 'package:get/get_state_manager/src/simple/get_controllers.dart';
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
import 'package:sk_base_mobile/models/base_search_more.model.dart';
|
|
|
|
class BaseSearchMoreController<T extends BaseSearchMoreModel>
|
|
extends GetxController {
|
|
RxList<T> list = RxList([]);
|
|
RxString searchKey = ''.obs;
|
|
final searchBarTextConroller = TextEditingController();
|
|
RefreshController refreshController =
|
|
RefreshController(initialRefresh: false);
|
|
int page = 1;
|
|
int limit = 15;
|
|
int total = 0;
|
|
RxList<int> selectedIndex = RxList([]);
|
|
final loading = false.obs;
|
|
getData({bool isRefresh = false}) {}
|
|
|
|
@override
|
|
onReady() {
|
|
super.onReady();
|
|
initData();
|
|
}
|
|
|
|
initData() async {
|
|
loading.value = true;
|
|
try {
|
|
await getData(isRefresh: true);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
Future<void> onRefresh() async {
|
|
await getData(isRefresh: true).then((_) {
|
|
refreshController.refreshCompleted(resetFooterState: true);
|
|
}).catchError((_) {
|
|
refreshController.refreshFailed();
|
|
});
|
|
}
|
|
|
|
Future<void> onLoading() async {
|
|
await getData().then((_) {
|
|
if (_.isEmpty) {
|
|
refreshController.loadNoData();
|
|
} else {
|
|
refreshController.loadComplete();
|
|
}
|
|
}).catchError((_) {
|
|
refreshController.loadFailed();
|
|
});
|
|
}
|
|
}
|