mobileApplicationsKonectarApp/lib/viewmodel/configprovider.dart

94 lines
3.6 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:pwa_ios/model/interaction_config_data.dart';
import 'package:pwa_ios/model/interaction_data.dart';
import 'package:pwa_ios/utils/mockapi.dart';
import 'package:pwa_ios/utils/util.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
class ConfigDataProvider extends ChangeNotifier {
Future<void> initConfigUIData() async {
List<InteractionConfigData> interactionConfigData = [];
// interactionConfigData = await fetchInteactionConfigData();
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
if (await InternetConnectionChecker().hasConnection) {
interactionConfigData = await fetchLocalInteactionConfigData();
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();
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();
// dynamic jsonResultc2 = jsonDecode(
// await rootBundle.loadString("assets/images/interactiondatac2.json"));
// // for (var value in jsonResult) {
// InteractionDataSet interactionDataSet2 =
// InteractionDataSet.fromJson(jsonResultc2);
// dynamic jsonResult2 = jsonDecode(
// await rootBundle.loadString("assets/images/interactionform.json"));
// dynamic jsonResult2c2 = jsonDecode(
// await rootBundle.loadString("assets/images/newconfigdata.json"));
List<InteractionConfigData> interactionConfigData = [];
// for (var value in jsonResult) {
// InteractionResultData interactionConfig =
// InteractionResultData.fromJson(jsonResult2);
ResponseData responseData = ResponseDataFromJson(jsonResult);
for (InteractionResultData obj in responseData.data) {
// InteractionResultData interactionConfigc2 =
// InteractionResultData.fromJson(obj);
interactionConfigData.add(
// InteractionConfigData(
// dataSet: interactionDataSet,
// widgets: interactionConfig,
// id: "IN01",
// name: "InteractionForm1"));
// inte ractionConfigData.add(
InteractionConfigData(widgets: obj, id: obj.id, name: obj.name));
}
return interactionConfigData;
}
// List<InteractionConfigData> fetchInteactionUIConfigData(UIDataResponse data) {
// //final data = json.decode(jsonResult);
// InteractionDataSet interactionDataSet =
// InteractionDataSet(data: data.formAttr);
// InteractionResultData interactionConfig =
// InteractionResultData(result: data.formFields, id: data.id , name: '');
// List<InteractionConfigData> interactionConfigData = [];
// interactionConfigData.add(InteractionConfigData(
// dataSet: interactionDataSet,
// widgets: interactionConfig,
// id: "IN01",
// name: "InteractionForm1"));
// return interactionConfigData;
// }
}