A collection of Flutter Hooks inspired by React's react-use
library. This monorepo contains multiple packages providing different categories of hooks for Flutter development.
Package | Description | Version |
---|---|---|
flutter_use |
Core hooks library with essential utilities | |
flutter_use_audio |
Audio playback and control hooks | |
flutter_use_battery |
Battery state monitoring hooks | |
flutter_use_geolocation |
Location and permission hooks | |
flutter_use_network_state |
Network connectivity hooks | |
flutter_use_sensors |
Device sensors hooks | |
flutter_use_video |
Video playbook hooks |
For the core package:
flutter pub add flutter_use
For specialized packages:
flutter pub add flutter_use_audio # Audio hooks
flutter pub add flutter_use_battery # Battery hooks
# ... and so on
Try out all hooks with live examples at: https://wasabeef.github.io/flutter_use/
Core package: flutter_use
useToggle
anduseBoolean
β tracks state of a boolean.useCounter
anduseNumber
β tracks state of a number.useList
β tracks state of an array.useMap
β tracks state of a map.useSet
β tracks state of a Set.useStateList
β circularly iterates over an array.useDefault
β returns the default value when state isnull
.useLatest
β returns the latest state or props.usePreviousDistinct
β likeusePrevious
but with a predicate to determine ifprevious
should update.useTextFormValidator
β reactive form validation with real-time feedback.
Core package: flutter_use
useInterval
β re-builds component on a set interval usingTimer.periodic
.useTimeout
β re-builds component after a timeout.useTimeoutFn
β calls given function after a timeout.useUpdate
β returns a callback, which re-builds component when called.
Core package: flutter_use
useFutureRetry
βuseFuture
with an additional retry method.useDebounce
β debounces a function.useThrottle
β throttles a value to update at most once per duration.useThrottleFn
β throttles a function to execute at most once per duration.useError
β error dispatcher.useException
β exception dispatcher.
Core package: flutter_use
useScroll
β tracks a widget's scroll position.useScrolling
β tracks whether widget is scrolling.useClickAway
β triggers callback when user clicks outside target area.useCopyToClipboard
β copies text to clipboard.
Core package: flutter_use
useEffectOnce
β a modifieduseEffect
hook that only runs once.useLifecycles
β callsmount
andunmount
callbacks.useMount
β callsmount
callbacks.useUnmount
β callsunmount
callbacks.useUpdateEffect
β run aneffect
only on updates.useCustomCompareEffect
β run aneffect
depending on deep comparison of its dependencies.useFirstMountState
β check if current build is first.useBuildsCount
β count component builds.
Core package: flutter_use
useLogger
β logs in console as component goes through life-cycles.
Package: flutter_use_sensors
useAccelerometer
,useUserAccelerometer
,useGyroscope
, anduseMagnetometer
β tracks accelerometer, gyroscope, and magnetometer sensors.
Core package: flutter_use
useOrientation
β tracks state of device's screen orientation.useOrientationFn
β calls given function when screen orientation changes.
Package: flutter_use_battery
useBattery
β tracks device battery state.
Package: flutter_use_geolocation
useGeolocation
β tracks geo location and permission state of user's device.
Package: flutter_use_network_state
useNetworkState
β tracks the state of apps network connection.
Package: flutter_use_audio
useAudio
β plays audio and exposes its controls.
Package: flutter_use_video
useAssetVideo
anduseNetworkVideo
β plays video, tracks its state, and exposes playback controls.
useEvent
β subscribe to events.useFullscreen
β display an element or video full-screen.usePageLeave
β triggers when mouse leaves page boundaries.usePermission
β query permission status for apps APIs.useMethods
β neat alternative touseReducer
.useSetState
β createssetState
method which works likethis.setState
.usePromise
β resolves promise only while component is mounted.useObservable
β tracks latest value of anObservable
.
Unlicense β public domain.