Example codes (with additional features) of Flutter device calendar plugin, display a list of events & allow interacting with the device's calendar
State management: Mimic Scoped Model using Provider
Data model: CustomEvent
- Scroll to nearest-to-date event on arrow button press
- Event item animations (slide / press trash bin to delete event)
note: create/edit events with recurrence rule is not stable
FutureBuilder
is only used for building Widgets with 3 states only: initial -> processing -> done. It can not rebuild itself after that (unless you're overwriting the future instance, or calling a async method in the future param, but those are bad practices) If you want to do more with the snapshot data later, like deleting/modifying it & update UI, useBuilder
,StreamBuilder
orValueListenableBuilder
instead.- Make state management as consistent as possible, either by using a state management tool (like
Provider
,InheritedWidget
,Scoped Model
...) or just passing state data via constructor, don't create a mixed mess of both.- Note: Passing state objects through the widget tree is not recommended by many as this is extremely non-scalable as the app grows bigger.
- Don't abuse callbacks, as the above note mentioned, you may never know if you suddenly need to wrap your widget by another widget (and Flutter is infamous for that), implement some kind of event notifier/listener or use
ValueNotifier
class. - Dispose AnimationControllers immediately when they are not needed anymore, it may cause conflicts with otherwise, even when you dispose them in Widget life cycle's
dispose()
method. - Operator overloading: now this is a pretty grey area, use it with immutable & unique object only!
- Always break down big widget into many smaller ones, don't use function for that. Creating many scoped context is good, it won't rebuild the entire tree when the something is modified.
- Push
Provider.of
as far as possible down the widget tree, so that the bigger ones (usually on the above) won't get rebuilt to often. - Remember to utilize
listen: false
inProvider.of