Detect device operating system

Fidélitas University 🔵 🟡

Costa Rica 🇨🇷

Professor: Ariel Ramos Ortega

Do you want to know on which operating system your application is running? 📱

  • Step 1: Create a Custom Action: detectOS

  • Step 2: Return a string value

  • Step 3: Copy and paste the following code into your Custom Action

    Copy

    // Automatic FlutterFlow imports
    import '/flutter_flow/flutter_flow_theme.dart';
    import '/flutter_flow/flutter_flow_util.dart';
    import '/custom_code/actions/index.dart'; // Imports other custom actions
    import '/flutter_flow/custom_functions.dart'; // Imports custom functions
    import 'package:flutter/material.dart';
    // Begin custom action code
    // DO NOT REMOVE OR MODIFY THE CODE ABOVE!
    
    import 'dart:io' show Platform;
    import 'package:flutter/foundation.dart' show kIsWeb;
    
    Future<String> detectOS() async {
      var platformName = '';
      if (kIsWeb) {
        platformName = "Web";
      } else {
        if (Platform.isAndroid) {
          platformName = "Android";
        } else if (Platform.isIOS) {
          platformName = "IOS";
        } else if (Platform.isMacOS) {
          platformName = "MacOS";
        } else if (Platform.isWindows) {
          platformName = "Windows";
        } else {
          platformName = "Dispositivo desconocido";
        }
      }
      return ("El sistema operativo de este dispositivo es: " +
          platformName.toString());
    }

That's all!

You can implement it on a page with text and a button

7
2 replies