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

Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

What is the difference between var and dynamic and final in dart?| Flutter By Example

How to: Check if Phone number is valid or not in Dart| Flutter By Example

Dart| Flutter How to read an image from a disk and resize a file

Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

Dart| Flutter How to get extension name and MIME type of a file with example