I’m writing a flutter app that needs to set up elasticsearch on first run. To do this, I need to run some commands in the terminal, I know how to do it, but I also need information from the terminal for a complete setup. How to get information from terminal to my flutter app, can i assign the value of one of the terminal strings to some variable in flutter?
I not found a some issues about getting info from terminal to app.
You can use
--dart-define from the terminal while running your app or while building your application.
flutter run --dart-define=BASE_URL=https://flutter.dev
BASE_URL is a key and you can pass value to it, you can name it as per your need.
And, You can access this in your
Flutter app like below:
You can check out this video as well for the same: Passing values from the command line to Flutter app
constis required while accessing that value you pass using
dart-defineand the key name is case sensitive.
Answered By – ibhavikmakwana
Answer Checked By – Marilyn (FlutterFixes Volunteer)