Mistakes that Flutter Developers Should Stop Doing - Part one

Umut Arpat
3 min readJan 28, 2023

--

Photo by Kenny Eliason on Unsplash

1000 lines of code

A dart file should be only consisted of 150–200 lines of code max. (Ofc. there could be exceptions)

When it is bigger than 200 lines of code there is a high chance of widget separation issue.

Before Separation

After Separation

After Separation

Of course you should only do this when widgets are bigger. Don’t just separate a widget to another class if it is only Text(“Hello”) just like in the example.

Separating widgets to functions instead of classes

When you separate widgets it should be Stateful or Stateless classes, Not functions.

Using functions is anti pattern for Flutter widget tree. And it may lead to performance issues and bugs.

Using classes is the right way to do this plus you can reach context.

Bad

Good

Not writing unit tests

A Flutter Developer should write unit tests for code maintenance and in order to become a hireable developer.

Writing unit tests will make your actual code more readable and SOLID compatible. If your code isn’t SOLID compatible it will be harder to test.

Thus if you care about unit testing your code. It will make your code quality better along the way.

Just right click your controller or view model and click on Go to Tests:

It will create a test file for you in “test” folder. Inside “test” folder, folder structure can be same as your “modules” folder structure.

You can now write your own tests! Depending on the state management. It can be a different experience.

I will discuss that topic in the future for my Riverpod, flutter_hooks folder architecture article. Stay tuned!

Thank your for reading.

--

--