flutter_watchos 0.1.0
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
NestedScrollViewscrolls 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. WatchCrownScrollnow chooses that scrollable, for a screen with more than one, and still gives its subtreeWatchScrollPhysics.enabled: falsekeeps the crown off the scrollables under it, andscrollIndicator: falsehides the crown scroll indicator.WatchScrollPhysicsfollows 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. ThemaxStretchFractionandedgeRelaxationparameters are removed.WatchCrownScrollingandWatchCrownSensitivityare 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.WatchCrownis 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.WatchOSNativeBindingsgainsclockBandHeight. - Fixed: setting
WatchStatusBar.hiddento a new value now asks for a frame, so the clock hides or shows even on a screen that does not repaint.WatchStatusBargains three test seams marked@visibleForTesting:bindingsOverride,isWatchOverrideandscheduleFrameOverride. - 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 itsSafeArea.
The API docs changed too:
- Docs: every public member now has API documentation, the Web side of
WatchOSNativeBindingsincluded.
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 Platformexists only wheredart:iodoes, so Web code cannot use it. Code that also builds for the Web uses the staticFlutterWatchosPlatformgetters, 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, andlayer: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,isIosandisAppleMobiletell Apple Watch apart from iPhone and iPad, which both reportPlatform.isIOS. They are safe to call from shared code on every platform, the Web included, where all three arefalse.WatchOSInfo: synchronous device information (watchOS version, model, machine id, Simulator flag, screen size and scale).WatchHaptics: Taptic Engine feedback throughWKInterfaceDevice.playHaptic.WatchStatusBar: shows or hides the clock watchOS draws over every app, andheightOfgives the height of the band the clock sits in.WatchCrownScroll,WatchScrollPhysicsandWatchScrollBehavior: 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 withdrain(), 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.WatchAlwaysOnandWatchAlwaysOnBuilder: 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.