5 MORE mistakes every new Flutter developer must avoid.

5 MORE mistakes every new Flutter developer must avoid.

Ayush Pawar
·Feb 19, 2022·

4 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Introduction
  • Mistake 1
  • Mistake 2
  • Mistake 3
  • Mistake 4
  • Mistake 5
  • Bonus Tip
  • Conclusion

Introduction

Well, recently I wrote about 5 mistakes that every new Flutter developer must avoid. Looks like a lot of people related to that post so I decided to add 5 More mistakes that probably every new Flutter developer makes.

If you have stumbled upon this article before making any of the mistakes then congratulations! Read this article and try to avoid these habits in your Flutter development journey.

Mistake 1

Not learning from in-built documentation. This is probably one of the biggest mistakes people make. Not only beginners, but even people who have a fair amount of experience don't read the in-built documentation.

What I mean by in-built documentation is that Flutter has created documentation inside the Dart code of a widget. For example, look at the image below. Screenshot (118).png

If you hover on the ListTile and tap Ctrl+B, you will be taken to its source code. There, you will see tons of comments explaining what each line does. You will find this for every Widget available. If you are stuck somewhere, READ the internal docs first and then search for answers on Stackoverflow.Mom In Pool With Kids 18022022192632.jpg

Mistake 2

Using Listviews over Listview. builder. Well, this is a mistake that newbies make. Even I used to do this until I got the hang of builders.

Don't do something like this

// A code to render 5 containers in a list
ListView(
                  children: [
                    Container(
                      color: Colors.red,
                    ),
                    Container(
                      color: Colors.red,
                    ),
                    Container(
                      color: Colors.red,
                    ),
                    Container(
                      color: Colors.red,
                    ),
                    Container(
                      color: Colors.red,
                    )
                  ],
                )

Instead, do this

// A code to render 5 containers in a list
ListView.builder(
                    itemCount: 5,   // tells how many items should we have in the list
                    itemBuilder: (context, index) {
                 // return whatever widget you want to return.
                      return Container(
                        color: Colors.red,
                      );
                    },
                )

See the difference in the neatness and efficiency of the code?. The index variable is used to track the widget number. For example, if there are 5 items, then index = 0 will represent the first item, and so on...

Mistake 3

Overusing packages. Erm, if you have read the first part of this series then there I said that you must use packages wherever you can but I also said that use it where it saves a good amount of time and code.

Do not use packages to edit your snack bars and stuff like that. You can do it on your own by just adding 5-7 lines of code. Understand the trade-off. Adding 5-7 lines of code will only take seconds or probably a minute or two. You don't need to add packages and increase the app size for that. Roller Coaster Dad 18022022192516.jpg You have to use packages where it will take probably a good amount of time or thinking to implement the feature. Like building a GPS feature from scratch.

Mistake 4

Hard coding styles in your text. This is also a mistake that even the intermediate folks make. This is not exactly a mistake but a bad coding practice I would say.

Whenever you are using a style attribute in your text, do not do this.

const Text(
 "Log In with Magic Link",
  style: TextStyle(
  color: Colors.white,
  fontSize: 18,
  fontWeight: FontWeight.bold),
),

Instead, do this. This makes your text-style reusable and makes the code clean and efficient

// Create a variable above your Build method
TextStyle s1 =  const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,);

// Then do this
child: Text("Log In with Magic Link", style: s1),

Mistake 5

Not using linting. Well, beginners don't even know what linting is, so let me explain.

Linting is the process of checking the source code for Programmatic as well as Stylistic errors and unformatted code. You can find the current rules in the analysis_option.yaml file. This file is present in your root directory. It is advised to use this package for the best linting environment. You can read the documentation and configure it in your project. It is super easy to follow and configure. Tyler The Creator Demon 18022022192343.jpg

Bonus Tip

If you are guilty of doing these mistakes then you are on the right track, my friend. Almost everyone makes such mistakes in the beginning and the rest of them read such articles beforehand. I have probably made almost all the 10 mistakes in my Flutter journey. Sir Isaac Newton 18022022193742.jpg

Conclusion

With this, we conclude our article on the 5 mistakes every new Flutter developer must avoid. If you liked the article, then do share it with other friends and drop me a follow.

Keep following CSwithIyush for tutorials, tips/tricks on Flutter and DSA.

Did you find this article valuable?

Support Ayush Pawar by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this