Flutter Coding Session: WorkManager and Background Tasks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I don't always use chat GPT but sometimes I do chat GPT or Gemini just any any AI conversation model if I need help it's it's supposed to be saved in disk and I'm trying to pull it into a virtual machine we have a string that represents an array but it also ended up taking the brackets what we're going to do instead is just manually take out the braces and that would naturally make this work hello everybody hello my lovely people hope you guys are having a decent day we're going to continue on some identifiers it would be nice to check if background tasks work even if the app is terminated I should really save the packages that I use I wonder if there's like pictures or something or I can run the example move to Android Gradle I feel like I should be upgrading to the newest Android Gradle but every time I do it breaks you know where it said that it would have a notification once the flag is enabled you will receive a notification whenever a background task sugared this way you can oh you know what this is maybe it needs to be on an actual phone so let's try that we have a pixel here that I use for testing we are going to try and see if we can get this to work so we'll connect it to our Android we'll see what happens when we background it now we need to pass in data that we want to use the thing is that we can send data over but it doesn't matter what matters is the data that is currently being seen in this moment they're actually just grabbing the data let's delete stuff we don't need and essentially and we would have to invoke a method to return a list of apps not related to our model we can probably just create one of these right oh no we need a build context actually there's no build context in isolated world right let me double check that that's true there's no context unless we build a a widget and if we build a widget for a build context it doesn't really do anything it kind of just adds a lot of Plumbing that we don't need what we would need from our app is the list of blocked apps let's see at this point when it's inactive hidden paus cancelled so that's the order so hidden pause okay so it should save everything so let's choose maybe like schedu L yeah let's do schedule list we're just trying to see if we can get some values here I'm waiting for this thing okay so second period task started like this started but it didn't call back I'm pretty sure that um that I don't even need to use a uh a phone I'm pretty sure I could use an emulator so we're going to try this out this is probably going to crash my program but we ball okay so this is working now have to do two things one we have to go into our settings menu and go into our applications apps and this one let's turn on notifications let's go back here and let's reset this and there you go now we see all of the notifications well this is clearly not working I'm pretty sure if I printed this right here if I did this I mean we can we can find out pretty quickly if uh this updated with the refresh yeah that is from the Android app that's annoying I don't see a null statement oh here hidden paused null why does it keep doing that where where is this sound coming from I'm pretty sure it's through this okay so this does work this is grabbing the profile why does it keep ringing like that what is happening oh here we go later all right let's see here it's null again I wonder why it's doing that yeah these definitely need await statement but the await statement shouldn't bother this see schedule list and it has a schedule so now if I do this this should now show a scheduled list okay so personal profile is the thing that gives it because personal profile is a string that holds all the other properties try doing this let's refresh this see if that works we're running this this forward let's see if this is still null hopefully it's not no it is null dang yeah this is null it's an isolated environment in order to make preference look up via get synchronous uses a cache which is normally updated usually this is mation detail that does not you should call reload on the instance from it to update its cach with any external changes if this is problematic okay so apparently you could do reload and if this doesn't work that's totally okay we'll just have to shift a lot of the method calls and everything in the actual isolate here or a virtual machine Let's see it's still no yeah so this isn't going to work okay cool so how do you communicate between them we can probably communicate between them through some fancy way here so spawn on isolate port. send I don't always use chat GPT but sometimes I do chat GPT or Gemini just any any AI conversation model if I need help but for the most part I find it a lot more natural to look things up on stack Overflow medium and GitHub reos the answers aren't exactly what I want because I feel like there's a certain way to ask conversation sometimes fortunately provides a better way a simpler way which is a high level to execute a and isolate and receive the result I was thinking like maybe I should be storing all of this information in a database but that's just a lot of data pretty much there is data cached in our main thread right here there has to be a way by the way to rename these so they look different but pretty much one of these call Stacks in main is our main thread and then the other two are virtual machine threads that are created that are in isolated environments and I'm trying to get information from the main thread I'm trying to get data from the main thread which is saved it's it's supposed to be saved in disk um using a shared preference which is like a a data storage plug-in and I'm trying to pull it into a virtual machine but it doesn't seem to be working at all communicate from different enges is needed in this situation currently I solve this problem by starting an HTTP service oh that's kind of smart HTTP requests in our app I mean as long as it's all local it doesn't matter right they're close to working on it but it's not working yet we should probably move this out cuz this is going to get very noisy I don't know if VM entry points need to be in the same file as Maine I also don't think it has to be called callback dispatcher let's just make a new folder and we'll deal with everything else later right this repository is getting kind of lit it has so many sections this is going to be background F I wonder how I shift in between uh in between files on vs code but we could just do something like this we can save this we can put this in here I don't think we need shared preferences right now it's supposed to do this every 5 seconds do we want to instantiate an appas every 5 seconds but we can do this for now okay we're going to take out debugging we don't need that what is this this is also for debugging don't need that we should also remove that from the main function as well but and I guess we can do this that pretty much solves that all right so with this logic we need to send over the list of block apps we should really have all of this be in uh the call back right this should be one function it should be honestly we can put it here for now void Trigger or um init background thread background test call back dispatcher parallel thread or a background thread and then we can kind of take things from there once things are working all right this looks pretty good we should add a comment to just say initializes uh background asks that pull up toate usage data for apps on a device and determines up toate usage data for apps on a device and determines if an overlay could be triggered now this all depends on one thing it depends on overlay main like where is overlay main called okay so it's only called there which means that it's tied directly to the third party PL again which means that it should be okay that we're not calling overlay main cuz we'll call it through flutter overlay window or whatever it is and then the next thing to do first we need to see if blocked apps gets passed in I mean I guess like the logic is here except this doesn't really I guess we'll do it underneath here cuz we're trying to replicate that um something similar to converting the Json object that we get into a list that we can use so the first thing we need is our personal profile or user profile that we're passing through and that'll be here and locked appless is going to be this going to be a list the list of profile apps it says we can just cast it so we'll try this out okay so this does work because of strings which means that it's not being converted properly but this still isn't being okay so clearly this is a this is a joke because profile app we made it so that the string when it is converted to a string it converts pack package name and then if this doesn't work then I assume it's because the local variable is being wiped this is working we don't need anything else to be honest all we really need is the list of app names and this is good because we can just check this list to see if it's available there's definitely some ingrin code that needs to be ran when the application is launched seems a little weird but uh platform specific code all right let's see if this runs it seems like it seems like background task callback isn't being called at all all right let's check it out let's see if this works worker result failure for work R calling map closure Dynamic string all right so this fails let's try a Reload or a hot restart I should say but it doesn't because it still says it's trying to call a map uh tried calling cing okay that clearly doesn't work see this is why I hate using this it's kind of weird that this doesn't work unless I I completely stop it we're getting there it's a conversion this is kind of frustrating for some reason even though this is returning a map string Dynamic it's still doing some type of detection to see what primitive typers sending to our map and it's just not making it easy to cast things easier this will probably work letter how to convert a string that represents an array into a list of strings okay so this is kind of hacky we have a string that represents an array but it also ended up taking the brackets and I was trying to find a way to do it properly like to convert it convert a string that represents an array I don't think there's a way to actually remove the brackets what we're going to do instead is just manually take out the braces and that would naturally make this work this is a list of strings so you don't see two bra here and this is just pumping out every time we check if it's empty if it's not we do this and either way we're just printing out the block app well we're not printing it out we're using it in this uh for Loop check but yeah this would um this logic works fine because the only time we're worried about updates to this blocked app list but the only way to update it is by going back into our app and if you go back into the app and you background it again it cancels SS all of the the backlogs of background threads and it restarts them this is good enough right so this is all working now I feel like this is a good place to end for now we did pretty good today we hit a huge milestone which I'm very happy about again I appreciate you guys if you're tuning in for the first time and you haven't been a part of the channel or the community yet then feel free to subscribe so you can join the next stream that I do and uh you could see all the content hopefully I I create more stuff that will help you guys out so I'll see you guys in the next one thanks for coming
Info
Channel: Just Joemer
Views: 301
Rating: undefined out of 5
Keywords: self improvement, productivity, personal development, joemer ramos, self development, software engineer
Id: K3Ei9RaO4uk
Channel Id: undefined
Length: 12min 36sec (756 seconds)
Published: Fri Mar 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.