Handling permission requests in Android for Flutter plugins

Updated for the new plugin registration process in Flutter 1.12. 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. The gist is for pre 1.12, I’ll try to get a post 1.12 gist up in the next little while but until then [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…]

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…]