Flutter wear is a library for flutter aspiring to be a one-stop shop for all related features for android wear (We're not there yet, but will slowly get there π).
This library is still in very very early development, and breaking changes may be introduced every version !
package:flutter/material.dart
)androidx.wear.protolayout.expression.PlatformHealthSources
for tiles, research more for in app service)With Dart:
$ dart pub add flutter_wear
With Flutter:
$ flutter pub add flutter_wear
Manually:
dependencies:
benchmark: ^0.3.0
Don't forget to set android compileSdkVersion to 34 and minSdkVersion to 28 in the build.gradle !
android {
compileSdkVersion 34
...
defaultConfig {
minSdkVersion 28
}
}
Get all available nodes :
final nodes = Wear.getNodes();
Send message to device :
// Path is like route, to know where to direct to message
Wear.send(WearMessage.string("PATH", data), nodeId: watch.id /* or phone */);
Send message to all devices (Fit for cases where only one device is connected) :
Wear.send(WearMessage.string("PATH", data));
Listen for incoming messages :
Wear.listen("PATH", _onIncomingMessage);
// Dont forget to removeListener !
Wear.removeListener("PATH", _onIncomingMessage);
Tiles can finally be made using Flutter π !
The following code :
class WeatherTile extends Tile<WeatherInfo> {
const WeatherTile();
@override
Future<WeatherInfo?> createState() {
return FakeWeatherProvider().getWeather();
}
@override
TileWidget build(TileContext context, WeatherInfo? state) {
if (state == null) return const Text("Something went wrong...");
return PrimaryLayout(
body: _Forecast(temperature: state.temperature),
title: _Location(location: state.location),
chip: _Humidity(humidity: state.humidity),
);
}
@override
Map<String, TileResourceProvider> resources(TileContext context, WeatherInfo? state) => {
'forecast_cloudy_day': TileResources.asset("assets/weather/forecast_cloudy_day.png"),
'forecast_humidity': TileResources.asset("assets/weather/forecast_humidity.png"),
'location': TileResources.asset("assets/weather/location.png"),
};
}