flutter-watch kit
the watch tips project has been updated again, the interface has been tidied up and a seperate value for the tip cost has been added and displayed ( a requested update). i have also added a custom ‘keypad’ rather than using the standard one available for the platform, hopefully the app now looks a bit better than it did – ux/ui design is not my strong point.
but the biggest update is that there is now also an android version (without watch support). doing this has helped a lot as i can use the flutter android app for development purposes so that i now have hot reload back (development is good again ….)
for ios, i still need to run/build (and fail) with the flutter tools for ios (this is required to generate the correct build scripts) and finish with xcode, but general dev is know easier.
this was an originally experiment to see if can use flutter to build an ios app with an accompanying watchos app. my first attempts using the beta product were not successful so the idea was parked. having now re-visited this i can now get a compiled blank watch app up and running with a flutter app, so i will, in stages, try and re-create the watchtips app using flutter.
app store link
ths app is a really simple app and originally just created as a proof point.
but for anyone interested here are the release links:
plan
- 1.0 create a vanilla flutter app (this initial commit)
- 1.1 add a blank watch project and get it working
- 1.2 modify the watch app functionally into watchtips
- 1.3 update the flutter app to watchtips
- 1.4 see if i can bridge between the 2 app (as the titanium version does)
- 2.0 tidy up both the flutter code and the ios project and use it to submit the app into the app store
- 2.x+ – updates and improvements
flutter package project
from the results of this test project, i have started developing a flutter package to allow communication between a flutter ios app and a watch app. this should allow easier integration with some standard functionality, though it is still a pain atm as after you add a watch kit target to the ios project as flutter run/build no longer works. this means all package testing and development then needs to be done via xcode.
i have got messaging working from an ios app to the watch via the plugin, this can be seen working in avideo here.
generating a distro build
the only way, so far, i have found of creating a distro build is following this seqence.
set the bundle id
before adding the watch kit app target set the final bundle id, as the watch app and associated extension needs to use the same prefix. if not you may need to update all references before creating the final archive.
change all the version and build values
this must be done for each target (in this case 3), change them to $(flutter_build_name) and $(flutter_build_number) respectively, otherwise although the test runs work, the archive will not unless the version numbers match.
run the flutter build first
this will fail, but it generates the correct shell scripts to enable ios to carry out the build (flutter build ios –release).
create archive in xcode
- 1 select generic device + watchos device as the destination
- 2 run product -> archive
- 3 if build successful , run the validate app
- 4 if validate successful – upload to app store!!!
versions
2.1
- updated watch and phone ui
- currency now defaults to the phone/ipad locale
- package made universal, so it runs on ipad (no watch supoort)
2.0
- first app store release
1.4 – rough and ready but working!
i have now managed to add the required code into the ios project to allow it to communicate with flutter and send data updates from the watch so they are reflected in the app.
basically if you do a calculation for a tip on the watch then the data is transferred to the associated device.
you need to forgive the (bad?) objective c coding as it is not really my thing – who in their right mind thought of it in the first place anyway 🙂 . a lot of this was just brute force trial and error as well as a lot of searching and testing.
apart from that the difficult issue for me was that although methodchannel is quite well documented, eventchannel is not, the only examples i found were to do with plugin extensions, but again probably due to my dislike (due to not understanding it very well) of objective c.
i will try to create a generic plug-in later, but that will be done in swift.
1.3
so after a bit of a hair pulling out session i have managed to get this working. i now have a iwatch app as well as a flutter ios app to build and run. i have tested this by building and distribuing to a physical phone via hockeyapp. now the bad news……
i cannot use flutter to either build the flutter project or do the ios release build, so i actually built the flutter app in a seperate project then added the lib dir back into this one.
this is a major pain as to do an testing, on device or simulator i need to use xcode to do all the build (i.e. no hot-reloading), but it does work.
to create the ad-hoc distro of the app i again used xcode, set the target to generic device and archived the project. the resulting ad-oc signed app works well.
but i think the last stage will be a major hurdle as i will need to do all building using xcode………
1.2
updated watch app and added functioning watchtips. watch app can now be used to calculate bill split and tips.
1.1
after using xcode to define a simulator with an attached watch emulator the standard vanilla app (from 1.0) was updated as follows
- set a bundle id on the ios runner app (u.spiralarm.watchtips)
- add a new target in xcode (file->new->target), a watchkit app was selected
- untick include notification scene and include complication
- name the product watchtips
- generate 2 sets of assets (i use an app called asset catalog creator), one for the runner app and one for the watch app so that both have a full set of icons.
- open the interface.storyboard for rhe watchtips app and add a button to the screen
after this i can no longer user the ide (vsc) to start the app up in debug mode as i get the following error ( perhaps some sort of cusom build configuration is required):
=== build target watchtips extension of project runner with configuration debug ===
target specifies product type 'com.apple.product-type.watchkit2-extension', but there's no such product type for the 'iphonesimulator' platform
could not build the application for the simulator.
error launching application on iphone 7 with watch 42mm.
however, if i use xcode i can use xcode to compile the app and run the watch app on the emulator.
Comments are closed.