flutter_object_form_field 1.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new60

flutter_object_form_field

Working with TextFormField is nice until you want to work with something other than String. For example, if you want invoke date timer picker, you have to create a focus node, listen for focus, show the dialog when needed. If you do not want to use some special object to store the selected value, you will end up with parsing the data before save just because TextFormField only works with String.

This library provides ObjectFormField<T> that works much better for these cases. You provide it with a function that turns your object into String and a picker async function that returns newly picked object (DateTime from date picker).

Usage

To use this plugin, add flutter_object_form_field as a dependency in your pubspec.yaml file.

Examples


//
// USAGE WITH CUSTOM OBJECT
//
ObjectFormField<Emotion>(
  objectToString: (emotion) => emotion?.name,
  pickValue: (oldEmotion) async {
    // returns an emotion object
    return await Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => EmotionsPage()));
  },
  decoration: InputDecoration(labelText: 'Emotion'),
  validator: (value) {
    if (value == null) {
      return 'You have to pick an emotion';

    if (value.name == 'Sadness') {
      return 'Show me your smile!';
    }
  },
),
//
// USAGE WITH DATE TIME
//
ObjectFormField<DateTime>(
  // can use some kind of formatter
  objectToString: (dateTime) => dateTime?.toString(),
  pickValue: (oldDate) async {
    return await showDatePicker(
      context: context,
      initialDate: DateTime.now(),
      firstDate: DateTime(1900),
      lastDate: DateTime(2100),
    );
  },
  decoration: InputDecoration(labelText: 'Date'),
  validator: (value) {
    if (value == null) {
      return 'You have to select date';
    }
  },
),

Contribution and Support

Contributions are welcome!<br> If you want to contribute code please create a PR<br> If you find a bug or want a feature, please fill an issue

[1.0.1] - 01.11.2018

  • Minor bug fix

[1.0.0] - 01.11.2018

  • No changes

[0.0.1] - 01.11.2018

  • Initial implementation

example/README.md

Example

The example consists of two fields - one with custom object Emotion and the other with DateTime object.

Have a look at lib/main.dart.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_object_form_field: ^1.0.1

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:flutter_object_form_field/flutter_object_form_field.dart';
  
Version Uploaded Documentation Archive
1.0.1 Nov 1, 2018 Go to the documentation of flutter_object_form_field 1.0.1 Download flutter_object_form_field 1.0.1 archive
1.0.0 Nov 1, 2018 Go to the documentation of flutter_object_form_field 1.0.0 Download flutter_object_form_field 1.0.0 archive
0.0.1 Nov 1, 2018 Go to the documentation of flutter_object_form_field 0.0.1 Download flutter_object_form_field 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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