Flutter Null Safety Unit Tests: Late for Tests

Dart added the late keyword as part of their null safety release and it is very useful, particularly for testing. As a quick review null safety means telling the compiler that some variables will never be null. Any variable declared without a question mark following the type declaration is null safe. So String name is null safe while String? name can be null. Given that the question mark is new syntax all code written before null safety was introduced now declares all variables as cannot be null. The new late keyword tells the compiler that although a variable is not [Read on…]

GO Obsolete Dependencies

This article refers to problems that would probably only be seen for those running older versions of GO. If you know all about module management and are running up to date versions of GO with modules then you probably won’t find anything useful here. Up until very recently I was running a pre-module GO version and that bit me. If like me, you haven’t made the switch to modules and some of your dependencies appear to be missing functionality that you’re sure is there, read on. Signs of Trouble It all started with a fairly innocuous error message from the [Read on…]

Null Safety firstWhere

The change to null safety in Dart is a good thing, however a common pattern I used firstWhere for got broken. The pattern is to search a collection and return null if the search returns nothing. The short answer is that you should use firstWhereOrNull instead in this case. Example of the Issue Before the null safe version of Dart the code would look like this: The naive conversion to null safety would be: But this conversion will show a warning that the test if ( null == val ) is not required because the value can’t be null. What’s [Read on…]

GOLANG unexpected directory layout error

I got this error trying to compile some GO code today and the usual searches didn’t immediately turn up the answer to my issue. The error output made it seem that something was wrong with the path setup in my GO environment which lead me into a dead end of searches and attempted resolutions. The actual problem was very simple. I was importing with a path relative to the project directory and GO no longer approves of that. All import paths should now be relative to the src directory within the directory given by the $GOPATH environment variable. Bad, don’t [Read on…]

Java Object Creation is Very Fast

I was recently doing a code review and suggested some refactoring to extract some behaviour into separate classes. A common question came up, “This code has to be fast so shouldn’t I avoid object creation?” My instinct is always no, ignore those considerations when coding, let the compiler handle it until proven that you have to step-in. This time I avoided my laziness and cross checked that instinct. The top result on a quick search said that object creation should be avoided due to expense, but mentioned a Pentium II so I was suspicious. I’m not going to link to [Read on…]

OAuth2 – Get a Token Via REST Google Sign In

Every time I want to get an access token for a REST service for an integration test or other non-interactive use I forget how to go about it using OAuth and then have to piece it back together. My use case is wanting to give some headless process access to a user level service like Google Calendar. This post is now my permanent memory of how to do it, I hope it helps someone else. The Steps Get an account on the service Define the client for OAuth access – example using a Google API Get the code using an [Read on…]

Widget Testing and Flutter 1.20.1

After the upgrade to Flutter 1.20.1 none of my widget tests worked anymore. On investigation I found that my widgets weren’t getting rendered at all, i.e. their build method wasn’t being called. This is a preliminary result but I was doing this in my test: Seems like that no longer works and must now be: I haven’t seen anything in the release notes that suggests this should be required. I’m still investigating but in case this helps someone else I thought I’d put it out there.

Custom Domains for AWS API Gateway Without Route 53

There’s some very good articles on using the Serverless Framework to setup custom domains for API Gateway endpoints. For my use case I wasn’t planning to use Route 53 for DNS hosting for the domain so they were missing a crucial step. This post documents that step. Configuration Follow the article linked above to setup the plugin and basic configuration. The configuration for the custom domain in theserverless.yml file is almost exactly as shown in the article with the exception of the createRoute53Record line which I changed to turn off the Route 53 DNS interaction. Setup Steps With that change [Read on…]

Compressing POST Requests in Flutter

Posting to REST endpoints from mobile applications is a very common use case. Some of those POST requests can get a little large and it can be useful to compress them before sending to save the user some data. It turns out to be very easy to do this compression in Flutter and I didn’t find resources for it when I went looking so I thought I’d record the steps I took. Code Example This is pretty much just the standard example of using POST. The two things that need to change to send compressed content is to add the [Read on…]

‘What’s My Name’ for Serverless Framework

It is frequently useful to know the name of a generated resource in the Serverless Framework when building for AWS. I had been struggling with this when I needed to refer to a generated resource in a separate CloudFormation section. After much searching I found a very useful trick that is probably already well documented but I’ll add my small bit of amplification here. Finding the Generated CloudFormation Serverless works by generating a CloudFormation template based on the serverless.yml file. This generated file is accessible in a hidden subdirectory of the directory that contains the serverless.yml file if you run [Read on…]