conditional_wrapper 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

conditional_wrapper #

A widget that allows you to conditionally wrap a child with a widget

Example

[1.0.0] - 3/15/2020 #

  • Initial Release

[1.0.1] - 3/16/2020 #

  • Add ifFalse option to allow for another wrapping option if the condition is false

example/lib/main.dart

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

void main() {
  runApp(ConditionalWrapperHome());
}

class ConditionalWrapperHome extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Conditional Wrapper Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

final containerKey = GlobalKey(debugLabel: 'container');
final containerKey2 = GlobalKey(debugLabel: 'container2');

class _MyHomePageState extends State<MyHomePage> {
  bool shouldWrap1 = false;
  bool showFirstOption = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Conditional Wrapper Example'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text("Don't Wrap"),
                  Switch.adaptive(
                      value: shouldWrap1,
                      onChanged: (value) {
                        setState(() {
                          shouldWrap1 = value;
                        });
                      }),
                  Text('Wrap'),
                ],
              ),
              ConditionalWrapper(
                condition: shouldWrap1,
                child: Text(shouldWrap1 ? 'Wrapped' : 'Unwrapped'),
                builder: (BuildContext context, Widget child) {
                  return Column(
                    children: <Widget>[
                      Container(
                        key: containerKey,
                        padding: EdgeInsets.all(20),
                        child: child,
                        color: Colors.blue,
                      ),
                      Text('Some other child inside a Column'),
                    ],
                  );
                },
              ),
            ],
          ),
          Divider(),
          Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text("First Wrap Option"),
                  Switch.adaptive(
                      value: showFirstOption,
                      onChanged: (value) {
                        setState(() {
                          showFirstOption = value;
                        });
                      }),
                  Text('Second Wrap Option'),
                ],
              ),
              ConditionalWrapper(
                condition: !showFirstOption,
                ifFalse: (context, child) => Container(
                  decoration: BoxDecoration(
                      border: Border.all(color: Colors.blue, width: 2)),
                  padding: EdgeInsets.all(5),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text('This is the second'),
                      child,
                      Text('wrapping option'),
                    ],
                  ),
                ),
                child: Container(
                    padding: EdgeInsets.all(5),
                    color: Colors.blue,
                    child: Text('Child Widget')),
                builder: (BuildContext context, Widget child) {
                  return Container(
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.red, width: 2),
                    ),
                    padding: EdgeInsets.all(5),
                    child: Column(
                      children: <Widget>[
                        Text('This is the first'),
                        child,
                        Text('wrapping option'),
                      ],
                    ),
                  );
                },
              ),
            ],
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  conditional_wrapper: ^1.0.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:conditional_wrapper/conditional_wrapper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
71
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
94
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • conditional_wrapper that is a package requiring null.

Maintenance suggestions

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test