Flutter: can I find out what platform I am on?


I am developping a project that should work both as an app and a web page. I am using flutter_secure_storage to store local data for the app, but I need a different approach for web.
Is there a way I can find out what platform I am on at runtime, and choose the correct read-write functions accordingly?


you can add this extension file to the project and call in any object


import 'dart:io';
import 'package:flutter/foundation.dart' show kIsWeb;

extension Target on Object {
  bool isAndroid() {
    return Platform.isAndroid;
  bool isIOS() {
    return Platform.isIOS;
  bool isLinux() {
  return Platform.isLinux;
  bool isWindows() {
  return Platform.isWindows; 
  bool isMacOS() {
  return Platform.isMacOS; 
  bool isWeb() {
  return kIsWeb; 
  // ยทยทยท

and import it anywhere and use it like this

  Widget build(BuildContext context) {
    return isAndroid()? Text("Android"):Text("Not Android");

Answered By – Omar Mahmoud

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *