7. Best Practices for your Flutter Project

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hi thanks for taking a look into the video, I really hope you enjoyed it and could learn something from it. If you have any questions please let me know :)

👍︎︎ 1 👤︎︎ u/MyracleDesign 📅︎︎ Dec 22 2020 🗫︎ replies
Captions
hello my friends and welcome back to another episode of flutter explained today we want to talk about the top seven best practices for flutter that i have learned from you guys i asked on twitter what is your best practice for flutter and you answered really well to that question you gave me 130 likes for this tweet and thank you so much for that response and so i thought i make a video where i clearly distinguish all the parts i try to enhance one of them and i want to talk about each of them i will not name every name that gave me that comment but down in the video description below you will find the twitter feeds and everything where the people discuss for example about stream builder and not stream builder and also all the different comments about the best practices so check out the tweet below and now let's get started but before we begin let's talk about these guidelines and best practices all of these are just guidelines or best practices so you can follow them but they are not written in stone and you cannot change them that wouldn't make sense so take these as your guidelines that you can use to improve your projects if you don't have something already in place and discuss that with your team because usually team decisions are better than single decisions so think about that discuss it with your team bring in good arguments and if you want to bring that into your team and your team is not happy with it yet maybe try to convince them with good considerations and pros and cons all right finally let's start with the first one linting and code analysis all right so linting in flutter code analyzes or the analyzes options i highly recommend you to use that because it allows you to bring up code smells and also shows how to structure your code it directly implements the right solutions for you and shows them inside of your ide that have the benefit that a you have a lot of complexity in software development right so you have to understand how functions work what all this kinds of stuff is doing so you don't really want to care how a function should look like or how to structure your projects for that you have analyzes options that allows you to enforce some things like for example single quote and double quote which doesn't look like much but it helps you if you stick aligned with one pattern here also you don't want to really have this complexity inside so the best thing is to enforce it so everyone should be on the same page with it that is my personal opinion i know there are different ones but i really like if the code enforces me to good patterns and best practices another thing to keep in mind is that newcomers and beginners in your code will very fast will understand these rules if they are enforced or will be visible inside of your ide in the tweet they have or there have been the recommendation for a package called lint which i personally really like and use and i'm very happy with it so far because it narrows down the analyzes options already for you so you don't have to specify everything for yourself another package solution would be the one from flutter project which is pendant it's also very famous already but here it is very narrowed down to the project of flutter and have a lot of smarts for this project so check out both of them understand what is the benefits and disadvantages of that and also try to implement your own rules on top of that because that is possible you can take a linting rule set and implement your own rules additionally that will make it way better and it's give your own code style discuss that with your team and you will find the best possible way for you and your team [Music] single responsibility for your widgets is very important and that means for example think about the package internal widgets that you get from flutter so example the text widget in the text widget it only have the responsibility to show text and actually it is all what it is doing a container surrounds widgets and a column shows something in a column a row in a row so it is very clear and understandable where this comes from this allows your widgets if you create one a lot of functionality and brings a lot of conciseness and understanding of the code into it it's easier to refactor to rename to understand what is happening so i highly recommend you to make it single responsible but be careful single responsibility does not mean you only have one widget or you just create one widget itself it could be a composition to create a screen so the responsibility would be to composite a lot of widgets into one screen or hold the state for a lot of widgets inside of one widget all of these are responsibilities and this allows you to bring these benefits into your code very easily we talked already about single responsibility in another video which was the solid principle and you know these things are a little bit similar so if you want check out the video up in the info box to understand the single responsibility a bit better fantastic but now let's go to the third point [Music] the third point is one of my favorites because it is so true for a lot of frameworks programming languages and anything else it is that you should read the repository and understand what happens there and learn from it there is no one better who a team who is dedicated to the framework and works on it so think about it the flutter framework is a package on github it allows you to see all comments all code changes poor requests understand how people think and also like top engineers of google top engineers on the world because we are a fantastic community who are working together and all of them have their inspiration they have knowledge they have ideas and so for you if you want to learn from that it is very important to know where to look at one basic example is i got a question on linkedin how to test pan and pinch allowance on a screen so what i did is i searched in flutter and in flutter we have the interactive widget and showed him that everything in flutter is tested so i send it to him the testing of this interactive viewer so we learned something from that and you should too you learn from pull requests from comments on pull requests maybe create your own pull request you can learn from issues you can learn and learn and you can communicate with the flutter team so check out absolutely the repository of them check out how the packages that you use are created talk with the community that will be a really big investment in your career as a software developer and will make you even stronger developer the next point is for me personally a little bit challenging and i'm always doing it wrong so the fourth best practice that i can give you is keep your widgets short concise and as small as possible [Music] yeah i'm doing myself hard with that so you take your widget you write and write and write and write and suddenly you have 600 lines of code and you don't even know where they come from it's going close to the single responsibility if you remember but also into how you separate your code from your widget and where you bring your styles and everything inside sometimes you just put everything in one line the guy who is answered there was saying that lines of 200 inside of your widget and i would highly recommend to do that because 200 lines of code is a good print on how big a file should be so then you would start to extract the things this makes the widgets usually very small and you have a lot of files but think about it you are very easy to navigate through your code and there was one question that i found interesting and that was regarding to naming of these widgets if you have a lot of small widgets how would you name them and this is one of the biggest challenges in software development finding good names so of course that makes it harder but on the other side if you find a good name for something you can find these things over and over again and you can reuse it maybe later and so on and so forth so i highly recommend to do that check out on the twitter feed and also try it out yourself how i go usually for is i create a lot of a large widget and then i try to separate all the different parts into own widgets so that i have at the end one large widget into broken down into smaller widgets i catched you right away in the middle of the video first of all thank you for watching now hit the like button if you have the time subscribe to this channel if you haven't yet and now go further with the video [Music] keep starting development with cicd in mind cicd stands for continuous integration and continuous delivery and if you think at the very first moment on these both things you will have an easier time in the future because what is the icd i created already a video for that where you get the information how it works there we created it in code magic and this allows us to create a pipeline what is a pipeline just in short well you push your code to github github has like a master branch where you say whenever there is some new update you want to trigger the ci so the continuous integration which runs all the tests all the build functions and it will try to bring your app in a state that is deliverable after that this triggers the cd which is continuous delivery and tries to publish that file that is generated so an apk or any ios file into the different stores so you would push something into master and suddenly it appears in app store or google play store it's not always that easy i know so take your time try to understand how cicd works give it time in the front because it allows you to run your tests permanently which gives you so much benefits in code quality and allows you to write your tests and even if you are too lazy to run them locally you will at least find it in the build pipeline that something is wrong why is it a good backs best practice check out all the big projects every one of them has at least one build pipeline so check it out understand how it works i highly recommend you to keep that in mind in the beginning because it makes your delivery process so much easier okay this brings us to point six how do we keep styles don't implement them hard-coded into your widgets and this is also a trap that i'm falling sometimes into especially in my site projects where i take all my colors fonts stylings and so on and so forth and just hard coat them directly into the widgets the benefit of that is it is very easy to write quick and dirty you are very fast finished but the problem is whenever you want to change the color palette in the future and believe me this happens more often than it should do then you have the problem that you now have to remove all the different parts you have to modify so many files you have to identify widgets that contains these styles and take them out improve that with your functions and so on and so forth so i highly recommend you if you start a new project jump right into it and work with a theme use the context of method get the theme get the colors that you need the styles that you need and with that you are way faster in the future and you don't have to care too much if something is modifying in the future all right and now the last best practice of today and i think it is one of the most important ones is don't start without a plan [Music] if you fail to prepare you prepare to fail right so this is from benjamin franklin and this sentence tells a lot so that means if you just start in your project and you think let's write some code let's hack it down it will be perfect and i will be finished in one day first of all most pro nearly no project really finished in one day that never happened and think about it if you are working really for a company you work on features sometimes a week and you want now to finish a whole application in one day impossible doesn't work take your time to understand that then your side projects will be more successful another part is create a wireframe instead of just trying to develop and think yeah i will make the design on my head during the code this never happens well so take your time even if you just draw it on a paper with your pencil in a basic scrabble or scribble that makes it way better than just writing code and hope that the result will be good last but not least if you make this it will give you more motivation it will bring down and cut down widgets already maybe already on the paper you will understand what you can write as an own component what should have its own widgets where should you work the hardest on and all this gives you way more motivation keeps you to that and if you are really really into that project write some user stories because nothing feels better than to hit a to-do make it finished and be ready with your task so think about it and try that alright so that's it for this year 2020. thank you so much that you have supported us and helped us in all the way it was a fantastic year we reached a lot of goals we achieved nearly everything that we wanted to achieve which is fantastic for us which is fantastic for you and i'm very happy that we are where we are today this saturday we will have a live stream masted event i and i hope you will find that up in the info box and we want to talk a little bit about our last year what we have achieved i mean matab is now a software engineer i am still self-employed we want to talk about that bring your questions with you we want of course to talk a little bit about flutter maybe we also write one or two lines of code we don't know yet let's see and thank you very much for joining us today enjoy the rest of your week hit the like button subscribe to this channel if you haven't yet and see ya the next time bye guys
Info
Channel: Flutter Explained
Views: 10,454
Rating: 4.8672986 out of 5
Keywords: best practices, flutter, code practices, flutter project structure best practices, flutter architecture patterns, flutter best practices github, flutter architecture best practices, flutter best practices medium, flutter practice, flutter app development best practices, flutter layout best practices, flutter sdk, flutter clean code, flutter mvvm, flutter best practices, flutter best practices and tips, flutter tutorial, software development
Id: bn5e95b3uLY
Channel Id: undefined
Length: 14min 35sec (875 seconds)
Published: Tue Dec 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.