mobileApplicationsKonectarApp/lib/viewmodel/configprovider.dart

93 lines
3.5 KiB
Dart
Raw Normal View History

2024-01-04 07:06:37 +00:00
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.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:permission_handler/permission_handler.dart';
import 'package:file_picker/file_picker.dart';
class ConfigDataProvider extends ChangeNotifier {
Future<void> initConfigUIData() async {
// dynamic jsonResult = await MockApiCall().getConfigData();
List<InteractionConfigData> interactionConfigData = [];
// interactionConfigData = await fetchInteactionConfigData();
//interactionConfigData = fetchInteactionUIConfigData(jsonResult);
interactionConfigData = await fetchLocalInteactionConfigData();
var 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 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(jsonResult2c2);
for (InteractionResultData obj in responseData.data) {
// InteractionResultData interactionConfigc2 =
// InteractionResultData.fromJson(obj);
interactionConfigData.add(
// InteractionConfigData(
// dataSet: interactionDataSet,
// widgets: interactionConfig,
// id: "IN01",
// name: "InteractionForm1"));
// interactionConfigData.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;
// }
}