From the course: Flutter Essential Training: Build for Multiple Platforms

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Creating your own custom widget

Creating your own custom widget

- [Instructor] At this point, we have a number of chat bubbles elements built under this list view. And that is pretty great progress for you already. However, as a software engineer, do you think this is a maintainable or readable way of building this part of the UI? We are constantly duplicating code for doing the same thing, just with minor differences. Also, it is not so maintainable as well, because if I make a change in this child, like making this too black, I will have to redo that modification in every child here. This is more prone to human errors. So can we extract this out as a different function with parameters that return a widget, and then we can call that function directly here and make the code more readable? Let's try it out. I'm copying this out, and let's create a method here called getChatBubble, which takes an alignment and a message. It will return a widget. So here, you can return the entire…

Contents