Calling a Function When Loading a Stateful Widget in Flutter

My capstone group is building a mobile app using the Flutter SDK, and it requires for a user to be logged in to reach any page other than a login page, a sign up page, and a forgotten password page. We are using Google’s FirebaseAuthentication package to handle securely logging in and out, but we also have our own Cloud Firestore database that stores additional user and account information beyond the basic login information that Firebase stores. So after a new user creates an account, we needed a way to gather the additional information we need and store that in the database.

After a user logs in or sign ups, our app routes them to the app’s homepage, so we figured that when the home widget is loaded, we could just call a function that would determine if the user’s FirbaseAuth user ID corresponded with a document in our Firestore database, but figuring out how to effectively call this function when loading the stateful class that builds the widget that is the foundation of our homepage proved trickier than I anticipated.

I first tried to just call a function in the widget’s build method but quickly ran into an issue: database calls need to be made asynchronously to prevent blocking, and the build method is not asynchronous. So I did some googling and cam across initState().

initState() is a function that is called a single time when a widget is inserted into the app’s widget tree and the widget’s state is initialized. Because other screens are just loaded in the body of our homepage widget, meaning the homepage should only be inserted into the tree a single time when a user is already in the database, this is a great solution that will not make a bunch of unnecessary database calls. I used the following code within the widget generated by the StatefulWidget’s createState() method to check if the user already existed in the database and if not, route them to a set up page.

class NavBarPage extends StatefulWidget

const NavBarPage({    Key? key,  }) : super(key: key);
  @override  State<NavBarPage> createState() => _NavBarPageState();

}

class _NavBarPageState extends State<NavBarPage> {

  @override 

// Check if firebase_auth uid corresponds to document in db.  void initState() {    asyncUidCheck().then((value) {    });    super.initState(); 

}

}

My First Two Weeks on the Job

I started last Monday at my first full-time software developer job. So far I haven’t even written a single line of code. I primarily spent the first week setting up my dev environment and getting familiar with the processes and systems my team handles. Just getting my env set up was a way bigger task than I anticipated. I had already been working at my company (PacificSource Health Plans) in a mostly non-technical role, but I had done a bit of coding in my previous position, so I already had a lot of the developer software installed- Visual Studio, Visual Studio Code, Microsoft SQL Server Management studio-but I still had to install some ancillary software and get access permissions to all the servers, directories, databases and source control I will need for my job. This involved submitting many, many help desk tickets requesting access.

In addition to get my environment set up, I’ve also been learning about the codebase and the business it is supporting. This has involved many hours of meetings and watching more senior developers walk me through code and explain different systems. I’ve already learned a ton, but it has been mentally exhausting too. I’m really looking forward to being able to contribute more and start writing some code.

The best part of the new job so far was when I actually got to solve a problem myself (well sorta, I answered an important person’s question, at least). The most senior developer on my team left for a different company last Friday, but for the week our tenures overlapped, he tried to pass on as much information to me as he could. One of the things we discussed was a process that automatically assigns primary care providers to our Medicaid members. The primary logic for this process is handled in a SQL stored procedure that is nearly one thousand lines long (yeah, it’s a little scary) which he briefly went over with me.

On Tuesday, the VP of my old department called me to ask a question about the assignment logic (he never called me directly when I was actually in his department, funnily enough. I guess I’m moving up in the world). It took over an hour of reading through the SQL and, with the help of another developer, running snippets of it in SQL Server Management Server and analyzing the results, but I was finally able to understand how everything worked to answer his question.

The best part about that process was that I was totally engaged the whole time. I had a question at hand, and I was determined to understand the code well enough to answer it, and I genuinely didn’t want to stop until I did. Being a new developer can be kind of overwhelming at times, but I think I’m really going to enjoy this career once I get my feet under me.

Rounding the Home Stretch

This is my last quarter at OSU, and I am really looking forward to graduation. Don’t get me wrong, my experience in this program has been very positive overall and I’m enjoying both my classes this year, but I’m feeling a little burned out. Between 492 and creating a mobile app I’ve been diving head first into Dart and Flutter. In general, I really like learning new technologies and having coding heavy assignments, which these two classes are offering in abundance, but I’m not feeling as enthusiastic as usual. I’ve also been transitioning from my old job and getting everything in place to hand off all my responsibilities. That’s been a little stressful, but my last day in my old department is tomorrow and then on Monday I officially start my career as a software engineer. I am super excited about that!

All gripes aside, the Flutter framework is starting to click more and more, and it is gratifying to to see our project start to get off the ground. Starting a project is always the hardest part for me, so I think I will feel more excited and motivated the farther we get into it. I was having a really good time tonight working on some front-end code. I just need to get over that new language/framework hump where I feel like “man, I have idea what’s going or how to translate my ideas into functional code” and I am definitely getting there. Just gotta keep on truckin’.

I Got Hired!

I finally did it! I got hired as an associate software developer. This is the culmination of journey that begun over four years ago, back in 2017, when I set my sights on becoming a software developer in some capacity and started learning HTML, CSS and JavaScript with the hopes of getting myself hired somewhere as a web developer.

I started off working my way through Codecademy and FreeCodeCamp courses on my lunch breaks. I bought a few Udemy courses and began working on some small web dev projects but myself taught curriculum was not always well defined and although I was certainly learning quite a bit of JavaScript, web development and even a bit about data structures and algorithms, it felt at time like I didn’t have a lot to show for all my work. Although I did infrequently to junior web developers job postings I came across, I never was invited to so much as a phone interview during the first year of my self-education.

A turning point came in 2019 when I read a Medium article about Node.js library called Puppeteer. I had been working through some Udemy classes that focused on writing Node apps and had also some come across some YouTube tutorials for building desktop apps using Node and the Electron framework, but I had been feeling rather uninspired and had mostly just been following along video tutorials rather than designing and developing my own projects, but a light bulb flipped on when I read about Puppeteer, which is used to create web scraping and web automation apps.

I immediately envisioned how I could write an app that would automate some of my job duties. So I did. I presented it my company’s IT department and they were impressed. They set me up with one of the company’s senior developers and together over a period of seven months we created a .NET app that recreated and expanded upon the functionality of my Node app.

It was also around this time I started at OSU. Although I learned a ton in my quasi internship, my company required a degree before I’d be eligible to get hired full time as a developer. I decided to mostly put my job hunt on hold and focus on completing my degree. Now, with my graduation date less than 90s days off, I was eligible to apply to junior dev position that opened in my company, and I got it!

Diving into my Capstone project (after some hoops talk)

I just got done playing basketball. I play basketball just about every day if I can find a game or get one going. Thursday nights there is regular pickup ball at a local church’s indoor court. The church is right down the road from my apartment and the competition is normally pretty good, so I almost always try to make it if I can. I played six games today. I had two pretty good games (the first one I shot 2/3 from deep; the second one I had three points at the rim and beat a former NFL play off the dribble and then hit a floater in the lane), three okay games and one pretty bad game. A solid night overall!

If I could have any career in the world, I would almost certainly choose to be an NBA player. Getting paid millions of dollars to eat right, exercise and play basketball at the highest level, having all summer off, being able to tell my girlfriend “babe, I’m sorry but I have to go hoop. It’s literally my job.” Yeah, that all sounds pretty good to me. But, unfortunately I’m 6’2″ and not that athletic. I’m about as likely to make it to the NBA as I am to become the president of Russia. Fortunately for me, however, I’m pretty stoked on my second place career choice, which is being a software developer.

I imagine that my experience with my capstone will have a lot of similarities to working as a professional software developer. I’ll be working in a group of four to develop a mobile bike sharing app. There were a lot of really interesting project ideas available for us to choose from. I’m slightly disappointed I won’t be doing a project involving machine learning. I’ve never worked on a machine learning project or delved too deeply into the subject, but it seems very interesting and I gotta believe that ML technology will only become more and more important to and ubiquitous in our society in the coming decades. I guess I should look back into that machine learning Coursera course I signed up for last summer and then barely even worked on (cut me some slack, I had just finished Operating Systems I, by far the hardest class I’ve taken at OSU, at the end of the spring quarter. My brain needed a break).

All that said, I am really excited to be creating a mobile app. I’ve never developed a mobile app before, but in addition to my capstone, I’m taking CS 492- Mobile Software Development this quarter, so I imagine I’ll be getting a lot of mobile dev practice in the coming weeks. My group has decided that we will be using Flutter as our SDK for our project. It’s the SDK taught in 492, which three of our group’s four members are taking this quarter, so it seemed like the logical choice. I’ve been spending the past weak learning the basics of Dart, which is the language Flutter apps are written in. It is a statically and strongly typed compiled language with a syntax similar to languages in the C family. Like JavaScript, it has function hoisting, which I appreciate. The weird thing about Flutter that I’m still trying to wrap my head around is that everything is a widget. The Flutter documentation describes a widget as “an immutable description of part of a user interface.” I’m still figuring exactly what this means when it comes to writing and organizing the code. I’m gonna need to spend some time really dissecting the code of some Flutter apps to understand exactly what’s going on under the hood.

My First Blog Post

Well, I’m officially starting this blog for CS 467 assignment at Oregon State, but I’ve actually wanted to started a blog for a while. I’m a computer science student (just one more term!) but before I started studying CS at OSU, I got a BA in English at Ohio University. Back in my OU days I wrote a lot, mostly because I had to for school, but still, it was something I mostly enjoyed and something, I like to believe, I was pretty good at. These days I don’t write much besides code, work emails, Reddit comments and text messages, so it will be good to re-sharpen my writing skills, and maybe even write something others will enjoy reading.

But enough about my writing aspirations. Let’s get back to OSU and computer science. As I mentioned earlier, this blog is an assignment for CS 467, which is the capstone course for Oregon State’s post baccalaureate computer science program. This is my last quarter in the program. I just have to complete the capstone and the other class I am taking this quarter (CS 492 Mobile Development) and I will be graduating with a BS in Computer Science. It’s been a very good program and I’ve learned a ton, but I’m very excited to graduate. Juggling a full time job and school can be pretty exhausting at times.

At some point I’d like to right a bit of a retrospective about my experience with OSU’s program. Even though I had been teaching myself programming and learning some of the fundamentals of computer science for about two years when I enrolled at OSU, I’ve learned so much over the 2.5 years I’ve been in this program. My favorite courses have been CS 271 -Computer Architecture and Assembly Language (really interesting look at how the physical components of a computer and how software interacts with it at the most fundamental level), CS 325 Analysis of Algorithms (I like the learning about algorithms and data structures and the more academic concepts in computer science. I took this one through OSU Cascades, the Bend campus- I live in Bend, by the way.) and CS 340 – Introduction to Databases (building a full stack web app with a Python Flask backend and mySQL database was a lot of fun. Honorable mention to CS 344 – Operating Systems I. That class was too hard for me to say it was fun, but I did learn a ton and getting an A in the class was the most rewarding accomplishment I’ve had so far in this program. I’d like to write about all the class eventually, but right now I’m more focused on the classes I’m currently enrolled in.