Skip to main content

Posts

Showing posts from September, 2023

Observer Pattern: The Hidden Magic Behind Flutter State Management

When I first started learning state management in Flutter, it honestly felt like magic. I'd change one variable, call setState , and the screen would just… update. Later I met ValueNotifier and ValueListenableBuilder , and it got even stranger — now only one widget would rebuild while everything around it stayed perfectly still. I hadn't written any code to watch for changes. I hadn't wired anything up. It just worked. And anything that "just works" without me understanding why makes me a little uncomfortable. So I did what any curious developer does: I went down the rabbit hole. I wanted to know how a value "knows" when to tell the UI to rebuild. Who is listening? How does the change travel from my variable to the pixels on screen? That question led me to something much bigger than Flutter — a classic software design pattern called the Observer pattern . Once I understood it, the magic didn't disappear. It just turned into some...

ListView Builder!

ListView.builder is a versatile Flutter widget that allows you to create scrollable lists efficiently, especially when dealing with large or dynamic lists. Unlike a traditional ListView, where you provide a fixed list of children, ListView.builder generates list items on-demand as the user scrolls, which can help save memory and improve performance. When we have to to deal with large amount of dynamically changing data or we have fetch data from the database, we have to use a ListView.builder widget.  The main difference between ListView and ListView.builder is one work with fixed data and other work with generated list items on-demand as the user scrolls, which can help save memory and improve performance. ListView.builder widget has some additional parameters, which are: itemCount,  is set to the length of the data source (myList), indicating the total number of items to be displayed. itemBuilder, defines how each list item is constructed. It receives an index, which ...

ListView and ListTile!

Listview and Listtile are basic widgets, which are used to make a scrollable lists of item in a mobile app. They are essential component for building app where we need various type of lists, such as menus, chat message lists and etc. ListView: Listview is a widget used to create a scrollable list of children. It can hold a list of widgets and automatically handles scrolling when the content exceeds the available space. ListTile: Listtile widget is designed to represent a single item within a list. It typically contains title, subtitle, leading or trailing icon and can be made tappable. Key Properties of listTile: Title : The primary content of the list item. Subtitle : Optional secondary content. leading : A widget display before the title. trailing : A widget display after the title. Ontap : A callback function that is triggered when the listtile tapped. Both Listview and Listtile are highly customizable, and you can style them according to the app design requirements. They are versat...