api constants stored in hive #5

Merged
snehalathad merged 1 commits from snehalatha_dev into dev 2024-12-10 09:37:40 +00:00
12 changed files with 473 additions and 85 deletions

80
assets/api_constants.json Normal file
View File

@ -0,0 +1,80 @@
[
{
"api": "loadFutureEvents",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "saveUserInterestedEvent",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "saveUserAttendingEvent",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "getSpecialitiesDonutChart",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "getTopicCloudChart",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "getTopAffiliationBarChart",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "eventSpeakers",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "saveEventsTopicNote",
"interval": 5,
"method": "POST",
"module": "eventapis"
},
{
"api": "eventUserAnalytics",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "saveEventOffline",
"interval": 0,
"method": "POST",
"module": "eventapis"
},
{
"api": "contactslistapi",
"interval": 5,
"method": "POST",
"module": "contactsapi"
},
{
"api": "saveContactsOffline",
"interval": 0,
"method": "POST",
"module": "contactsapi"
},
{
"api": "saveInteraction",
"interval": 0,
"method": "POST",
"module": "contactsapi"
}
]

View File

@ -64,6 +64,7 @@ import 'package:konectar_events/contacts_module/ui_screen/interactionform/model/
import 'package:konectar_events/contacts_module/ui_screen/interactionform/repository/hive_repository.dart';
import 'package:konectar_events/contacts_module/ui_screen/interactionform/viewinteractionprovider.dart';
import 'package:konectar_events/firebaseexample.dart';
import 'package:konectar_events/model/hive_api_constants.dart';
import 'package:konectar_events/model/myeventsmodel.dart';
import 'package:konectar_events/model/neweventsmodel.dart';
import 'package:konectar_events/model/sessionnotesmodel.dart';
@ -175,11 +176,13 @@ Future main() async {
Hive.registerAdapter(ProAdapter());
Hive.registerAdapter(Training1Adapter());
Hive.registerAdapter(SpeAdapter());
Hive.registerAdapter(HiveApiConstantsAdapter());
await Hive.openBox<UserData>("UserDataBox");
await Hive.openBox<EventsList>("EventsListBox");
await Hive.openBox<SessionNotesModel>("SessionNotesModelBox");
await Hive.openBox<MyEventsModel>("MyEventsBox");
await Hive.openBox<HiveApiConstants>("hiveApiConstants");
WidgetsFlutterBinding.ensureInitialized();
// FirebaseMessaging.instance.getToken().then((value) {
@ -259,38 +262,34 @@ Future main() async {
],
child: SafeArea(
top: true,
child: new OverlaySupport.global(
toastTheme: ToastThemeData(background: Colors.green),
child: MaterialApp(
theme: ThemeData(
//fontFamily: "SourceSerif",
),
debugShowCheckedModeBanner: false,
title: 'Dynamic Links Example',
initialRoute: '/',
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => FutureBuilder<bool>(
future: SessionManager().isLoggedIn(),
builder: (context, snapshot) {
print("Data_is : $snapshot");
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
final isLoggedIn = snapshot.data ?? false;
print("isLoggedIn_is : $isLoggedIn");
print("secret : $secretkey");
return isLoggedIn
? IntroductionAnimationScreen()
: IntroductionAnimationScreen();
}
},
), //userInfo != null ? const Home() : OpenidScreen(credential: credential,),
// '/details': (BuildContext context) => const HomeScreen(),
},
),
child: MaterialApp(
theme: ThemeData(
//fontFamily: "SourceSerif",
),
debugShowCheckedModeBanner: false,
title: 'Dynamic Links Example',
initialRoute: '/',
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => FutureBuilder<bool>(
future: SessionManager().isLoggedIn(),
builder: (context, snapshot) {
print("Data_is : $snapshot");
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
final isLoggedIn = snapshot.data ?? false;
print("isLoggedIn_is : $isLoggedIn");
print("secret : $secretkey");
return isLoggedIn
? IntroductionAnimationScreen()
: IntroductionAnimationScreen();
}
},
), //userInfo != null ? const Home() : OpenidScreen(credential: credential,),
// '/details': (BuildContext context) => const HomeScreen(),
},
),
),
),

View File

@ -0,0 +1,62 @@
// To parse this JSON data, do
//
// final apiConstantsResponse = apiConstantsResponseFromJson(jsonString);
import 'dart:convert';
List<ApiConstantsResponse> apiConstantsResponseFromJson(List<dynamic> json) =>
List<ApiConstantsResponse>.from(
json.map((x) => ApiConstantsResponse.fromJson(x)));
String apiConstantsResponseToJson(List<ApiConstantsResponse> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class ApiConstantsResponse {
String? api;
int? interval;
String? method;
String? module;
ApiConstantsResponse({
this.api,
this.interval,
this.method,
this.module,
});
factory ApiConstantsResponse.fromJson(Map<String, dynamic> json) =>
ApiConstantsResponse(
api: json["api"],
interval: json["interval"],
method: json["method"],
module: json["module"],
);
Map<String, dynamic> toJson() => {
"api": api,
"interval": interval,
"method": method,
"module": module,
};
}
enum Method { POST }
final methodValues = EnumValues({"POST": Method.POST});
enum Module { CONTACTSAPI, EVENTAPIS }
final moduleValues = EnumValues(
{"contactsapi": Module.CONTACTSAPI, "eventapis": Module.EVENTAPIS});
class EnumValues<T> {
Map<String, T> map;
late Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
reverseMap = map.map((k, v) => MapEntry(v, k));
return reverseMap;
}
}

View File

@ -1,5 +1,6 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:konectar_events/utils/hivetypeids.dart';
part 'hive_api_constants.g.dart';
@HiveType(typeId: HiveTypeIdConstants.hiveApiConstantsId)
class HiveApiConstants {
@ -7,6 +8,11 @@ class HiveApiConstants {
String? functionName;
@HiveField(1)
int? interval;
@HiveField(2)
String? method;
@HiveField(3)
String? module;
HiveApiConstants({this.functionName, this.interval});
HiveApiConstants(
{this.functionName, this.interval, this.method, this.module});
}

View File

@ -0,0 +1,50 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'hive_api_constants.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class HiveApiConstantsAdapter extends TypeAdapter<HiveApiConstants> {
@override
final int typeId = 106;
@override
HiveApiConstants read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HiveApiConstants(
functionName: fields[0] as String?,
interval: fields[1] as int?,
)
..method = fields[2] as String?
..module = fields[3] as String?;
}
@override
void write(BinaryWriter writer, HiveApiConstants obj) {
writer
..writeByte(4)
..writeByte(0)
..write(obj.functionName)
..writeByte(1)
..write(obj.interval)
..writeByte(2)
..write(obj.method)
..writeByte(3)
..write(obj.module);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HiveApiConstantsAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -7,6 +7,7 @@ import 'package:dio/io.dart';
import 'package:flutter/services.dart';
import 'package:konectar_events/model/affiliationsmodel.dart';
import 'package:konectar_events/model/allsessionnotesmodel.dart';
import 'package:konectar_events/model/api_constants_model.dart';
import 'package:konectar_events/model/events_details.dart';
import 'package:konectar_events/model/events_list_resp_2.dart';
import 'package:konectar_events/model/events_speakers_k1.dart';
@ -14,6 +15,7 @@ import 'package:konectar_events/model/eventsdetailmodel.dart';
import 'package:konectar_events/model/eventsmodel.dart';
import 'package:konectar_events/model/eventsoverview.dart';
import 'package:konectar_events/model/eventspeakers.dart';
import 'package:konectar_events/model/hive_api_constants.dart';
import 'package:konectar_events/model/keywords_model.dart';
import 'package:konectar_events/model/neweventsmodel.dart';
import 'package:konectar_events/model/scope_model.dart';
@ -22,6 +24,7 @@ import 'package:konectar_events/model/sessionstopics_model.dart';
import 'package:konectar_events/model/specialtymodel.dart';
import 'package:konectar_events/model/topics_cloud_model.dart';
import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/viewmodel/hive_repository.dart';
class ApiCall {
final dio = Dio();
@ -540,6 +543,39 @@ class ApiCall {
}
return data;
}
//LOCAL API CONSTANTS
Future<dynamic> fetchApiConstants() async {
dynamic jsonResult =
jsonDecode(await rootBundle.loadString("assets/api_constants.json"));
//dynamic jsonResult = await MockApiCall().getConfigDataMedical();
List<ApiConstantsResponse> responseData =
apiConstantsResponseFromJson(jsonResult);
print('Response_data_is: $responseData');
List<ApiConstantsResponse> eventslist = responseData
.where(
(element) => element.module == EventsConstants.moduleName,
)
.toList();
List<HiveApiConstants> hiveApiConstantsList = [];
if (eventslist.isNotEmpty) {
for (ApiConstantsResponse obj in eventslist) {
HiveApiConstants hiveApiConstants = HiveApiConstants(
functionName: obj.api,
interval: obj.interval,
method: obj.method,
module: obj.module);
hiveApiConstantsList.add(hiveApiConstants);
}
}
print("APICONST LIST LENGTH:${hiveApiConstantsList.length}");
if (hiveApiConstantsList.isNotEmpty) {
HiveOperations.saveApiConstants(hiveApiConstantsList);
}
}
//************ K2 API CALLS ***********************************************************************************************************************************
Future<List<EventsList>> getEventsFromK2(int page, String search,

View File

@ -19,31 +19,37 @@ class EventsConstants {
static const String domainUrl = "http://192.168.2.109:8007/api/method/";
//192.0.0.2:8007 - iphone
// 192.168.2.109:8007 - office
// 192.168.2.109:8007 - office jkqehjkq
//K1 API~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static const String moduleName = "eventapis";
static const String stagingUrl =
"https://cardio-staging.konectar.io/eventapis/";
"https://cardio-staging.konectar.io/$moduleName/";
static const String url = stagingUrl;
static const String devUrl =
"http://192.168.2.130/konectar-sandbox/eventapis/";
static const String eventslistapi = "loadFutureEvents/";
static const String followUnfollowEvent = "saveUserInterestedEvent/";
static const String attendNotAttendEvent = "saveUserAttendingEvent/";
"http://192.168.2.130/konectar-sandbox/$moduleName/";
static const String eventslistapi = "loadFutureEvents";
static const String followUnfollowEvent = "saveUserInterestedEvent";
static const String attendNotAttendEvent = "saveUserAttendingEvent";
static const String specialtyOfSpeakers = "getSpecialitiesDonutChart";
static const String insightsTopicsCloud = "getTopicCloudChart/";
static const String insightsBarChart = "getTopAffiliationBarChart/";
static const String insightsTopicsCloud = "getTopicCloudChart";
static const String insightsBarChart = "getTopAffiliationBarChart";
static const String speakerslistapi = "eventSpeakers";
static const String eventdetailsapi = "eventOverview";
static const String showEventsTopicsAndSession = "showEventsTopicsAndSession";
static const String getTopicNotes = "getTopicNotes";
static const String saveEventsTopicNote = "saveEventsTopicNote";
static const String eventUserAnalytics = "eventUserAnalytics";
//MY CONSTANTS
static const String saveEventOffline = "saveEventOffline";
static const String contactsListapi = "contactslistapi";
//Hive
/*
{
{
"contacts":{
name:"loadFutureEvents",
interval:5,
method:POST,

View File

@ -389,10 +389,14 @@ class _LoginScreenState extends State<LoginScreen> {
// _displaySnackBar(textFieldsValidation(provider));
// }
// },
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => NavigationHomeScreen()),
onPressed: () async {
await ApiCall().fetchApiConstants().then(
(value) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => NavigationHomeScreen()),
);
},
);
},
textColor: Colors.white,

View File

@ -10,6 +10,7 @@ import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/utils/dateformater.dart';
import 'package:konectar_events/view/helpdesk.dart';
import 'package:konectar_events/view/home.dart';
import 'package:konectar_events/viewmodel/hive_repository.dart';
import 'package:konectar_events/widgets/drawerusercontroller.dart';
import 'package:konectar_events/widgets/home_drawer.dart';
import 'package:provider/provider.dart';
@ -44,8 +45,13 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
body: DrawerUserController(
screenIndex: drawerIndex,
drawerWidth: MediaQuery.of(context).size.width * 0.75,
onDrawerCall: (DrawerIndex drawerIndexdata) {
changeIndex(drawerIndexdata);
onDrawerCall: (DrawerIndex drawerIndexdata) async {
bool checkContacts = await HiveOperations.checkIfApiExists(
EventsConstants.contactsListapi);
if (!checkContacts && drawerIndexdata.name == "Contacts") {
} else {
changeIndex(drawerIndexdata);
}
//callback from drawer for replace screen as user need with passing DrawerIndex(Enum index)
},
screenView: screenView,
@ -218,7 +224,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
screenView = const HomeScreen();
});
break;
case DrawerIndex.Help:
case DrawerIndex.Contacts:
setState(() {
screenView = Contacts1();
});

View File

@ -0,0 +1,28 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:konectar_events/model/hive_api_constants.dart';
class HiveOperations {
static Future<void> saveApiConstants(List<HiveApiConstants> hiveList) async {
late Box<HiveApiConstants> hiveApiConstantsBox;
hiveApiConstantsBox =
await Hive.openBox<HiveApiConstants>('hiveApiConstants');
hiveApiConstantsBox.addAll(hiveList);
}
static Future<bool> checkIfApiExists(
String api,
) async {
late Box<HiveApiConstants> hiveApiConstantsBox;
hiveApiConstantsBox =
await Hive.openBox<HiveApiConstants>('hiveApiConstants');
List<HiveApiConstants> list = hiveApiConstantsBox.values.toList();
return list.indexWhere(
(element) => element.functionName == api,
) ==
-1
? false
: true;
}
}

View File

@ -1,12 +1,16 @@
import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:konectar_events/model/hive_api_constants.dart';
import 'package:konectar_events/model/userdata_model.dart';
import 'package:konectar_events/utils/apicall.dart';
import 'package:flutter/services.dart';
import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/viewmodel/hive_repository.dart';
import 'package:mobile_device_identifier/mobile_device_identifier.dart';
class LoginProvider extends ChangeNotifier {
late Box<UserData> box;
bool showCodeField = false;
bool showMessage = false;
bool loading = false;
@ -37,6 +41,79 @@ class LoginProvider extends ChangeNotifier {
print(userData2.imageBytes);
}
Future<void> saveApiData() async {
List<HiveApiConstants> hiveList = [
HiveApiConstants(
functionName: "loadFutureEvents",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "saveUserInterestedEvent",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "saveUserAttendingEvent",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "getSpecialitiesDonutChart",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "getTopicCloudChart",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "getTopAffiliationBarChart",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "eventSpeakers",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "eventOverview",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "showEventsTopicsAndSession",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "getTopicNotes",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "saveEventsTopicNote",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "eventUserAnalytics",
interval: 0,
method: "POST",
module: "eventapis"),
HiveApiConstants(
functionName: "saveEventOffline",
interval: 0,
method: "POST",
module: "eventapis"),
// HiveApiConstants(functionName: "contactslistapi", interval: 0),
];
HiveOperations.saveApiConstants(hiveList);
}
Future<UserData> getUserData() async {
box = await Hive.openBox<UserData>('UserDataBox');
Iterable<UserData> data = box.values;

View File

@ -4,6 +4,7 @@ import 'package:konectar_events/utils/app_theme.dart';
import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/utils/sessionmanager.dart';
import 'package:konectar_events/view/login.dart';
import 'package:konectar_events/viewmodel/hive_repository.dart';
import 'package:shared_preferences/shared_preferences.dart';
class HomeDrawer extends StatefulWidget {
@ -40,42 +41,75 @@ class _HomeDrawerState extends State<HomeDrawer> {
super.initState();
}
void setDrawerListArray() {
drawerList = <DrawerList>[
DrawerList(
index: DrawerIndex.Help,
labelName: 'Contacts',
icon: Icon(Icons.account_circle),
// isAssetsImage: true,
// imageName: 'assets/images/supportIcon.png',
),
DrawerList(
index: DrawerIndex.HOME,
labelName: 'Events',
icon: Icon(Icons.event),
),
void setDrawerListArray() async {
bool checkContacts =
await HiveOperations.checkIfApiExists(EventsConstants.contactsListapi);
if (!checkContacts) {
drawerList = <DrawerList>[
DrawerList(
index: DrawerIndex.HOME,
labelName: 'Events',
icon: Icon(Icons.event),
),
DrawerList(
index: DrawerIndex.FeedBack,
labelName: 'HelpDesk',
icon: Icon(Icons.help),
),
DrawerList(
index: DrawerIndex.Invite,
labelName: 'Medical Insight',
icon: Icon(Icons.group),
),
// DrawerList(
// index: DrawerIndex.Share,
// labelName: 'Rate the app',
// icon: Icon(Icons.share),
// ),
// DrawerList(
// index: DrawerIndex.About,
// labelName: 'About Us',
// icon: Icon(Icons.info),
// ),
];
DrawerList(
index: DrawerIndex.FeedBack,
labelName: 'HelpDesk',
icon: Icon(Icons.help),
),
DrawerList(
index: DrawerIndex.Invite,
labelName: 'Medical Insight',
icon: Icon(Icons.group),
),
// DrawerList(
// index: DrawerIndex.Share,
// labelName: 'Rate the app',
// icon: Icon(Icons.share),
// ),
// DrawerList(
// index: DrawerIndex.About,
// labelName: 'About Us',
// icon: Icon(Icons.info),
// ),
];
} else {
drawerList = <DrawerList>[
DrawerList(
index: DrawerIndex.Contacts,
labelName: 'Contacts',
icon: Icon(Icons.account_circle),
// isAssetsImage: true,
// imageName: 'assets/images/supportIcon.png',
),
DrawerList(
index: DrawerIndex.HOME,
labelName: 'Events',
icon: Icon(Icons.event),
),
DrawerList(
index: DrawerIndex.FeedBack,
labelName: 'HelpDesk',
icon: Icon(Icons.help),
),
DrawerList(
index: DrawerIndex.Invite,
labelName: 'Medical Insight',
icon: Icon(Icons.group),
),
// DrawerList(
// index: DrawerIndex.Share,
// labelName: 'Rate the app',
// icon: Icon(Icons.share),
// ),
// DrawerList(
// index: DrawerIndex.About,
// labelName: 'About Us',
// icon: Icon(Icons.info),
// ),
];
}
}
@override
@ -345,7 +379,7 @@ class _HomeDrawerState extends State<HomeDrawer> {
enum DrawerIndex {
HOME,
FeedBack,
Help,
Contacts,
Share,
About,
Invite,