How to mock a static getter's return value in Dart or Flutter?
You should not mock classes that you don't own. Your unit test must be platform independent. On your case you should refactor your code to get rid of this dependency.
If you really wanna continue with this dependency at least depends on abstractions:
abstract class MyPlatform { bool isAndroid(); bool isIos(); }class MyPlatformImp implements MyPlatform { @override bool isAndroid() => Platform.isAndroid; @override bool isIos() => Platform.isIOS; }
then you can mock MyPlatform on your uses.
This kind of variable you would test on Integration Testshttps://flutter.dev/docs/cookbook/testing/integration/introduction
You can also create different tests for platforms using the onPlatform attribute of test() https://api.flutter.dev/flutter/test_api/test.html