flutter_cross_platform 0.1.3+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

Cross Platform #

The Cross Platform provides mixins to simple decide which widget should be built. For example, we need some widget looks in one way on devices and other way on web. Or we need to include/exclude (svg, hover, ...) some widgets on web platform.

Usage #

PlatformSplitMixin

Allows to split widget into 'device' and 'web' variants

class PlatformSplitted 
  extends StatelessWidget 
  with PlatformSplitMixin {

  @override
  Widget build(BuildContext context) {
    // You can pass any data to each variant builder

    // will return green container with platform specific text
    return platformVariant(context, data: Colors.green);
  }

  @override
  Widget device(context, {data}) {
    return Container(
      color: data as Color,
      child: Center(
        child: Text("I'm device variant")
      ),
    );
  }

  @override
  Widget web(context, {data}) {
    final color = data as Color;
    return Container(
      color: color,
      child: Center(
        child: Text("I'm web variant")
      ),
    );
  }
}

PlatformSplitSingletonMixin

Similar to previous mixin but initialize variants only once. Useful, for example, to override navigation.

class MyApplication
  extends StatelessWidget
  with PlatformSplitSingletonMixin {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "MyApplication",
      builder: (context, child) {

        // Initialise singletons outside widgets
        // So they will not rebuild
        initPlatforms(context);
        return platformVariant;
      },
    );
  }

  @override
  Navigator web(context) {
    return Navigator();
  }

  @override
  Navigator device(context) {
    return Navigator();
  }
}

[0.1.3] - 19 April 2020 #

  • Rename platform mixins to PlatformSplitMixin and PlatformSplitSingletonMixin
  • Make mixins available to work with any widget
  • Add README

[0.1.1] - 17 April 2020 #

  • Separate navigators by screen type and platform

[0.1.0] - 08.04.2020 #

  • Initial mixin add

example/example.dart

// Allows to split widget into 'device' and 'web' variants
class PlatformSplitted
  extends StatelessWidget
  with PlatformSplitMixin {

  @override
  Widget build(BuildContext context) {
    // You can pass any data to each variant builder

    // will return green container with platform specific text
    return platformVariant(context, data: Colors.green);
  }

  @override
  Widget device(context, {data}) {
    return Container(
      color: data as Color,
      child: Center(
        child: Text("I'm device variant")
      ),
    );
  }

  @override
  Widget web(context, {data}) {
    final color = data as Color;
    return Container(
      color: color,
      child: Center(
        child: Text("I'm web variant")
      ),
    );
  }
}


// Similar to previous mixin but initialize variants only once. Useful, for example, to override navigation.
class MyApplication
  extends StatelessWidget
  with PlatformSplitSingletonMixin {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "MyApplication",
      builder: (context, child) {

        // Initialise singletons outside widgets
        // So they will not rebuild
        initPlatforms(context);
        return platformVariant;
      },
    );
  }

  @override
  Navigator web(context) {
    return Navigator();
  }

  @override
  Navigator device(context) {
    return Navigator();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_cross_platform: ^0.1.3+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_cross_platform/flutter_cross_platform.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [flutter_cross_platform] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

19 out of 19 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://gitlab.com/nogipx/flutter_cross_platform was unreachable.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (responsive_builder).

Repository URL doesn't exist. (-10 points)

At the time of the analysis the repository field https://gitlab.com/nogipx/flutter_cross_platform was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
responsive_builder ^0.1.5 0.1.9 0.2.0+2
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8