222 lines
8.1 KiB
Dart
222 lines
8.1 KiB
Dart
|
import 'package:discover_module/ui_screen/interactionform/NewtworkConnectivity.dart';
|
||
|
import 'package:discover_module/ui_screen/interactionform/mockapi.dart';
|
||
|
import 'package:discover_module/ui_screen/interactionform/model/interaction_config_data.dart';
|
||
|
import 'package:discover_module/ui_screen/interactionform/model/interaction_data.dart';
|
||
|
import 'package:discover_module/ui_screen/interactionform/util.dart';
|
||
|
import 'package:flutter/foundation.dart';
|
||
|
import 'package:hive_flutter/hive_flutter.dart';
|
||
|
|
||
|
class ConfigDataProvider extends ChangeNotifier {
|
||
|
Future<void> initConfigUIData() async {
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
// interactionConfigData = await fetchInteactionConfigData();
|
||
|
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
|
||
|
NetworkConnectivity networkConnectivity = NetworkConnectivity();
|
||
|
bool isOnline = await networkConnectivity.isInternetAvailable();
|
||
|
|
||
|
print("Checkonline: $isOnline");
|
||
|
if (isOnline) {
|
||
|
interactionConfigData = await fetchLocalInteactionConfigData();
|
||
|
print("interactionConfigData_is $interactionConfigData");
|
||
|
var box = Hive.box<InteractionConfigData>('InteractionConfigDataBox');
|
||
|
|
||
|
if (!box.isOpen) {
|
||
|
box = await Hive.openBox<InteractionConfigData>(
|
||
|
'InteractionConfigDataBox');
|
||
|
}
|
||
|
|
||
|
if (box.isEmpty) {
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
} else {
|
||
|
box.clear();
|
||
|
print("IamELse");
|
||
|
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
Future<List<InteractionConfigData>> fetchLocalInteactionConfigData() async {
|
||
|
// dynamic jsonResult = jsonDecode(
|
||
|
// await rootBundle.loadString("assets/images/interactiondata.json"));
|
||
|
dynamic jsonResult = await MockApiCall().getConfigData();
|
||
|
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
|
||
|
ResponseData responseData = ResponseDataFromJson(jsonResult);
|
||
|
print('Response_data_is: $responseData');
|
||
|
print('Response_data_dta_is: ${responseData.data}');
|
||
|
|
||
|
for (InteractionResultData obj in responseData.data) {
|
||
|
interactionConfigData
|
||
|
.add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name));
|
||
|
}
|
||
|
print("interactionConfigData_issss: ${interactionConfigData.length}");
|
||
|
return interactionConfigData;
|
||
|
}
|
||
|
|
||
|
//pooja
|
||
|
|
||
|
Future<void> initConfigUIData123() async {
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
// interactionConfigData = await fetchInteactionConfigData();
|
||
|
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
|
||
|
NetworkConnectivity networkConnectivity = NetworkConnectivity();
|
||
|
bool isOnline = await networkConnectivity.isInternetAvailable();
|
||
|
if (isOnline) {
|
||
|
interactionConfigData = await fetchLocalInteactionConfigData123();
|
||
|
var box = Hive.box<InteractionConfigData>('InteractionConfigDataBox');
|
||
|
|
||
|
if (!box.isOpen) {
|
||
|
box = await Hive.openBox<InteractionConfigData>(
|
||
|
'InteractionConfigDataBox');
|
||
|
}
|
||
|
|
||
|
if (box.isEmpty) {
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
} else {
|
||
|
box.clear();
|
||
|
print("IamELse");
|
||
|
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
Future<List<InteractionConfigData>>
|
||
|
fetchLocalInteactionConfigData123() async {
|
||
|
// dynamic jsonResult = jsonDecode(
|
||
|
// await rootBundle.loadString("assets/images/interactiondata.json"));
|
||
|
dynamic jsonResult = await MockApiCall().getConfigData123();
|
||
|
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
|
||
|
ResponseData responseData = ResponseDataFromJson(jsonResult);
|
||
|
print('Response_data_is: $responseData');
|
||
|
print('Response_data_dta_is: ${responseData.data}');
|
||
|
|
||
|
for (InteractionResultData obj in responseData.data) {
|
||
|
interactionConfigData
|
||
|
.add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name));
|
||
|
}
|
||
|
print("interactionConfigData_issss: ${interactionConfigData.length}");
|
||
|
return interactionConfigData;
|
||
|
}
|
||
|
|
||
|
Future<void> initConfigUIDataMedical() async {
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
// interactionConfigData = await fetchInteactionConfigData();
|
||
|
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
|
||
|
|
||
|
NetworkConnectivity networkConnectivity = NetworkConnectivity();
|
||
|
bool isOnline = await networkConnectivity.isInternetAvailable();
|
||
|
if (isOnline) {
|
||
|
// if (await InternetConnectionChecker().hasConnection) {
|
||
|
interactionConfigData = await fetchLocalInteactionConfigDataMedical();
|
||
|
var box = Hive.box<InteractionConfigData>('InteractionConfigDataBox');
|
||
|
|
||
|
if (!box.isOpen) {
|
||
|
box = await Hive.openBox<InteractionConfigData>(
|
||
|
'InteractionConfigDataBox');
|
||
|
}
|
||
|
|
||
|
if (box.isEmpty) {
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
} else {
|
||
|
box.clear();
|
||
|
print("IamELse");
|
||
|
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
Future<List<InteractionConfigData>>
|
||
|
fetchLocalInteactionConfigDataMedical() async {
|
||
|
// dynamic jsonResult = jsonDecode(
|
||
|
// await rootBundle.loadString("assets/images/interactiondata.json"));
|
||
|
dynamic jsonResult = await MockApiCall().getConfigDataMedical();
|
||
|
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
|
||
|
ResponseData responseData = ResponseDataFromJson(jsonResult);
|
||
|
print('Response_data_is: $responseData');
|
||
|
print('Response_data_dta_is: ${responseData.data}');
|
||
|
|
||
|
for (InteractionResultData obj in responseData.data) {
|
||
|
interactionConfigData
|
||
|
.add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name));
|
||
|
}
|
||
|
print("interactionConfigData_issss: ${interactionConfigData.length}");
|
||
|
return interactionConfigData;
|
||
|
}
|
||
|
|
||
|
Future<void> initConfigUIDataEng() async {
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
// interactionConfigData = await fetchInteactionConfigData();
|
||
|
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
|
||
|
// if (await InternetConnectionChecker().hasConnection) {
|
||
|
|
||
|
NetworkConnectivity networkConnectivity = NetworkConnectivity();
|
||
|
bool isOnline = await networkConnectivity.isInternetAvailable();
|
||
|
if (isOnline) {
|
||
|
interactionConfigData = await fetchLocalInteactionConfigDataEng();
|
||
|
var box = Hive.box<InteractionConfigData>('InteractionConfigDataBox');
|
||
|
|
||
|
if (!box.isOpen) {
|
||
|
box = await Hive.openBox<InteractionConfigData>(
|
||
|
'InteractionConfigDataBox');
|
||
|
}
|
||
|
|
||
|
if (box.isEmpty) {
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
} else {
|
||
|
box.clear();
|
||
|
print("IamELse");
|
||
|
|
||
|
for (InteractionConfigData data in interactionConfigData) {
|
||
|
box.put(await getNextAutoIncrementValue(), data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
notifyListeners();
|
||
|
}
|
||
|
|
||
|
Future<List<InteractionConfigData>>
|
||
|
fetchLocalInteactionConfigDataEng() async {
|
||
|
// dynamic jsonResult = jsonDecode(
|
||
|
// await rootBundle.loadString("assets/images/interactiondata.json"));
|
||
|
dynamic jsonResult = await MockApiCall().getConfigDataEng();
|
||
|
|
||
|
List<InteractionConfigData> interactionConfigData = [];
|
||
|
|
||
|
ResponseData responseData = ResponseDataFromJson(jsonResult);
|
||
|
print('Response_data_is: $responseData');
|
||
|
print('Response_data_dta_is: ${responseData.data}');
|
||
|
|
||
|
for (InteractionResultData obj in responseData.data) {
|
||
|
interactionConfigData
|
||
|
.add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name));
|
||
|
}
|
||
|
print("interactionConfigData_issss: ${interactionConfigData.length}");
|
||
|
return interactionConfigData;
|
||
|
}
|
||
|
}
|