form_submit_button 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

Make use of FormState in a StatelessWidget Form. #

A button to be used in a Form, which will pass the Form's state in the onPressed method.

Why use StatelessWidget? #

If you are using the container/presentation pattern and want to use the Form as a presentation component, which most of the time you do, you would want somehow to get a hold of the FormState.

How to use it #

Check the example.

Change Log for form_submit_button #

A button to be used in a Form, which will pass the Form's state in the onPressed method.

v0.1.0 - 2019-03-19

Chore #

Docs #

Test #

This CHANGELOG.md was generated with Changelog for Dart

example/example.dart

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

typedef FormSubmittedCallback = void Function(Map<String, String>);

class FormPresentation extends StatelessWidget {
  final Map<String, String> values = const {};

  /// Input
  final String initialValue;

  /// Output
  final FormSubmittedCallback formSubmitted;

  const FormPresentation({Key key, this.initialValue, this.formSubmitted})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Form(
      child: Column(
        children: <Widget>[
          TextFormField(
            decoration: InputDecoration(labelText: 'Field1'),
            onSaved: (value) => values['Field1'] = value,
            initialValue: this.initialValue,
          ),
          FormSubmitButton(
            child: Text('submit'),
            submit: (FormState state) {
              if (state.validate()) {
                state.save();
                this.formSubmitted(this.values);
              }
            },
          ),
        ],
      ),
    );
  }
}

class FormContainer extends StatefulWidget {
  @override
  _FormContainerState createState() => _FormContainerState();
}

class _FormContainerState extends State<FormContainer> {
  @override
  Widget build(BuildContext context) {
    return FormPresentation(
      initialValue: 'value',
      formSubmitted: (Map<String, String> values) {
        //Probably serialize it to your model here and use a BLoC to save it
      },
    );
  }
}

main() {
  runApp(MaterialApp(
    title: 'FormSubmitButton Example',
    home: Scaffold(
      body: FormContainer(),
    ),
  ));
}

Use this package as a library

1. Depend on it

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


dependencies:
  form_submit_button: ^0.1.0

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:form_submit_button/form_submit_button.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
12
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]
56
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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