The method 'putIfAbsent' was called on null - list

I am trying to create a LinkedHashMap and populate it with a DateTime as the key and a List as the value in my flutter app. I keep running into problems with creating this.
Here is what I am trying right now without success:
List<dynamic> _getEventsForDay(DateTime day) {
for (int i = 0; i < eventDoc.length; i++ ) {
if (day.year == eventDate.year && day.day == eventDate.day && day.month == eventDate.month) {
List<dynamic> eventList = [];
eventList.add(eventDoc[i].agencyId);
eventList.add(eventDoc[i].agentId);
eventList.add(eventDoc[i].eventDate);
eventList.add(eventDoc[i].eventDescription);
eventList.add(eventDoc[i].eventDuration);
eventList.add(eventDoc[i].eventName);
eventList.add(eventDoc[i].eventStartTime);
return kEvents.putIfAbsent(eventDateUTC, () => eventList);
}
}
}
Everything is working except the last line and the putIfAbsent call. The eventDateUTC and the eventList both have values.
I am getting this error when I try to execute the
return kEvents.putIfAbsent(eventDateUTC, () => eventList);
line. When this line executes I get this error:
The method 'putIfAbsent' was called on null.
Receiver: null
Tried calling: putIfAbsent(Instance of 'DateTime', Closure: () => List<dynamic>)
kEvents is declared like this:
LinkedHashMap<DateTime, List> kEvents;
I am sure I am missing something small but I don't have enough experience with flutter to know what it is. Please help if you can.

Related

react native giftedchat can not edit message text

I want to edit a message, but it's only updated when i changed this message _id. Can someone provide me how to do it, here is my code:
const onSend = useCallback((messagesToSend = []) => {
if(editMessage != null){
setEditMessage()
const m = messagesToSend[0]
const newMessages = [...messages]
const index = newMessages.findIndex(mes => mes._id === editMessage._id);
console.log('index: ', index)
if(index > -1){
newMessages[index].text = m.text // => ***i only edit the text***
// newMessages[index]._id = uuid.v4() => ***this working if changed _id***
console.log('newMessages', newMessages[index]) // => ***new message changed it's text but the bubble not change when re-render***
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setMessage(newMessages)
}
}else{
setReplyMessage()
appendMessage(messagesToSend)
}
})
It looks like you're using useCallback without a dependency array. This means that any dependencies that you rely on will be memoized and won't update when you run the function.
You should add messages, editMessage, and maybe setMessage and appendMessage, to the dependency array. Like so:
const onSend = useCallback(
(messageToSend = []) => etc,
[messages, editMessage, setMessage, appendMessage]);
That's the first thing I would try
ok i found problem, in MessageText the function componentShouldUpdate need modify a bit

Cannot read property 'split' of undefined while testing getting this error

https://www.youtube.com/watch?v=8xDM8U6h9Pw
This is my string I am trying to split that url from = sign. But I am getting error as
TypeError: Cannot read property 'split' of undefined
My code is as follows:
getVideoURL() {
if (this.mealDetails !== null && this.mealDetails !== undefined) {
// let splitUrl = this.mealDetails.strYoutube.split("=");
console.log("strYoutube", this.mealDetails.strYoutube);
this.splitUrl = this.mealDetails.strYoutube.split("=");
const id = this.splitUrl[1];
let url = `https://www.youtube.com/embed/${id}`;
return url;
}
},
please tell me how to resolve that error
Not sure what you intend to do .. but how about this?
const mealDetails = {
strYoutube: "https://www.youtube.com/watch?v=8xDM8U6h9Pw"
}
function getVideoURL(obj) {
if (obj) { // check for non-empty object
const splitUrl = obj.strYoutube.split("=")
return 'https://www.youtube.com/embed/'+splitUrl[1]
}
}
const newUrl = getVideoURL(mealDetails)
console.log(newUrl)
This works great -> https://jsfiddle.net/9r13t4v6/3/
Please use parameters when calling functions ... and to check empty object you can use if(value) ... if it's not empty (=> NaN, null, undefined, 0, false) it will eval as true ..
plus you don't have to use that many variables :) try to stick with as many as possible (-> better readability)

How to pass LedgerJournalTrans table in resolve method of InvoiceJournalExpPartcicipantProvider class?

I have literally tried everything but still in vain. This here is InvoiceJournalExpParticipantProvider class that is supposed to provide me partici[ant names inside the workflow (all of this is custom code). Now what i want is to pass the LedgerJounalTrans table instead of the VendInvoiceInfoTable or VendInvoiceInfoLine table. I cannot seem to find a way to do this. I tried using the following code
else if (_context.parmTableId() == tableNum(LedgerJournalTrans))
{
ledgerJournalTrans = LedgerJournalTrans::findRecId(_context.parmRecId(),false);
}
But it constantly gives me an error either telling me that the operand types are of not the same types or the number of arguments passed are invalid although when i go and check the findRecId() method of ledgerJournalTrans table there are only two params being passed.
public WorkflowUserList resolve(WorkflowContext _Context, WorkflowParticipantToken _participantTokenName)
{
WorkflowUserList userList = WorkflowUserList::construct();
VendInvoiceInfoTable vendInvoiceInfoTable;
VendInvoiceInfoLine vendInvoiceInfoLine;
VendInvoiceInfoLine_Project vendInvoiceInfoLine_Project;
WorkflowParticipantExpenToken workflowParticipantExpenToken;
WorkflowParticipantExpenTokenLine workflowParticipantExpenTokenLine;
RefRecId dimensionAttributeSetRecId;
MarkupTrans markupTrans;
CompanyInfo legalEntity;
ProjTable projTable;
HcmWorker worker;
DirPersonUser personUser;
HcmPositionDetail hcmPositionDetail;
HcmPosition hcmPosition;
HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
LedgerJournalTrans ledgerJournalTrans;
// check participant token name is given otherwise throw error
if(!_participantTokenName)
{
throw error('Participant name');
}
userList.add('Admin');
if (!_participantTokenName)
{
throw error("#SYS105453");
}
workflowParticipantExpenToken = WorkflowParticipantExpenToken::findName(
this.documentType(),
_participantTokenName);
if (!workflowParticipantExpenToken)
{
throw error(strFmt("#SYS313865", _participantTokenName));
}
if (_context.parmTableId() == tableNum(VendInvoiceInfoTable))
{
vendInvoiceInfoTable = VendInvoiceInfoTable::findRecId(_context.parmRecId());
}
else if (_context.parmTableId() == tableNum(VendInvoiceInfoLine))
{
vendInvoiceInfoTable = VendInvoiceInfoLine::findRecId(_context.parmRecId()).vendInvoiceInfoTable();
}

Flutter add item to list

I would like to add an item to a list:
void submitAll() async {
List<UserSearchItem> userSearchItems = [];
Firestore.instance
.collection('insta_users')
.snapshots()
.listen((data) =>
data.documents.forEach((doc){
print(data.documents.length);
User user = new User.fromDocument(doc);
UserSearchItem searchItem = new UserSearchItem(user);
userSearchItems.add(searchItem);
print(user.bio);
}));
print("Loaded");
print(userSearchItems.length);
}
But if I print the length of the list to the console, it always says, the list is 0 long...
print(userSearchItems.length);
Any suggegstions?
Best Regards
I will try to give an explanation of what is happing here take a look on this code:
import 'dart:async';
void main() {
List<int> userSearchItems = [];
Timer _sendTimeOutTimer;
const oneSec = Duration(seconds: 2);
_sendTimeOutTimer = Timer.periodic(oneSec, (Timer t) {
userSearchItems.add(1);
print(userSearchItems.length); // result 1 and it will be executed after 2 seconds
_sendTimeOutTimer.cancel();
});
print(userSearchItems.length); // result 0 and it will be executed first
}
The print inside asynchronous action(Timer) it will be executed after 2 seconds means after the asynchronous action ends but the one which is outside of asynchronous action(Timer) it will be executed directly without waiting 2 seconds, in your case the asynchronous action is listening to data .listen((data) =>, so if you print the length outside of your asynchronous action you will not see the deferent because the item is not added yet.
Solution: you can create function witch return Future and then wait until it's finished then print the length.
List<UserSearchItem> userSearchItems = [];
Future<String> submitAll() async {
Firestore.instance
.collection('insta_users')
.snapshots()
.listen((data) =>
data.documents.forEach((doc){
print(data.documents.length);
User user = new User.fromDocument(doc);
UserSearchItem searchItem = new UserSearchItem(user);
userSearchItems.add(searchItem);
print(user.bio);
return 'success';
}));
}
void yourFunction() async{
await submitAll();
print("Loaded");
print(userSearchItems.length);
}
Then call yourFunction().
Try to add print(userSearchItems.length); inside forEach after adding the item and you will see the real length.
There is a simple way tu add new data tu a list on Flutter.
for (var i = 0; i < list.length; i++) {
double newValue=newValue+1; //This is just an example,you should put what you'r trying to add here.
list[i]["newValueName"] = newValue; //This is how we add the new value tu the list,
}
See if it work by doing a:
print(list);//You can put a breakpoint her to see it more clearly
Hope it helps.

i want to update only single row column value with rollback commit

i want to update only single row column value with rollback commit but when i create table object inside if and pass to insertonsubmit it gives me error,plz help me how can i solve this
var challan = dataContext.Purchase_Challans.Where(t => t.Challan_ID == Convert.ToInt64(ViewState["challanid"]) && t.Company_ID == Convert.ToInt32(Session["CompanyId"])).Select(t => t).ToList();
if (challan.Any())
{
challan.ToList()[0].Inv_DocumentId = dmsPurchaseInvoice.Document_ID;
dataContext.Purchase_Challans.InsertOnSubmit()
dataContext.SubmitChanges();
}
Would be helpful to know more details about the error, but I assume it's because you tell the dataContext to insert an entity that you just retrieved (whereas you want to update it).
Also the code you posted does not even compile and is full of questionable code, like challan.ToList() where it already is a list, or parsing strings inside a delegate.
That said, this code is more straightforward and more likely to work (but to be honest I didn't test it):
var challanId = Convert.ToInt64(ViewState["challanid"]);
var companyId = Convert.ToInt32(ViewState["CompanyId"]);
var challan = dataContext.Purchase_Challans.SingleOrDefault(t => t.Challan_ID == challanId && t.Company_ID == companyId);
if (challan != null)
{
challan.Inv_DocumentId = dmsPurchaseInvoice.Documet_Id;
dataContext.SubmitChanges();
}