Skip to main content

Posts

How to use controller to manage state from outside of a StatefulWidget in Flutter

  A stateful widget is a widget with mutable state and rebuild itself upon changing the state. There are several state management approaches to manage state as specified on flutter.dev . It is quite easy to update its state from inside using the setState method but if we would like to update it from outside then we have to use one of the available packages.  Today i am going to show you that we can also use controllers to manage state of a stateful widget from outside just like TextEditingController is used in case of TextField or a TextFormField . This approach is also suitable if we are creating a package and don't want to use other state management packages as dependencies. Let's modify the default increment app that the flutter plugin generates. First create a controller class as follows: class MyController {  VoidCallback onIncrement ;  void dispose () {     onIncrement = null;   } } MyController is a simple class with onIncrement property of type VoidCallback and dispos
Recent posts

How to create custom widget based Info Window for Google Maps in Flutter?

Flutter is all about widgets. But in case of Google Maps it is not completely true. There are some components which are not flutter widget yet (e.g. Markers and Info Windows). In case of markers it is still easy to change icon but info windows are not allowed to be customise. Currently info window objects (not widget) can only take "title" and "snippet" and both of these needs to be "String" strictly. UPDATE 19/01/2021 : I have published a package on pub.dev for this functionality. Please checkout  Custom Info Window . Custom InfoWindow Currently supported InfoWindow Today I am going to create a widget based info window which can take any widget and show on the top of marker pin when the marker is tapped. Also this will remain on the top of marker pin even if the user starts to change camera position by swiping unless map or another marker is tapped. At the time of writing this post "google_maps_flutter 0.5.28+1" is available on "pub.dev&qu