Running Flutter app on localhost with a real device
To run a Flutter app on a real device connected to your localhost, you need to follow the steps outlined below:
- Ensure that both your computer and the real device are connected to the same network.
- Get the IP address of your computer:
- In your Flutter app code, update the base URL of your API endpoints to use your computer’s IP address instead of “localhost”.
- Run the Flutter app using the following command:
- Make sure to replace “your_computer_ip_address” with the IP address you obtained, and “port” with the appropriate port number (e.g., 8080).
<Windows> ipconfig <Mac/Linux> ifconfig
final baseUrl = 'http://your_computer_ip_address:port';
flutter run --dart-define=FLUTTER_HTTP_BASE_URL=http://your_computer_ip_address:port
Now your Flutter app will be running on your localhost and can be accessed from your real device.
Example
Assuming your computer’s IP address is 192.168.0.10 and you want to use port 8080:
final baseUrl = 'http://192.168.0.10:8080';
Then, to run the Flutter app:
flutter run --dart-define=FLUTTER_HTTP_BASE_URL=http://192.168.0.10:8080
- Flutter fixed bottom container
- Flutter html parser
- Flutter get navigation bar height
- Flutter formkey currentstate null
- Flutter harmonyos
- Flutter failed to delete a directory at “build”. the flutter tool cannot access the file or directory. please ensure that the sdk and/or project is installed in a location that has read/write permissions for the current user.
- Flutter local notifications