THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
Sometimes, We need to get the hostname of a running application in the current environment in the dart and flutter application
This post shows multiple ways to get a hostname in the dart and flutter project.
dart:io
package provides platform class that provides information of an running environment.
Platform class has a static method localHostname
that returns the hostname of a system.
static String get localHostname => _localHostname;
Here is an example program to get a hostname in dart
import 'dart:io' show Platform, stdout;
void main() {
final hostname = Platform.localHostname; // returns hostname as string
print(hostname);
}
Output
localhost
dart:html
package provides html window class that contains location hostname properties
html.window.location.hostname
returns the hostname of the running machine.
import 'dart:html' as html;
void main() {
final hostname = html.window.location.hostname;
print(hostname);
}
Output:
localhost
Learned how to get the hostname of a running application in the dart and flutter app
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts