flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.46k stars 27.12k forks source link

[Proposal] allow rootBundle access from spawned isolates #96895

Open variablevariance opened 2 years ago

variablevariance commented 2 years ago

Currently as of flutter 2.8.1, isolates cannot use rootBundle. I faced this issue and had to make a workaround for it but it introduces unnecessary code and looks ugly.

Example:

Future<void> function() async{
    String data= await rootBundle.loadString(filepath);
    compute(f,data)
}
void f(String data){
    print(data);
}

should be

Future<void> function() async{
    String data= await rootBundle.loadString(filepath);
print(data);
}

//just call function like compute(function,args); I hope my example shows why rootBundle should be allowed in isolates.

maheshj01 commented 2 years ago

HI @variablevariance, Thanks for filing the issue. RootBundle are not accessible in spawned isolates please see this line comments from the source code. https://github.com/flutter/flutter/blob/657830b4c77aecfd0e32ec6504c859213dded97a/examples/layers/services/isolate.dart#L132-L138

variablevariance commented 2 years ago

what I mean is that rootbundle should be accessible from spawned isolate in flutter.

maheshj01 commented 2 years ago

This is done in the main isolate because spawned // isolates do not have access to the root bundle

I think this answers it that this is currently not possible. However I will leave this issue open for further insights from the team.

maheshj01 commented 2 years ago

cc: @chinmaygarde

chinmaygarde commented 2 years ago

This is blocked on https://github.com/flutter/flutter/issues/13937

mdejeans commented 1 year ago

As #13937 is resolved, should be now able to access rootBundle from spawned isolates ?

CaptainDario commented 3 months ago

@chinmaygarde is this now possible? Because as mentioned the blocking issue has been resolved.