Handling permission requests in Android for Flutter plugins

While building the Android functionality for a plugin recently I had to handle a system permission request. Although all the parts of that are simple it took me a while to figure out how to put them together. In hopes of making it simpler for others looking to do this here’s all the bits in one place. Note: Code examples are Kotlin, there’s a full gist here. Handling the callback The part that I had to search a bit to pull together was how to handle the Android permission callback in my plugin. The Android documentation for it is here [Read on…]

Error handling in Flutter plugins

I’ve just figured out Flutter error handling for method channels communicating with native code and wanted to capture the technique. This is something that I missed despite a fair amount of reading on plugin integration, so others might have missed it as well. There’s a very good post, Flutter Platform Channels, where I got much of this information, definitely worth a read. There are some details that it doesn’t cover, particularly about testing, and it’s not just focused on error handling, so I thought I’d boost the signal on that. Error structure An error communicated across a method channel is [Read on…]

String internationalization in Flutter

I was recently reviewing the options for app internationalization in Flutter and there was quite a lot of discussion and content written about it. In this post I’ll describe what I think the right choice is and why, as well as provide a few missing _how to_ guides. The short version of the post is that I think you should use the built-in Flutter tools and avoid some of the suggested alternatives. Alternatives Flutter tools Flutter has a set of tools for handling Internationalization, the intl and intl_translation packages. I think the Flutter team has done a very good job [Read on…]

Flutter plugin iOS tests in Swift

Creating plugins for Flutter is well documented and pretty easy. Unit testing the resulting native code in iOS wasn’t quite as straightforward so I thought I’d capture what I did while I still remember the steps. This post shows how to create a new plugin for Flutter with a Swift implementation for iOS, and then add Swift XCTest unit tests for that implementation. Creating a new plugin To create my first plugin I followed the Flutter docs, in particular the section on Developing plugin packages. I used the version of the create command that specified the native languages, like so: [Read on…]