flutter_watchos 0.1.0 copy "flutter_watchos: ^0.1.0" to clipboard
flutter_watchos: ^0.1.0 copied to clipboard

Platform detection and utilities for Flutter apps running on Apple Watch (watchOS). Provides runtime checks for watchOS, device info, capability queries, and Taptic Engine haptics.

0.1.0 #

The Digital Crown now scrolls the way it scrolls a native watchOS scroll view, and WatchScrollPhysics moves like a native scroll view under the finger, as measured on a watch. The crown API changes with it:

  • The crown needs no code. An app built with flutter-watchos 0.1.0 scrolls with a hidden native scroll view behind the Flutter content, so watchOS supplies the acceleration, the momentum, the detent haptics, the spring at either end and the crown scroll indicator. Among the vertical scrollables on screen that have something to scroll, the crown drives the frontmost one that covers at least 40% of the screen, or the largest when none does; a NestedScrollView scrolls as one, and a page view or a wheel settles on whole pages or items. An app that still compiles its own watchOS runner keeps the older crown until the runner moves to the current template.
  • WatchCrownScroll now chooses that scrollable, for a screen with more than one, and still gives its subtree WatchScrollPhysics. enabled: false keeps the crown off the scrollables under it, and scrollIndicator: false hides the crown scroll indicator.
  • WatchScrollPhysics follows a native scroll view: UIKit's rubber band (0.55 of the finger's travel at the edge), a critically damped spring at either end, UIKit's fling deceleration. The maxStretchFraction and edgeRelaxation parameters are removed.
  • WatchCrownScrolling and WatchCrownSensitivity are removed. A native scroll view's crown sensitivity and detent haptics belong to the system, so there is nothing left for them to set. Remove the calls.
  • WatchCrown is unchanged: while an app reads the raw crown, the crown goes to it and does not scroll.

The watch's safe area leaves the clock out by default from flutter-watchos 0.1.0: it keeps content clear of the display's rounded corners only. The package gives the clock's band to content that has to start below it:

  • Added: WatchStatusBar.heightOf(context), the height of the band at the top of the screen that the clock sits in. WatchOSNativeBindings gains clockBandHeight.
  • Fixed: setting WatchStatusBar.hidden to a new value now asks for a frame, so the clock hides or shows even on a screen that does not repaint. WatchStatusBar gains three test seams marked @visibleForTesting: bindingsOverride, isWatchOverride and scheduleFrameOverride.
  • Example: the home list no longer relies on the safe area to keep its first row clear of the clock. It covers the whole screen, starts its first row below the clock with WatchStatusBar.heightOf, and adds the safe-area insets to the rest of its padding, so its rows scroll under the clock and down to the bottom edge, as in a native watchOS list. The crown screen, which does not scroll, keeps its SafeArea.

The API docs changed too:

  • Docs: every public member now has API documentation, the Web side of WatchOSNativeBindings included.

An app on the last published build removes its WatchCrownScrolling calls and any WatchScrollPhysics arguments. Its layout follows the new safe area on its next build: content that has to start below the clock takes its top from WatchStatusBar.heightOf, or the app keeps the earlier insets by setting FlutterWatchOSSafeArea to platform in watchos/Runner/Info.plist (see doc/layout.md). An app on an older build also checks two things:

  • Web only: extension FlutterWatchosPlatformExt on Platform exists only where dart:io does, so Web code cannot use it. Code that also builds for the Web uses the static FlutterWatchosPlatform getters, which work on every platform.
  • WatchPlatformView: on engines that composite platform views (WatchPlatformView.isComposited), the native view is drawn in paint order with the Flutter content around it, and layer: only decides which side owns the touches inside the view. On engines that do not, layer: also still picks whether the view is drawn above or below Flutter.

What the package gives a Flutter app on Apple Watch:

  • FlutterWatchosPlatform.isWatch, isIos and isAppleMobile tell Apple Watch apart from iPhone and iPad, which both report Platform.isIOS. They are safe to call from shared code on every platform, the Web included, where all three are false.
  • WatchOSInfo: synchronous device information (watchOS version, model, machine id, Simulator flag, screen size and scale).
  • WatchHaptics: Taptic Engine feedback through WKInterfaceDevice.playHaptic.
  • WatchStatusBar: shows or hides the clock watchOS draws over every app, and heightOf gives the height of the band the clock sits in.
  • WatchCrownScroll, WatchScrollPhysics and WatchScrollBehavior: choose the scrollable the Digital Crown drives, keep the crown off a list or hide its scroll indicator, and give finger scrolling the native watchOS feel. The crown itself scrolls natively with no code.
  • WatchCrown: raw Digital Crown rotation, as a stream or per frame with drain(), for games and custom controls.
  • WatchPlatformView: a native SwiftUI view at its place in the Flutter layout, composited in paint order with the Flutter content around it.
  • WatchAlwaysOn and WatchAlwaysOnBuilder: whether watchOS is showing the app dimmed in the Always-On state.
  • WatchMemory: how much memory the process may still allocate before watchOS stops it, and its current footprint.

On other platforms the package calls no native code: the device getters return defaults, and haptics, clock and crown calls do nothing.

4
likes
130
points
492
downloads

Documentation

API reference

Publisher

verified publisherflutterwatch.dev

Weekly Downloads

Platform detection and utilities for Flutter apps running on Apple Watch (watchOS). Provides runtime checks for watchOS, device info, capability queries, and Taptic Engine haptics.

Topics

#watchos #apple-watch #wearable #ffi

License

BSD-3-Clause (license)

Dependencies

ffi, flutter

More

Packages that depend on flutter_watchos

Packages that implement flutter_watchos