You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
E/flutter (24445): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: LateInitializationError: Field '_instance@2084288322' has not been initialized.
E/flutter (24445): #0 SodiumPlatform._instance (package:sodium_libs/src/sodium_platform.dart)
E/flutter (24445): #1 SodiumPlatform.instance (package:sodium_libs/src/sodium_platform.dart:21:41)
sodium_libs version: 1.2.0
flutter version: 2.8
used like this:
await Executor().execute(
arg1: str1,
fun1: (String demo) async {
// this is an isolate
final sodium = await CustomSodiumInit.init(); // this line occurs LateInitializationError
final encData = sodium.crypto.secretBox.easy(...);
// ...
},
);
CustomSodiumInit code:
// ......
static Future<sodium.Sodium> init({
@Deprecated('initNative is no longer required and will be ignored.')
bool initNative = true,
}) =>
_instanceLock.synchronized(() async {
if (_instance != null) {
return _instance!;
}
// Comment out this line or an exception(Unhandled Exception: UI actions are only available on root isolate) will occur
// WidgetsFlutterBinding.ensureInitialized();
_instance = await SodiumPlatform.instance.loadSodium();
if (!kReleaseMode) {
if (_instance!.version < _expectedVersion) {
// ignore: avoid_print
print(
'WARNING: The embedded libsodium is outdated! '
'Expected $_expectedVersion, but was ${_instance!.version}}. '
'${SodiumPlatform.instance.updateHint}',
);
}
}
return _instance!;
});
sodium_libs version 1.1.1 will work, but 1.2.0 not
The text was updated successfully, but these errors were encountered:
SodiumPlatform.instance is initialized automatically by flutter when the plugin is loaded. This happens as part of the WidgetsBinding.ensureInitialized() in normal code. This is not automatically executed when launching a new isolate, thus it does not get initialized. It did work with older versions, as back then flutter did not support loading dart plugins automatically.
This is not a bug, but expected behaviour. You have to do one of the following things to use the plugin in a different isolate:
Simply call WidgetsBinding.ensureInitialized() in your Isolate
Use a plugin like flutter_isolate that takes care of that for you.
E/flutter (24445): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: LateInitializationError: Field '_instance@2084288322' has not been initialized.
E/flutter (24445): #0 SodiumPlatform._instance (package:sodium_libs/src/sodium_platform.dart)
E/flutter (24445): #1 SodiumPlatform.instance (package:sodium_libs/src/sodium_platform.dart:21:41)
sodium_libs version: 1.2.0
flutter version: 2.8
used like this:
CustomSodiumInit code:
sodium_libs version 1.1.1 will work, but 1.2.0 not
The text was updated successfully, but these errors were encountered: