0.1.0: Update README.md, made small changes

This commit is contained in:
reidha 2020-04-12 21:08:32 +07:00
parent e68b05e8be
commit 98cdab0277
5 changed files with 108 additions and 103 deletions

View file

@ -1,3 +1,10 @@
## [0.1.0] - April 12, 2020
* Big fix: CheckboxIconFormField.enabled was not working
* Default colors can be set by providing `context` properly
* Update README.md
## [0.0.1] - April 12, 2020
* Add CheckboxListTileFormField

View file

@ -1,104 +1,4 @@
library checkbox_formfield;
import 'package:flutter/material.dart';
class CheckboxListTileFormField extends FormField<bool> {
CheckboxListTileFormField({
Key key,
Widget title,
BuildContext context,
FormFieldSetter<bool> onSaved,
FormFieldValidator<bool> validator,
bool initialValue = false,
bool autovalidate = false,
bool enabled = true,
bool dense = false,
Color activeColor,
Color checkColor = const Color(0xFFFFFFFF),
ListTileControlAffinity listTileControlAffinity =
ListTileControlAffinity.leading,
Widget secondary,
}) : super(
key: key,
onSaved: onSaved,
validator: validator,
initialValue: initialValue,
autovalidate: autovalidate,
builder: (FormFieldState<bool> state) {
return CheckboxListTile(
title: title,
dense: dense,
// if active color is null, Theme.of(context).accentColor will be used.
activeColor: activeColor,
checkColor: checkColor,
value: state.value,
onChanged: enabled ? state.didChange : null,
subtitle: state.hasError
? Text(
state.errorText,
style: context == null
? TextStyle(color: Colors.red)
: TextStyle(color: Theme.of(context).errorColor),
)
: null,
controlAffinity: listTileControlAffinity,
secondary: secondary,
);
},
);
}
class CheckboxIconFormField extends FormField<bool> {
CheckboxIconFormField({
Key key,
BuildContext context,
FormFieldSetter<bool> onSaved,
//FormFieldValidator<bool> validator,
bool initialValue = false,
bool autovalidate = false,
bool enabled = true,
IconData trueIcon = Icons.check,
Color trueIconColor,
IconData falseIcon = Icons.check_box_outline_blank,
Color falseIconColor,
double padding = 24.0,
double iconSize = 24.0,
}) : super(
key: key,
onSaved: onSaved,
//validator: validator,
initialValue: initialValue,
autovalidate: autovalidate,
builder: (FormFieldState<bool> state) {
return Padding(
padding: EdgeInsets.all(padding),
child: _createTappableIcon(state, trueIcon, trueIconColor,
falseIcon, falseIconColor, iconSize),
);
},
);
static Widget _createTappableIcon(
FormFieldState<bool> state,
IconData trueIcon,
Color trueIconColor,
IconData falseIcon,
Color falseIconColor,
double iconSize) {
if (state.value) {
return GestureDetector(
onTap: () {
state.didChange(false);
},
child: Icon(trueIcon, color: trueIconColor, size: iconSize),
);
} else {
return GestureDetector(
onTap: () {
state.didChange(true);
},
child: Icon(falseIcon, color: falseIconColor, size: iconSize),
);
}
}
}
export './checkbox_list tile_formfield.dart';
export './checkbox_icon_formfield.dart';

View file

@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
class CheckboxIconFormField extends FormField<bool> {
CheckboxIconFormField({
Key key,
BuildContext context,
FormFieldSetter<bool> onSaved,
bool initialValue = false,
bool autovalidate = false,
bool enabled = true,
IconData trueIcon = Icons.check,
IconData falseIcon = Icons.check_box_outline_blank,
Color trueIconColor,
Color falseIconColor,
Color disabledColor,
double padding = 24.0,
double iconSize,
}) : super(
key: key,
onSaved: onSaved,
initialValue: initialValue,
autovalidate: autovalidate,
builder: (FormFieldState<bool> state) {
trueIconColor ??= (context == null
? null
: Theme.of(context).accentIconTheme.color);
return Padding(
padding: EdgeInsets.all(padding),
child: state.value
? _createTappableIcon(state, enabled, trueIcon,
trueIconColor, disabledColor, iconSize)
: _createTappableIcon(state, enabled, falseIcon,
falseIconColor, disabledColor, iconSize));
},
);
static Widget _createTappableIcon(FormFieldState<bool> state, bool enabled,
IconData icon, Color iconColor, Color disabledColor, double iconSize) {
return IconButton(
onPressed: enabled
? () {
state.didChange(!state.value);
}
: null,
icon: Icon(icon,
color: enabled ? iconColor : disabledColor, size: iconSize),
);
}
}

View file

@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
class CheckboxListTileFormField extends FormField<bool> {
CheckboxListTileFormField({
Key key,
Widget title,
BuildContext context,
FormFieldSetter<bool> onSaved,
FormFieldValidator<bool> validator,
bool initialValue = false,
bool autovalidate = false,
bool enabled = true,
bool dense = false,
Color errorColor,
Color activeColor,
Color checkColor,
ListTileControlAffinity controlAffinity = ListTileControlAffinity.leading,
Widget secondary,
}) : super(
key: key,
onSaved: onSaved,
validator: validator,
initialValue: initialValue,
autovalidate: autovalidate,
builder: (FormFieldState<bool> state) {
errorColor ??=
(context == null ? Colors.red : Theme.of(context).errorColor);
return CheckboxListTile(
title: title,
dense: dense,
activeColor: activeColor,
checkColor: checkColor,
value: state.value,
onChanged: enabled ? state.didChange : null,
subtitle: state.hasError
? Text(
state.errorText,
style: TextStyle(color: errorColor),
)
: null,
controlAffinity: controlAffinity,
secondary: secondary,
);
},
);
}

View file

@ -1,7 +1,8 @@
name: checkbox_formfield
description: A few kinds of checkbox that can be used as FormField
version: 0.0.1
version: 0.1.0
homepage: https://reidha.github.io/
repository: https://github.com/reidha/checkbox_formfield
environment:
sdk: ">=2.1.0 <3.0.0"