Coder Social home page Coder Social logo

farajshuaib / flutter_formik Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 7 KB

A form management library for Flutter inspired by React Formik.

Home Page: https://pub.dev/packages/flutter_formik

License: Other

Dart 100.00%
dart flutter form validation

flutter_formik's Introduction

Flutter Formik

Flutter Formik is a form management library for Flutter inspired by the React Formik package. It provides an easy and intuitive way to handle form state, validation, and submission in your Flutter applications. Flutter Formik is designed to be simple, flexible, and extensible, allowing you to build complex forms with minimal boilerplate code. It is built on top of the form_validator package to provide customizable validation rules and error messages, this package remind of yup js library lol.

Features

  • Simple and declarative API for managing form state
  • Built-in validation support with customizable validation rules using form_validator package
  • Form submission handling with optional asynchronous operations
  • Integration with Flutter's widget tree for seamless rendering
  • Designed to promote separation of concerns and reusability

Installation

To use Flutter Formik in your Flutter project, add the following line to your pubspec.yaml file:

dependencies:
  flutter_formik: ^1.0.0

Then run flutter pub get to install the package.

Usage

Here's a basic example of how to use Flutter Formik:

import 'package:flutter/material.dart';
import 'package:flutter_formik/flutter_formik.dart';
import 'package:form_validator/form_validator.dart';

void main() {
  runApp(const Demo());
}

class Demo extends StatelessWidget {
  const Demo({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Formik Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
          title: const Text('Flutter Formik Demo'),
        ),
        body: Formik(
          initialValues: {
            'email': '',
            'password': '',
          },
          validationSchema: {
            'email': ValidationBuilder().required('Email is required').email('Email is not valid'),
            'password': ValidationBuilder().required('Password is required').minLength(6, 'Password must be at least 6 characters'),
          },
          onSubmit: (payload, errors) {
            if (errors.isNotEmpty) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(
                  content: Text(errors.values.first),
                ),
              );
              return;
            }
            UserModel user = UserModel.fromJson(payload);
            // Send user object to your business logic
            // ...
          },
          child: (values, isValid, handleSubmit, handleReset, handleChange, errors) {
            return Column(
              children: <Widget>[
                TextField(
                  decoration: InputDecoration(
                    labelText: 'Email',
                    errorText: errors['email'],
                  ),
                  onChanged: (value) {
                    handleChange('email', value);
                  },
                ),
                TextField(
                  decoration: InputDecoration(
                    labelText: 'Password',
                    errorText: errors['password'],
                  ),
                  onChanged: (value) {
                    handleChange('password', value);
                  },
                ),
                ElevatedButton(
                  onPressed: () {
                    handleSubmit();
                  },
                  child: const Text('Submit'),
                ),
              ],
            );
          },
        ),
      ),
    );
  }
}

For more detailed examples and advanced usage, please refer to the examples folder in the Flutter Formik GitHub repository.

Documentation

The documentation for Flutter Formik is available in the GitHub repository. It provides detailed explanations of the available features, usage guidelines, and API references.

Contributing

Contributions to Flutter Formik are welcome and encouraged! If you have any ideas, suggestions, or bug reports, please feel free to open an issue or submit a pull request on the GitHub repository.

License

Flutter Formik is licensed under the MIT License. See the LICENSE file for more information. []: # (END)

flutter_formik's People

Stargazers

NAEEM avatar Omar Almgerbie avatar

Watchers

faraj Shuaib avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.