ufukhawk / safe_device

MIT License
47 stars 45 forks source link

Null check operator used on a null value #11

Closed boeledi closed 2 years ago

boeledi commented 2 years ago

Hi,

I am trying to use your implementation, using the following code

bool isJailBroken = false;
  bool canMockLocation = false;
  bool isRealDevice = true;
  bool isOnExternalStorage = false;
  bool isSafeDevice = false;

  try {
    isJailBroken = await SafeDevice.isJailBroken;
    canMockLocation = await SafeDevice.canMockLocation;
    isRealDevice = await SafeDevice.isRealDevice;
    isOnExternalStorage = await SafeDevice.isOnExternalStorage;
    isSafeDevice = await SafeDevice.isSafeDevice;
    final bool securityBreach = (isJailBroken || canMockLocation || !isRealDevice || isOnExternalStorage || !isSafeDevice);
    log('Security:  isJailBroken: $isJailBroken  isRealDevice: $isRealDevice isOnExternalStorage: $isOnExternalStorage canMockLocation: $canMockLocation isSafeDevice: $isSafeDevice');

    if (securityBreach && !isSimulator) {
      return;
    }
  } catch (e) {
    log('[security validation] :: $e');
  }

but systematically obtain the following exception:

Null check operator used on a null value

Would you have any solution?

Many thanks

boeledi commented 2 years ago

The solution to the problem is to Ensure that the Flutter bindings are initialized before calling the plugin. So, put the following before accessing the plugin

WidgetsFlutterBinding.ensureInitialized();