setMockMethodCallHandler method

  1. @override
  2. @visibleForTesting
void setMockMethodCallHandler()
override

If your test environment is TargetPlatform.linux, TargetPlatform.windows, Web, then it assumes that you want to override and specify DeviceInfoPlatform.instance, so I'm not considering entering a branch.

The functions used to overwrite DeviceInfoPlatform in each environment are: TargetPlatform.linux ... DeviceInfoLinuxPlatform.registerWith TargetPlatform.windows ... DeviceInfoWindowsPlatform.registerWith Web ... DeviceInfoWebPlatform.registerWith Check the lib/test/device_info_test.dart for usage examples.

Implementation

@override
@visibleForTesting
void setMockMethodCallHandler() {
  // ignore: invalid_use_of_visible_for_testing_member
  testSetMockMethodCallHandler(
    const MethodChannel('dev.fluttercommunity.plus/device_info'),
    (methodCall) async {
      methodCallLogs.add(methodCall);
      switch (methodCall.method) {
        case 'getDeviceInfo':
          switch (defaultTargetPlatform) {
            case TargetPlatform.android:
              return mockAndroidDeviceInfoMap;
            case TargetPlatform.iOS:
              return mockIosDeviceInfoMap;
            case TargetPlatform.macOS:
              return mockMacosDeviceInfoMap;
            default:
              break;
          }
      }
      return null;
    },
  );
}