PlatformX A multi-platform lightweight tool which helps you check the platform your app is running on.

Gallery

 | |

Usage

There are 2 ways to use it.

First way :

PlatformX.platform

This will return one of the values of the PlatformEnum enum.

enum PlatformEnum {
  Android,
  IOS,
  Web,
  Windows,
  Linux,
  MacOS,
  Fuchsia,
}

Second way :

PlatformX.is[Android/IOS/Web/Windows/Linux/MacOS/Fuchsia]

Example:

PlatformX.isLinux

This will return true if you are running on that specific platform, or false otherwise.

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add platformx

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  platformx: ^1.1.0

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:platformx/platformx.dart';

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:platformx/platformx.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Checking platform',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'And the platform is...',
            ),
            Text(
              PlatformX.platform.toString(),
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
    );
  }
}

#flutter #dart #mobile-apps 

 

Lightweight Platform Checking Utility for Flutter
1.70 GEEK