abstract_widget 1.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • 66

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}'),
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 #

Abstract widget example.

Use this package as a library

1. Depend on it

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

  abstract_widget: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages 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';
Version Uploaded Documentation Archive
1.0.0 Jan 5, 2019 Go to the documentation of abstract_widget 1.0.0 Download abstract_widget 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


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
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies