fetchModel method
dynamic
fetchModel({})
Implementation
fetchModel({
BuildContext? context,
String? serviceName,
Function? dispatcher,
String? modelsName,
bool showDialog = true,
bool closeDialog = true,
bool showNotification = true,
bool allowRetry = false,
Function? onFetchComplete,
}) async {
bool isInternet = await SystemRF.network.hasInternet();
if (!isInternet) {
rf.msg(context!, 'Please turn on your internet connection');
return;
}
currentPage = 1;
pages = '';
totalRecord = 0;
completedPages = [];
isOldDelete = '';
showNotify = showNotification ? '1' : '';
pageSize = Libs.config.data.pageSize!;
fetchRequest['PageSize'] = pageSize;
if (modelsName == null) {
Models modelList = new Models();
for (var entry in modelList.get().entries) {
var modelRF = entry.value as ModelRF;
if (modelRF.syncable) {
if (modelsName == null)
modelsName = modelRF.model.runtimeType.toString();
else
modelsName = modelsName.toString() +
"," +
modelRF.model.runtimeType.toString();
}
}
}
_onAccept() async {
Map<String, dynamic> inputData = Map();
inputData['Model'] = modelsName;
pdlg = ProgressDialog(context!,
type: ProgressDialogType.download, isDismissible: true);
//_fetchWithoutService(context, modelsName, onFetchComplete);
if (dispatcher != null && !Platform.isIOS) {
await _fetchWithService(serviceName!, context, dispatcher, inputData,
modelsName!, showDialog);
} else {
_fetchWithoutService(
serviceName!, context, modelsName, onFetchComplete, showDialog);
}
}
rf.pref!.setBool('AdminNotify', showNotification);
if (showDialog) {
DialogRF(
context!,
height: 100,
title: 'Download Data',
subTitle: 'Download old data from server.',
avatarIcon: Icons.cloud_download,
type: DialogType.popup,
body: Padding(
padding: EdgeInsets.only(top: 20),
child: CheckRF(
height: 60,
data: [
RadioCheckData(
label:
'Do you want to delete local data before downloading server data?',
value: 0,
)
],
onChange: (val) => isOldDelete = val,
),
),
onAccept: () async {
await _onAccept();
},
);
} else {
isOldDelete = "1";
await _onAccept();
}
}