At the beginning of problems now

Recently in personal pluginsPangolinIn the use of feedback, there are a lot of students to reflect a problem to me 🧐

Young opinion 🤥

Context is null📌 this is not easy. Context is null📌 “Context did not get”, “do not call in the main function”, “increase delay start strategy”, this is my first batch of found problems in the children’s shoes, here if the first batch of children’s shoes can see the words, I first apologize 🍡, unlearned, give you trouble. But, but! Someone actually solved this problem by putting it in a page method… So, I am not purely misleading 👀, hahahahahahaha.

The text start

confusion

Later a careful student said he hit a breakpoint, showcontextAlready initialized, but not retrieved in the plug-in. And this operation? Oh huo 🤔, how fat four, I look all the way along the code, finally, found a wrong place.This is obtained in the plug-incontextThe first place, the place where dreams begin 💡. After checking it, I found that some students did not use it when the plug-in was initializedonAttachedToEngine()Methods. I was surprised 😟, is it so 🐮🍺 now,engineDon’tattach. There’s something wrong with the flutter, butflutter doctorCheck everything is ok! ✅. And then I found another shady function!What kind of character is this? ! 🎭, touch porcelain son of? Don’t try don’t know, a try startled, part of the students did not goonAttachedToEngine()But goregisterWith(). How did this happen?

c.

Finally, in the Flutter 1.12 migration record, I found a clue 😇A lot. What does that mean? 🤓 the general meaning is that the official has provided a newAndroid Plugin APIBut for the old onesPlugin APIIt will not be abandoned immediately. We recommend that you migrate your plugins as soon as possible. The plugins in the new API all use*Plugin.javaThe naming method of the. New plug-ins inheritFlutterPluginandMethodCallHandler(Officials also mention how to use itActivityYou need to inheritActivtiyAware). Before your plugin inheritsMethodCallHandlerAfter that, it will be providedregisterWith()Methods,registerWith()In the initializationMethodCallHandler. But a new version has been usedonAttachedToEngine()Method initializationMethodCallHandlerWe can still see it as we write the new version of the plug-inregisterWith()The method is official for compatibility support with older plugins ⛏. This I understand! I wrote it all downonAttachedToEngine()In the method, there are indeed some students who will not go. Because the old version did not have this method 😕.

done

How on earth to deal with this new oldAPIWill the handover be more elegant and rigorous? I am inGitHubRead a lot of official plug-in writing method, findPackageInfoHere also provides you as a reference.The new version of the students did not have any problems according toonAttachedToEngine()Rest assured bold forward, for the old version of the students, it doesn’t matter ~, I close to expand aonAttachedToEngine()In theregisterWith()Inside call, and in this customonAttachedToEngine()In the initialization, binding interface, so that your old plug-in is a new plug-in, look new 🤩. So far, I’ve had no responsecontext is nullThe problem of ~

harvest

In fact, in the investigation of this problem, he or too conceited, too not serious, in the face of the problem holding the attitude of course, did not carefully explore the problem, this is the programmer’s taboo 🤐. After the troubleshooting of their own problems, code should always remind themselves to pay attention to the rigor, all kinds of possibilities. Of course, I will pay more attention to this point in programming after learning knowledge.