Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if my Flutter app is running in the web?

Tags:

flutter

dart

I know that I can detect the operating system with Platform.isAndroid, Platform.isIOS, etc. but there isn't something like Platform.isWeb so how can I detect this?

like image 297
n1ks Avatar asked Sep 14 '19 16:09

n1ks


People also ask

Does Flutter run on web?

Flutter's web support delivers the same experiences on the web as on mobile. Building on the portability of Dart, the power of the web platform and the flexibility of the Flutter framework, you can now build apps for iOS, Android, and the browser from the same codebase.


2 Answers

There is a global boolean kIsWeb which can tell you whether or not the app was compiled to run on the web.

Documentation: https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html

import 'package:flutter/foundation.dart' show kIsWeb;  if (kIsWeb) {   // running on the web! } else {   // NOT running on the web! You can check for additional platforms here. } 
like image 164
Westy92 Avatar answered Sep 21 '22 12:09

Westy92


There is a code written Below to get OS/web where flutter is running...

if(kIsWeb)    return Text("It's web");  else if(Platform.isAndroid){      return Text("it's Android"); } 
like image 26
Deven Avatar answered Sep 21 '22 12:09

Deven