cross_platform 3.0.1 copy "cross_platform: ^3.0.1" to clipboard
cross_platform: ^3.0.1 copied to clipboard

Cross platform package that unifies the work with Platform and wrapps dart:io Platform and dart:html to determine platform of the host machine an info about it.

example/lib/main.dart

// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

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

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Widget _buildContent() {
    if (Platform.isWeb) {
      return Center(child: Text('Current platform is Web'));
    } else if (Platform.isAndroid) {
      return Center(child: Text('Current platform is Android'));
    } else if (Platform.isIOS) {
      return Center(child: Text('Current platform is iOS'));
    } else if (Platform.isMacOS) {
      return Center(child: Text('Current platform is MacOS'));
    } else if (Platform.isLinux) {
      return Center(child: Text('Current platform is Linux'));
    } else if (Platform.isWindows) {
      return Center(child: Text('Current platform is Windows'));
    } else if (Platform.isFuchsia) {
      return Center(child: Text('Current platform is Fuchsia'));
    } else {
      return Center(child: Text('Current platform is undefined'));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _buildContent(),
    );
  }
}
8
likes
160
points
608
downloads

Publisher

verified publisherthisismarch.dev

Weekly Downloads

Cross platform package that unifies the work with Platform and wrapps dart:io Platform and dart:html to determine platform of the host machine an info about it.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on cross_platform