I would like to introduce full platform adaptiveness to my app. Currently I use Material
for both iOS and Android version. I would like to show appropriate version of Widget depending on detected platform but I don't want to do this as shown on following code sample, because I have to do it multiple times for existing app.
Solution #1
return Theme.of(context).targetPlatform = TargetPlatform.iOS
? CupertinoTextField(
...)
: TextField(
...)
Solution #2
Fortunately, there are widgets like with adaptive
named constructor like Switch.adaptive
and works perfectly for me. Unfortunately you can count them on the fingers of one hand.
Solution #3
Use 3rd party library and. For example I can use PlatformButton
where possible and don't care what happens under the hood.
Solution #4 Write custom platform specific wrapper for each widget according to this tutorial.
Question #1
Which solution is the best considering time and testability? I'm big fan of Flutter's widget with .adaptive
named constructor but I can't wait until Flutter Dev team provide more similar widgets
Question #2 How to handle tests for iOS specific widgets using Firebase Test Lab? Should I write unit test to check if proper iOS version of widget is rendered? I see there is no other way.