i'm building an explorer using flutter getting apps length will take a while so i tried to get the value using annother Isolate, that's part of my main.dart code
Future<int> getValueFromIsolate() async {
return await compute(
apps,
0,
);
}
Future<int> apps(int n) async {
int value = 0;
List apps = await DeviceApps.getInstalledApplications(
includeAppIcons: true,
includeSystemApps: true,
onlyAppsWithLaunchIntent: true,
);
print(apps.length);
value = apps.length;
print(value);
return value;
}
And so there is my main function
void main() {
WidgetsFlutterBinding.ensureInitialized();
getValueFromIsolate().then(
(value) {
print("Then the value is $value");
},
);
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => AppProvider(),
),
ChangeNotifierProvider(
create: (_) => CategoryProvider(),
),
ChangeNotifierProvider(
create: (_) => CoreProvider(),
),
],
child: MyApp(),
),
);
}
But i still got this error
I/flutter ( 6234): ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized. I/flutter ( 6234): If you're running an application and need to access the binary messenger before
runApp()
has been called (for example, during plugin initialization), then you need to explicitly call theWidgetsFlutterBinding.ensureInitialized()
first. I/flutter ( 6234): If you're running a test, you can call theTestWidgetsFlutterBinding.ensureInitialized()
as the first line in your test'smain()
method to initialize the binding.
I don't understand what it's happening and i don't know what to do..!! Please need your help Thanks for reading and your help