How to: How to get Hostname in Dart| Flutter By Example

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.

How to get Hostname in dart application

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 hostname in dart

import 'dart:io' show Platform, stdout;

void main() {
  final hostname = Platform.localHostname; // returns hostname as string



hostname print in flutter application

dart:html package provides html window class that contains location hostname properties html.window.location.hostname returns the hostname of running machine.

import 'dart:html' as html;

void main() {
  final hostname = html.window.location.hostname;





Learned how to get the hostname of a running application in dart and flutter app

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.

Related posts

How to iterate loop Enum in Dart | Get Enum with index in Flutter By Example

Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

Dart tutorial examples/ Flutter By Examples

How to add Methods or Values to Enums in Dart | Flutter By Example

How to convert Double to Integer or Integer to double in Dart| Flutter By Example

How to: Enum to String in Dart | Print Enum name as String in Flutter By Example

Dart| Flutter How to get File name and extension with example