Flutter — The bug no one knows about. Well, almost no one…

Alex Josef Bigler
Full Struggle Developer
4 min readOct 20, 2023

Hey there! It’s time for a classic “Why, Flutter, why?!” moment. But let’s not dwell on that until you understand the point.

Here’s the point. Sooner or later, you’ll face a situation where you need to pass information in a request header. At the very least, token authorization is passed as “Authorization”: “bearer blablabla”. By the way, I accidentally capitalized the name, let’s call it a Freudian slip. But let’s move on. I always believed that the http library was the BASIC framework library for working with HTTP REST requests.

Oh, how wrong I was…

In reality, it’s just a wrapper, much like dio.

And when I needed to shove a locale like “Locale”: “en” into the headers, I was puzzled. Why isn’t it working?

Probably, if I had developed the API, I would’ve noticed right away that the headers come in lowercase, would’ve changed it on the backend, and the issue would’ve been resolved.

But the API isn’t mine, and it’s not possible to ask for changes. I have to solve this problem only on my side.

So, I dug deeper and found this 👈:

In the library, before sending, every header is set to .toLowerCase(). I don’t know why it’s done this way, and I’m curious about the rationale behind this… Anyway, without much thought, I switched to dio. An even trickier library, which is essentially not a library but a full-fledged framework for handling requests.

Okay, I made the switch to dio.

Remember my previous articles about dumb decisions in Flutter? Well, that was just a warm-up.

As they say — plagiarize, but not word for word…🥲

I doomscrolled forums, GitHub issues, and StackOverflow threads, searching for answers. Some developers suggested workarounds, while others were just as baffled as I was.

It became clear that this wasn’t just an isolated issue but a recurring theme in the Flutter ecosystem.

After a couple of days

The BASED library. HttpClient in the very namespace of dart:

The funniest thing is that they did the same thing there… They think they’re smarter than everyone else — headers should be in lowercase. 🫡

** Nope. **

But after a couple of dozens of “issues” they added the ability to use headers in their original form:

They should have named the property blessAndPreserveHeaderCase. You know, just to be more safe…

Alright

That’s all, folks. Actually, judging by the scope of the problem — there’s no real problem. So, soon frameworks will decide for you how to name your classes and so on.

Nowadays, libraries are written for every little thing. Developers don’t think about how to implement a task; they first google a library and then solve the task within that library. It’s convenient, of course. Why write code when someone else has already written it?

So, here’s the catch, the code is written by a developer just like you, maybe a bit more experienced. But the more experience, the higher the cost of a mistake, and you’ll be the one paying for it.

--

--

Alex Josef Bigler
Full Struggle Developer

Enthusiast of new technologies, entrepreneur, and researcher. Writing about IT, economics, and other stuff. Exploring the world through the lens of data.