yoeden / wearthat

Apache License 2.0
9 stars 1 forks source link

Tiles dont show up on watch #1

Closed brokoli18 closed 5 months ago

brokoli18 commented 5 months ago

Hi, I tried to build a quick demo app using your library and I am struggling using the tiles. I followed your docs and to confirm this is what my code looks like:

# main.dart
import 'package:flutter/material.dart';
import 'package:wear_plus/wear_plus.dart';
import 'package:yak/tile.dart';
import 'package:wearthat/tiles.dart' as wear_tiles;

@pragma('vm:entry-point')
void maintile() {
  wear_tiles.runTiles(
    [
      wear_tiles.TileService(
        name: "WeatherTile",
        routes: {
          '/': () => WeatherTile(),
          // If needed more routes
          // '/secondary': () => SecondaryWeatherTile(),
        },
      ),
    ],
  );
}

void main() {
  runApp(const MyApp());
}
...
#tile.dart
import 'package:wearthat/tiles.dart';
import 'package:weather/weather.dart';

Future<Weather> getWeather() async {
  WeatherFactory wf = WeatherFactory('<KEY>');
  Weather w = await wf.currentWeatherByLocation(55, 15);
  return w;
}

class WeatherTile extends Tile<Weather> {
  @override
  Future<Weather> createState() {
    return getWeather();
  }

  @override
  TileWidget build(TileContext context, Weather? state) {
    return Column(
      children: [
        SizedBox(
          width: 32,
          height: 32,
          child: Image("loading_weather"),
        ),
        Text("I will show my weather here, if i want to...DONT PRESSURE ME !"),
      ],
    );
  }

  @override
  Map<String, TileResourceProvider> resources(
          TileContext context, Weather? state) =>
      {
        'loading_weather': TileResources.asset("assets/img.png"),
      };
}
pubspec.yaml
...
tiles:
  WeatherTile:
    label: Quick Weather
    preview: assets/img.png

I also ran the dart command to update the tile.

❯ dart run wearthat:synctiles
Building package executable... 
Built wearthat:synctiles.

Clearing tiles...
  Removing tiles from manifest
  Removing tiles classes
  Removing tile previews

Adding tiles...
  Loading tiles from pubspec.yaml
  Added WeatherTile

Done in 0:00:00.000050.

When I run on the emulator however I cannot see the tile. My app starts but there is no custom tile there, only the default ones. Am I doing something wrong?

brokoli18 commented 5 months ago

Quite embarrassingly it seems that I was just forgetting to actually add the widget on the watch after creating it :facepalm: This can be closed

yoeden commented 5 months ago

Will open an issue to add the "Add widget on the watch" step. Glad you figured it out 👍