|
Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to?
I am currently working on a Flutter app, which worked just perfectly! I committed the recent changes,
$ git log -1
commit 6441c90ee1c010362eb81740184fb50d900b46a1 (HEAD -> master, gitlab/master)
Author: Afzaal Ahmad Zeeshan <my-email@example.com>
Date: Thu Jan 30 02:49:38 2020 +0500
Contacts and lists now showing the phone numbers are showing too.
The "past me" is telling me that database integration worked and SQLite receives all the records from the device for app usage. That is where I paused the development last night and committed the changes. Today I just resumed the development, and voila. The most basic of the code happens to not work.
var contacts = await ContactsService.getContacts();
if(contacts.length == 0) {
print("[INFO] Device does not have any contacts.");
return;
}
print("[INFO] Loaded ${contacts.length} contacts, attempting to save...");
var database = await $FloorAppDatabase.databaseBuilder(MyApp.dbName).build();
List<Recipient> newContacts = [];
contacts.forEach((contact) async {
var _contact = await database.recipientDao.findRecipientById(contact.identifier);
if(_contact == null) {
newContacts.add(Recipient(contact.identifier, contact.displayName));
}
});
if(newContacts.length > 0) {
await database.recipientDao.insertAllRecipients(newContacts);
print("[INFO] Added ${newContacts.length} contacts.");
}
The code attempts to save the contacts from a device to a device-only database. The _contact is always null , newContacts always gets a new element for contact (since there is no record in the database). But as soon as it hits the if(newContacts.length > 0) { line, the length of the array drops to zero.
There isn't any closure (Dart is JavaScript of Google) in action, awaits are applied just fine to pause the execution at IO-bound tasks, but still, it simply refuses to work.
Interesting thing is that this is the same code I committed last night!
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Then maybe a more suitable name than "Flutter" would be "Stutter"
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Ever happened to you that everything worked just fine for you, you take a back up, make changes and it refuses to work as it is intended to?
Today after lunch. Very annoying.
Afzaal Ahmad Zeeshan wrote: Interesting thing is that this is the same code I committed last night!
I feel your pain.
My code hasn't changed but now it fails to build.
There's a transform script working on the app.config and the transform script (created by another dev) is failing all of a sudden.
So, now instead of focusing on my code I have to figure out why the transform script is failing.
I'm fixing the _hammer_ so I can nail the boards together. argh!!
|
|
|
|
|
Quote: So, now instead of focusing on my code I have to figure out why the transform script is failing. True, such as a code-block it is. I have personally felt that among all the open-source frameworks, Flutter has the most open issues on GitHub. And these issues are not going anywhere.
Issues · flutter/flutter · GitHub
Even if I don't mess up with anything, Google would update something and it just wouldn't work.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Just flag it: "Won't fix: works on my machine sometimes".
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
contacts.forEach((contact) async {
var _contact = await database.recipientDao.findRecipientById(contact.identifier);
if(_contact == null) {
newContacts.add(Recipient(contact.identifier, contact.displayName));
}
});
if(newContacts.length > 0) {
Never used Dart before, but everything in my being is telling me that looks dangerous if forEach isn't a blocking function. Some quick googling tells me you may want to try Future.forEach.
|
|
|
|
|
Yep, you're right. What I am thinking about this is something like:
Future<void> processContacts(List<Contact> contacts) async {
for (var contact in contacts) {
if(await database.recipientDao.findRecipientById(contact.identifier) == null) {
}
}
} Future.forEach follows the similar approach to call the function that returns a Future , and await on it internally.
Who knows, if I change the code to this approach, the problem goes away.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I don't know enough about Dart to say. It depends on what you're looking to accomplish. If you want sequential but non-blocking processing of the list, yea I think it should work as long as you await on that function.
EDIT: Removed a sentence, been reading up on asynchronous stuff in Dart and it's the same as C# where it doesn't allow await inside of a non-async function.
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Interesting thing is that this is the same code I committed last night!
The fact that it didn't work before and did work now would seriously concern me.
Whoops I understood your post backward
Anyway, what I would consider is that your environment changed. See if there were any other commits or changes to the server?
Real programmers use butterflies
|
|
|
|
|
Quote: what I would consider is that your environment changed Nope, it is all same.
The file is just 50 lines of code and using the tip of Jon, I am considering a rewrite for this service, most probably that would spot any bugs if there are in my code.
A big problem with Flutter is that it too often requires a flutter clean to remove the clutter, most problems were solved that way, but not this.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
No, no, that won't do.
The usual complaint in the forum is that it worked yesterday, and nothing changed and it just stopped working.
You can't just admit you broke it like that.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Quote: is that it worked yesterday, and nothing changed and it just stopped working. Not yesterday, just one commit ago.
Nothing changed, restarted the emulators to try everything with fresh app installation and it stopped working. I did a hard reset on my Git, but still the same.
The take away is, always test the code from the beginning and then commit. Sadly, I did not have the tests written to verify these services (contacts storage and database) so this is what I need to work on.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Nothing changed Exactly what I wanted to hear
Yes, cherry picking, and not meant to be taken too seriously.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|