PlatformX A multi-platform lightweight tool which helps you check the platform your app is running on.
|
|
There are 2 ways to use it.
PlatformX.platform
This will return one of the values of the PlatformEnum enum.
enum PlatformEnum {
Android,
IOS,
Web,
Windows,
Linux,
MacOS,
Fuchsia,
}
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.
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.
Now in your Dart code, you can use:
import 'package:platformx/platformx.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,
),
],
),
),
);
}
}