abstract_widget 1.0.0

AbstractWidget #

pub package

Generic widget that builds itself depending on the derived class of current value.

AbstractWidget example

Usage #

  1. Define classes hierarchy:
abstract class Animal {
  static Animal get random => Random().nextBool() ? Doge() : Cate();
}

class Doge extends Animal {
  final int badDeeds = 0;
  final int goodDeeds = Random().nextInt(20);
}


class Cate extends Animal {
  static final _breeds = ['Oriental', 'Birman', 'Tonkinese'];

  final String breed = _breeds[Random().nextInt(_breeds.length)];
  final bool friendly = Random().nextBool();
}

  1. Create widget and pass it necessary builder functions:
// ...
  child: AbstractWidget<Animal>(Animal.random)
    ..when<Doge>((doge) => Text('wow. such widget.'))
    // It's also correct to omit type parameters as they will 
    // be inferred depending on argument type of the builder.
    ..when((Doge doge) => Center(
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            Text('Bad deeds: ${doge.badDeeds}'),
            Text('Good deeds: ${doge.goodDeeds}'),
          ]),
        ))
    ..when<Cate>(_buildCate),
  
  
Widget _buildCate(Cate cate) {
  // build cate widget here
}

Note #

Be cautious when passing builder functions without explicitly specifying generic type argument (like ..when((Doge doge) => ...) in the example above). In case of an incompatible type, Dart analyzer won't mark it as error, which will result in runtime exception.

[0.0.1] - 03/01/19.

  • Implement core functionality

example/README.md

example #

Abstract widget example.

Use this package as a library

1. Depend on it

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


dependencies:
  abstract_widget: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:abstract_widget/abstract_widget.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
31
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
21
Learn more about scoring.

We analyzed this package on Sep 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms:

Error(s) prevent platform classification:

Error(s) in lib/wrapper.dart: 'R' can't be used contravariantly or invariantly in 'Wrapper<T, R, Widget Function(R)>'.

Health issues and suggestions

Fix lib/wrapper.dart. (-43.75 points)

Analysis of lib/wrapper.dart failed with 2 errors:

line 16 col 25: 'R' can't be used contravariantly or invariantly in 'Wrapper<T, R, Widget Function(R)>'.

line 23 col 32: 'R' can't be used contravariantly or invariantly in 'Wrapper<T, R, Widget Function(BuildContext, R)>'.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/wrapper.dart: 'R' can't be used contravariantly or invariantly in 'Wrapper<T, R, Widget Function(R)>'.

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

At the time of the analysis the homepage field https://github.com/tomwyr/abstract-widget/ was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test