Home > front end >  Is it possible to get information from a terminal into a flutter app? If yes, please share an exampl
Is it possible to get information from a terminal into a flutter app? If yes, please share an exampl

Time:03-26

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.

CodePudding user response:

You can use --dart-define from the terminal while running your app or while building your application.

for example

flutter run --dart-define=BASE_URL=https://flutter.dev

Here 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:

const String.fromEnvironment('BASE_URL')

You can check out this video as well for the same: Passing values from the command line to Flutter app

const is required while accessing that value you pass using dart-define and the key name is case sensitive.

  • Related