MDeviceValue class

Reads a device metric in the widget process, so it is correct even when the app has not run for days.

It behaves exactly like an MBind — usable anywhere a bound value is accepted, including MProgressBar.value and MVisibility.bind:

MText(MDeviceValue(MDeviceMetric.batteryLevel))
MProgressBar(value: MDeviceValue(MDeviceMetric.batteryLevel), max: 100)
MVisibility(
  bind: MDeviceValue(MDeviceMetric.batteryCharging),
  child: const MIcon(sfSymbol: 'bolt.fill', androidDrawable: 'ic_lightning'),
)

An app-supplied battery level goes stale the moment the app is backgrounded; this does not. Only the metrics a widget actually references are collected.

Inheritance

Constructors

MDeviceValue(MDeviceMetric metric, {String? defaultValue})
defaultValue is forwarded, not inherited: Dart constructors do not pass named parameters up on their own, so without this a metric could never declare what to show before the first native read lands — which on iOS is every gallery preview, since the extension has not run yet.

Properties

defaultValue String?
Rendered when key has never been written.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
key String
finalinherited
metric MDeviceMetric
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited