Skip to content

Flutter Compositions vs Vue Composition API

Flutter Compositions draws heavy inspiration from Vue, yet the platforms differ. This guide highlights what carries over and what changes.

Similarities

  • Composition mindset: Declare reactive state, computed values, and lifecycle hooks inside setup().
  • Core primitives: ref, computed, watch, and dependency injection with provide / inject.
  • Lifecycle naming: onMounted, onUnmounted, onBuild mirror Vue’s hooks.

Key Differences

AspectFlutter CompositionsVue Composition API
RenderingReturns a Flutter widget treeReturns render functions / template state
Reactivity enginealien_signals (explicit refs)Vue’s proxy-based reactivity
Hot reloadre-runs setup(); refs preserved by declaration orderreruns setup() automatically; proxies keep deep reactivity
Dependency injectionInjectionKey<T> for compile-time safetyKeys are string/symbol; type safety is up to you

Working with Props

  • In Flutter, props are immutable fields. Use widget<T>() to get a reactive view of the latest props.
  • In Vue, props are already reactive proxies accessed directly.

Updating the UI

  • Compositions relies on Flutter’s widget diff. Only widgets that read changed refs rebuild.
  • Vue patches the virtual DOM; the framework updates DOM nodes directly.

Porting Tips

  1. Convert Vue ref/reactive to Flutter ref or custom model classes.
  2. Replace template directives (v-if, v-for) with Flutter widgets (if/switch, ListView.builder).
  3. Map Vue plugins/providers to InjectionKey + provide/inject.

Further Reading

Released under the MIT License.