import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:konectar_events/model/affiliationsmodel.dart'; 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/keywords_model.dart'; import 'package:konectar_events/model/neweventsmodel.dart'; import 'package:konectar_events/model/scope_model.dart'; import 'package:konectar_events/model/sessionnotesmodel.dart'; import 'package:konectar_events/model/specialtymodel.dart'; import 'package:konectar_events/model/topics_cloud_model.dart'; import 'package:konectar_events/utils/apicall.dart'; import 'package:konectar_events/utils/dateformater.dart'; import 'package:konectar_events/widgets/word_cloud.dart'; class EventsProvider extends ChangeNotifier { List keywordList = []; List therapeuticList = []; List eventList = []; List searchList = []; List myEvents = []; List eventdetailList = []; List srcheventdetailList = []; List selectedTherapeutic = []; List addedSessionNotes = []; int eventSessionCount = 0; String message = ""; late Box box; late Box sessionBox; bool isAllSelected = true; bool isFavSeleted = false; bool isSearch = false; bool isSearchSpeakers = false; List kFlutterHashtags = []; List topics = []; List specialtyList = []; OverviewData? overviewData; Affiliations affiliations = Affiliations(affiliationCount: [], affiliationNames: []); onSelectAll() async { // isFavSeleted = false; // isAllSelected = !isAllSelected; eventList = await getEvents(); notifyListeners(); } onSelectMy() async { // isFavSeleted = !isFavSeleted; eventList = await getMyEventsData(); notifyListeners(); } OnSearch(String searchtxt) { // searchtxt = searchtxt.toLowerCase(); isSearch = true; if (isFavSeleted) { searchList = eventList .where((element) => element.name1!.toLowerCase().contains(searchtxt)) // (element.city != "" && // element.city!.toLowerCase().contains(searchtxt)) || // (element.region != "" && // element.region!.toLowerCase().contains(searchtxt)) || // (element.country != "" && // element.country!.toLowerCase().contains(searchtxt))) .toList(); } else { searchList = eventList .where((element) => element.name1!.toLowerCase().contains(searchtxt)) // element.city!.toLowerCase().contains(searchtxt) || // element.region!.toLowerCase().contains(searchtxt) || // element.country!.toLowerCase().contains(searchtxt)) .toList(); } print("###$searchList@@@"); notifyListeners(); } getSessionCount() { List sessions = []; eventSessionCount = 0; for (var obj in eventdetailList) { sessions.addAll(obj.sessionName!.split(',')); eventSessionCount += int.parse(obj.numSess ?? "0"); } print("Count ${sessions.toSet().toList().length}"); print("Count2 ${sessions.toList().length}"); print("SEE SESSIONS ${sessions.toSet().toList()}"); eventSessionCount = sessions.toSet().toList().length; notifyListeners(); } OnFilters() { isSearch = true; if (isFavSeleted) { searchList = myEvents .where((element) => selectedTherapeutic.contains(element.therapeuticArea)) .toList(); } else { searchList = myEvents .where((element) => selectedTherapeutic.contains(element.therapeuticArea)) .toList(); } print("###$searchList@@@"); notifyListeners(); } onFilterReset() async { if (isFavSeleted) { eventList = await getMyEventsData(); } else { eventList = await getEvents(); } isSearch = false; searchList.clear(); notifyListeners(); } onSearchReset() async { if (isFavSeleted) { eventList = await getMyEventsData(); } else { eventList = await getEvents(); } isSearch = false; searchList.clear(); notifyListeners(); } OnSearchSpeakers(String searchtxt) { searchtxt = searchtxt.toLowerCase(); isSearchSpeakers = true; srcheventdetailList = eventdetailList .where((element) => element.kolFullName!.toLowerCase().contains(searchtxt) || element.eventTopics!.toLowerCase().contains(searchtxt)) .toList(); notifyListeners(); } onSearchSpeakersReset(String eventid) async { eventdetailList = await getEventsDetails(eventid); isSearchSpeakers = false; srcheventdetailList.clear(); notifyListeners(); } initFiltersData() async { // keywordList = await ApiCall().getkeywords(''); // therapeuticList = await ApiCall().getscopes(); notifyListeners(); } Future> getKeywordList(String keyword) async { keywordList = await ApiCall().getkeywords(keyword); return keywordList; //notifyListeners(); } Future> getEvents() async { eventList = await getAllEventsData(); if (eventList.isEmpty) { eventList = (await ApiCall().getEvents())!; //eventList = (await ApiCall().getStagingEvents())!; for (var events in eventList) { await saveEventsData(events); } } return eventList; //notifyListeners(); } Future> getAddedSessionNotes() async { addedSessionNotes = await getAllSessionNotesList(); if (addedSessionNotes.isEmpty && eventList.isNotEmpty) { addedSessionNotes = (await ApiCall().getSessionNotes())!; for (SessionNotesModel notes in addedSessionNotes) { int i = eventList.indexWhere((element) => element.name1 == notes.eventname); if (i != -1) { notes.eventid = eventList[i].eventId; } notes.addedBy = "user"; notes.addedDate = CustomDateFormatter().formatDate(); await saveSessionDataFromResp(notes); } } return addedSessionNotes; //notifyListeners(); } Future> getEventsDetails(String eventid) async { eventdetailList = (await ApiCall().getLocalEventsDetail(eventid))!; return eventdetailList; //notifyListeners(); } Future addEventsToFavs(String eventid) async { message = await ApiCall().addEventsToFav(eventid); return message; //notifyListeners(); } Future markAttending(String eventid) async { message = await ApiCall().attendEvents(eventid); return message; //notifyListeners(); } FutureOr saveEventsData(EventsList eventsData) async { box = await Hive.openBox('EventsListBox'); box.add(eventsData); List eventsData2 = await getMyEventsData(); notifyListeners(); } FutureOr favsEventsData(EventsList eventsData) async { box = await Hive.openBox('EventsListBox'); List data = box.values.toList(); int index = data.indexWhere( (element) => element.eventId == eventsData.eventId, ); box.putAt(index, eventsData); List eventsData2 = await getMyEventsData(); notifyListeners(); } Future> getMyEventsData() async { box = await Hive.openBox('EventsListBox'); Iterable data = box.values; myEvents = data .where( (element) => element.isfav == true, ) .toList(); // EventsList eventsdata = EventsList(); // for (var obj in data) { // eventsdata = new EventsList.fromJson(obj.toJson()); // } return myEvents; } Future> getAllEventsData() async { box = await Hive.openBox('EventsListBox'); Iterable data = box.values; myEvents = data.toList(); // EventsList eventsdata = EventsList(); // for (var obj in data) { // eventsdata = new EventsList.fromJson(obj.toJson()); // } return myEvents; } Future> getAllSessionNotesList() async { sessionBox = await Hive.openBox('SessionNotesModelBox'); Iterable data = sessionBox.values; addedSessionNotes = data.toList(); // EventsList eventsdata = EventsList(); // for (var obj in data) { // eventsdata = new EventsList.fromJson(obj.toJson()); // } return addedSessionNotes; } FutureOr deleteAllEventsData() async { box = await Hive.openBox('EventsListBox'); box.clear(); } FutureOr delateEventsData(EventsList event) async { //DELETE // box = await Hive.openBox('EventsListBox'); // List data = box.values.toList(); // int index = data.indexWhere( // (element) => element.eventId == eventid, // ); // await box.deleteAt(index); //REMOVE FROM FAVS box = await Hive.openBox('EventsListBox'); List data = box.values.toList(); int index = data.indexWhere( (element) => element.eventId == event.eventId, ); event.isfav = false; box.putAt(index, event); eventList = await getMyEventsData(); notifyListeners(); } FutureOr saveSessionDataFromResp(SessionNotesModel notesModel) async { sessionBox = await Hive.openBox('SessionNotesModelBox'); sessionBox.add(notesModel); notifyListeners(); } FutureOr getTopicsCloud(String eventid) async { List topics = (await ApiCall().getTopicsCloudData(eventid))!; // for (var events in eventList) { // await saveEventsData(events); // } //notifyListeners(); kFlutterHashtags = []; for (var topic in topics) { kFlutterHashtags .add(FlutterHashtag(topic.topic!, int.parse(topic.total!), false)); } notifyListeners(); } FutureOr getSpecialtyData(String eventid) async { specialtyList = (await ApiCall().getSpecialty(eventid))!; notifyListeners(); } FutureOr getAffiliations(String eventid) async { affiliations = (await ApiCall().getSpeakerCounts(eventid))!; notifyListeners(); } FutureOr getOverviewData( String eventid, String startDate, String endDate) async { overviewData = (await ApiCall().getEventsOverview(eventid, startDate, endDate)); notifyListeners(); } }