Flutter platformの判定

Platform.operatingSystemはエミュレータでは期待通りになるけど、 widget testなどでは、当たり前だけど、テストを実行しているパソコンのOS(windowsとかmac)になる。

Platform.isIOS,Platform.isAndroidなども同様。 さらにテスト時だけ変更したいなんてこともできないらしい。

それとは反対に、defaultTargetPlatformはdebugDefaultTargetPlatformOverrideに値を代入することで変更できます。

みたいなことがこのあたりに書いてあります。

defaultTargetPlatform property - foundation library - Dart API

それとdebugDefaultTargetPlatformOverrideを使用する際の注意事項が下記に載っています。

debugDefaultTargetPlatformOverride property - foundation library - Dart API

For example, setting this to TargetPlatform.iOS when the application is running on Android will cause the TalkBack accessibility tool on Android to be confused because it would be receiving data intended for iOS VoiceOver. Similarly, setting it to TargetPlatform.android while on iOS will cause certainly widgets to work assuming the presence of a system-wide back button, which will make those widgets unusable since iOS has no such button.