dhk_counter

A package that allows to add a counter to the application

Getting Started

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

###Example

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> {
  String _name;
  int _age;
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Form(
          key: _formKey,
          child: Padding(
            padding: EdgeInsets.all(15.0),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Text("Please enter you name and age"),
                TextFormField(
                  autovalidate: false,
                  onSaved: (value) => this._name = value,
                  validator: (value) {
                    if (value.length < 3)
                      return 'A minimum of 3 characters required';
                  },
                ),
                CounterFormField(
                  autoValidate: false,
                  onSaved: (value) => this._age = value,
                  validator: (value) {
                    if (value < 0) return 'value cannot be negative';
                  },
                ),
                RaisedButton(
                  child: Text("Submit"),
                  onPressed: () {
                    if (this._formKey.currentState.validate()) {
                      setState(() {
                        this._formKey.currentState.save();
                      });
                    }
                  },
                ),
                SizedBox(
                  height: 50.0,
                ),
                Text('${this._name} is ${this._age} years old'),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Libraries

counter
dhk_counter