-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass arguments into my application's main() #170
Comments
Yes you can, but it is a little tricky:
import 'dart:ffi';
import 'dart:io';
bool _isFutterPi = Platform.resolvedExecutable.endsWith('flutter-pi');
bool isFutterPiEnv() {
return _isFutterPi;
}
var _flutterPiArgs = <String>[];
List<String> getFlutterPiArgs() {
if (!isFutterPiEnv()) {
return const <String>[];
}
if (_flutterPiArgs.isEmpty) {
final dylib = DynamicLibrary.open('libc.so.6');
var getpid =
dylib.lookup<NativeFunction<_getpId>>('getpid').asFunction<_GetpId>();
var cmd = File('/proc/${getpid()}/cmdline').readAsBytesSync();
var index = 0;
for (var i = 0; i < cmd.length; ++i) {
if (cmd[i] == 0) {
_flutterPiArgs
.add(String.fromCharCodes(Uint8List.sublistView(cmd, index, i)));
index = i + 1;
}
}
}
return List.unmodifiable(_flutterPiArgs);
} Should return following list
|
Yeah the engine options are passed to the engine as-is, those are not the cmdline arguments for the |
Seems like flutter supports passing arguments to the app's |
Great, I will follow that. I am still on 1.x, but hope to migrate to 2.x engine binaries next month. |
Is there a way to get arguments into my main(), similar to below ?
void main(List<String> arguments) async { print('args: $arguments'); // ... do my stuff ... }
I tried adding a "custom" command line option in the [flutter engine options] portion of the flutter-pi command line, but arguments was still an empty List.
The text was updated successfully, but these errors were encountered: