Flutter Clock - My Submission

Jan 19, 2020

I came across the Flutter Clock contest more than a month after it was announced. It was not long before Christmas and I had a month left, but I like Flutter, so I immediately decided to give it a shot. I quickly had an idea of my creation: when I visited Hungary last summer, I visited my good old former colleague Miklos Vegh, who is—besides being a CAD software engineer—very proficient in PCB design and electronics. One of his cherished projects was a Nixie clock. If you haven’t seen Nixie tubes: they illuminate digits and some symbols placed inside a tiny glass tube. See this website. If you Google "Nixie Tube clock kit", you can see low- and high-priced versions of various designs.

I love the aesthetics of Nixie Tube clocks, so my choice was to bring that experience to the Flutter Clock contest. The library provided by the contest also provides extra information such as weather and temperature. I had an idea to create a bottom portion of the clock where I’d display this information in the style of Vacuum Fluorescent Displays. VFD is an older technology than LED or LCD displays, so in my mind I still preserved some retro feeling. This certainly could have been a choice if I targeted a Nixie Tube steampunk route, but that was not the direction of the design.

I started to study Nixie tubes and think about how I could synthesize the visuals. One distinctive feature is the shape of the digits. I could either draw the digits, but it could be a simpler solution to find a font that closely resembles Nixie tubes. The font definitely has to be Sans Serif and very thin along with specific features of various digits. This Design Stack Overflow topic has a lot of very good choices. I even purchased TTChocolates for mobile app distribution, but in my submission I use a thin-weight version of Roboto Mono. That’s a Google Web Font, so the judges can potentially use it more freely for their own purposes (I’d be so happy to see this as a clock choice in some app). Roboto Mono’s zero digit has an unwanted crossover and the digit 1 has the cap, but I think overall it’s still curved fine and thin enough. It’s 95% close to what I want (TTChocolates would be 100%). The fact that it’s monospaced can help a lot with the sizing and position of the tubes.

The bottom portion also uses a Google Web Font: VT323. That is also a monospace font and its pixelated design gives a very nice retro feeling. I only had to add some background pattern and a foreground grid which would represent the VFD control grid. Normally that’s a hexagonal grid just like what someone would see in (most of the) Nixie tubes, but for simplicity I went with a rectangular grid here. The hexagonal grid would have been too small: it could not have been generated with satisfying or visible aesthetics.

I modularized all widgets into sub-widgets, taking full advantage of Flutter’s principles. While other UI frameworks discourage using an overly complex or deep widget hierarchy, Flutter’s internal algorithms are linear—O(1) algorithmically—which allows composition of many widgets without significant performance impact. This way, widgets can be lean and focus only on their specific task. Separation of concerns is awesome!

The VFD Widget, for example, is composed of 3 VFD Lines, each of which is composed of individual VFD characters. The lines could have been Text() widgets of the whole line strings, but then I’d need to paint the whole foreground and the background in one run: towards the end of the line this caused offset artifacts in the delicate patterns compared to the monospace font. When each character has its own small foreground and background painter, I can avoid the gradually increasing offset problem and several calculations. There’s also a trick that I can reuse the same painter for background and foreground painting: the hairlines of the two need to perfectly align anyway, so we might as well use the exact same code and comply with the DRY principle as well.

The Nixie widget part of the clock is composed of 8 separate Nixie Tube widgets. The tubes have background and foreground painters that are responsible for drawing the tube outline, the legs of the tube, the internal hexagonal grid, and some internal details like the hanger rings. The digits are exactly lined up in order as in a real nixie tube. I had to make one distinction though: I was able to light up the given digit in that order, but the visuals weren’t satisfying. So the widget always takes out the active digit from that order and brings it up front right behind the hexagonal grid but above all the inactive digits. This decreases the emulation’s reality but increases contrast and helps readability.

At a high level, I’m using the InheritedWidget pattern to deliver the extra information to the desired widgets within the widget tree. For more details please check out the full GitHub repository: GitHub Repository. Also check out this live demo. This clock doesn’t look as good on Firefox by the way, but let’s not forget that the web platform of Flutter is still in beta and under development. So I’d advise viewing the live demo with Chrome right now. Overall Flutter in itself is a new technology and I’m extremely happy that we’ll have something that can target Android, iOS and web with the same codebase. Last time I saw such technology was the PlayN framework, which was a Google-backed technology as well, and this is why our mobile game has an online demo. In the future I want to rewrite Deal-O-Round in Flutter.

As far as the Flutter Clock goes, I also thought about creating a fun animated clock along the lines of the Google I/O 2018 digit animations. I have a concept and maybe I’ll implement that because I’d like to learn more about Flutter animations. Stay tuned for follow-up posts and please cheer me on for a placement in the Flutter Clock contest.

Comments loading...