diff --git a/lib/components/form/form_field/decorations/gf_formfield_decoration.dart b/lib/components/form/form_field/decorations/gf_formfield_decoration.dart index 5c1863cf..ceab3092 100644 --- a/lib/components/form/form_field/decorations/gf_formfield_decoration.dart +++ b/lib/components/form/form_field/decorations/gf_formfield_decoration.dart @@ -1,83 +1,94 @@ import 'package:flutter/material.dart'; import 'package:getwidget/shape/gf_textfield_shape.dart'; -class GfFormFieldDecoration extends InputDecoration { - const GfFormFieldDecoration( - {required this.context, - required this.shape, - required this.bgfilled, - this.bgcolor, - this.editingBorderColor, - this.idleBorderColor, - this.borderRadius, - this.textColor, - this.radius, - this.borderWidth, - this.gfprefixIcon, - this.hinttext, - this.fieldPadding}); - final Color? editingBorderColor; - final Color? textColor; - final double? radius; - final GFTextFieldShape shape; - final Color? idleBorderColor; - final BuildContext context; - final double? borderWidth; - final Widget? gfprefixIcon; - final double? borderRadius; - final String? hinttext; - final bool bgfilled; - final Color? bgcolor; - final EdgeInsets? fieldPadding; +class GfFormFieldDecoration extends InputDecoration{ + + + const GfFormFieldDecoration({ + required this.context, + required this.shape, + required this.bgfilled, + this.bgcolor, + this.editingBorderColor, + this.idleBorderColor, + this.borderRadius, + this.textColor, + this.radius, + this.borderWidth, + this.gfprefixIcon, + this.hinttext, + this.fieldPadding + }); + + final Color? editingBorderColor; + final Color? textColor; + final double? radius; + final GFTextFieldShape shape; + final Color? idleBorderColor; + final BuildContext context; + final double? borderWidth; + final Widget? gfprefixIcon; + final double? borderRadius; + final String? hinttext; + final bool bgfilled; + final Color? bgcolor; + final EdgeInsets? fieldPadding; - @override - InputBorder get errorBorder => OutlineInputBorder( - borderSide: BorderSide( - color: Colors.red.shade800, - width: borderWidth ?? 0, - ), - borderRadius: getradius(shape), - ); + + @override + InputBorder get errorBorder => + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red.shade800, + width: borderWidth??0, + ), + borderRadius: getradius(shape), + ); @override - InputBorder get focusedErrorBorder => OutlineInputBorder( + InputBorder get focusedErrorBorder => + OutlineInputBorder( borderSide: BorderSide( color: Colors.red, - width: borderWidth ?? 0, + width: borderWidth??0, ), borderRadius: getradius(shape), ); - @override - InputBorder get focusedBorder => OutlineInputBorder( + @override + InputBorder get focusedBorder => + OutlineInputBorder( borderSide: BorderSide( - color: editingBorderColor ?? Theme.of(context).primaryColor, - width: borderWidth ?? 0, + color: editingBorderColor??Theme.of(context).primaryColor, + width: borderWidth??0, ), borderRadius: getradius(shape), ); + @override + InputBorder get enabledBorder => + OutlineInputBorder( + borderSide: BorderSide( + color: editingBorderColor??Theme.of(context).primaryColor, + width: borderWidth??0, + ), + borderRadius: getradius(shape), + ); @override - InputBorder get enabledBorder => OutlineInputBorder( - borderSide: BorderSide( - color: editingBorderColor ?? Theme.of(context).primaryColor, - width: borderWidth ?? 0, - ), - borderRadius: getradius(shape), - ); - @override - InputBorder get border => OutlineInputBorder( + InputBorder get border => + OutlineInputBorder( borderSide: BorderSide( - color: editingBorderColor ?? Theme.of(context).primaryColor, - width: borderWidth ?? 0, + color: editingBorderColor??Theme.of(context).primaryColor, + width: borderWidth??0, ), borderRadius: getradius(shape), ); @override - InputBorder get disabledBorder => OutlineInputBorder( + InputBorder get disabledBorder => + OutlineInputBorder( borderSide: BorderSide( - color: editingBorderColor ?? Theme.of(context).primaryColor, - width: borderWidth ?? 0, + color: editingBorderColor??Theme.of(context).primaryColor, + width: borderWidth??0, ), borderRadius: getradius(shape), ); @@ -95,22 +106,21 @@ class GfFormFieldDecoration extends InputDecoration { Color? get fillColor => bgcolor; @override - EdgeInsets get contentPadding => - fieldPadding ?? const EdgeInsets.symmetric(horizontal: 4, vertical: 4); + EdgeInsets get contentPadding =>fieldPadding??const EdgeInsets.symmetric(horizontal: 4,vertical: 4); - BorderRadius getradius(GFTextFieldShape shape) { - double radius = 0; - switch (shape) { + BorderRadius getradius(GFTextFieldShape shape){ + double radius=0; + switch (shape){ case GFTextFieldShape.pills: - radius = 50; + radius=50; break; case GFTextFieldShape.roundedsquare: - radius = borderRadius ?? 0; + radius=borderRadius??0; break; case GFTextFieldShape.square: - radius = 0; + radius=0; break; } return BorderRadius.circular(radius); } -} +} \ No newline at end of file diff --git a/lib/components/form/form_field/gf_form_field.dart b/lib/components/form/form_field/gf_form_field.dart deleted file mode 100644 index f2ee1fcf..00000000 --- a/lib/components/form/form_field/gf_form_field.dart +++ /dev/null @@ -1,883 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:getwidget/components/form/form_field/decorations/gf_formfield_decoration.dart'; -import 'package:getwidget/components/form/form_field/validators/validators.dart'; -import 'package:getwidget/components/form/form_field/widgets/gf_formradiobutton.dart'; -import 'package:getwidget/components/form/form_field/widgets/gf_questionwidget.dart'; -import 'package:getwidget/components/text_field/gf_text_field.dart'; -import 'package:getwidget/shape/gf_textfield_shape.dart'; -import 'package:getwidget/types/gf_form_field_type.dart'; - -class GfFormField extends StatefulWidget { - GfFormField( - {Key? key, - required this.gfFormFieldType, - required this.editingbordercolor, - required this.idlebordercolor, - required this.borderwidth, - required this.hintText, - this.shape, - this.backgroundcolor, - this.normalbordercolor = Colors.grey, - this.focusedbordercolor = Colors.green, - this.errorbordercolor = Colors.red, - this.disabledbordercolor = Colors.black, - this.iconPrefix, - this.paddingvertical = 3, - this.paddinghorizontal = 4, - this.marginvertical = 3, - this.marginhorizontal = 4, - this.controller, - this.initialValue = '', - this.focusNode, - this.keyboardType = TextInputType.text, - this.textCapitalization = TextCapitalization.none, - this.textInputAction, - this.style = const TextStyle(), - this.strutStyle = const StrutStyle(), - this.textDirection = TextDirection.ltr, - this.textAlign = TextAlign.start, - this.textAlignVertical = TextAlignVertical.center, - this.autofocus = false, - this.readOnly = false, - this.toolbarOptions = const ToolbarOptions( - copy: true, cut: true, paste: true, selectAll: true), - this.showCursor, - this.obscuringCharacter = '.', - this.obscureText = false, - this.autocorrect = true, - this.smartDashesType, - this.smartQuotesType, - this.enableSuggestions = true, - this.autovalidate = true, - this.maxLengthEnforced = MaxLengthEnforcement.none, - this.maxLines = 1, - this.minLines = 1, - this.expands = false, - this.maxLength, - this.onChanged, - this.onTap, - this.onEditingComplete, - this.onFieldSubmitted, - this.onSaved, - this.validator, - this.inputFormatters, - this.enabled = true, - this.cursorWidth = 2.0, - this.cursorHeight, - this.cursorRadius, - this.cursorColor, - this.color, - this.borderradius, - this.keyboardAppearance, - this.scrollPadding = const EdgeInsets.all(20), - this.enableInteractiveSelection = true, - this.buildCounter, - this.scrollPhysics, - this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled, - this.onGenderChanged, - this.initialGender, - this.question, - this.acceptButtonText, - this.declineButtonText, - this.onQuestionWidgetChanged}) - : super(key: key) { - if (gfFormFieldType == GfFormFieldType.question && question == null) { - throw Exception('Question cannot be Null for question widget'); - } - } - final GfFormFieldType gfFormFieldType; - final Color normalbordercolor; - final Color editingbordercolor; - final Color focusedbordercolor; - final Color errorbordercolor; - final Color idlebordercolor; - final Color disabledbordercolor; - final double borderwidth; - final double? paddingvertical; - final double? paddinghorizontal; - final double? marginvertical; - final double? marginhorizontal; - final Color? backgroundcolor; - final GFTextFieldShape? shape; - final String hintText; - final Widget? iconPrefix; - final TextEditingController? controller; - final String initialValue; - final FocusNode? focusNode; - final TextInputType? keyboardType; - final TextCapitalization textCapitalization; - final TextInputAction? textInputAction; - final TextStyle? style; - final StrutStyle? strutStyle; - final TextDirection? textDirection; - final TextAlign? textAlign; - final TextAlignVertical? textAlignVertical; - final bool autofocus; - final bool? readOnly; - final ToolbarOptions? toolbarOptions; - final bool? showCursor; - final String obscuringCharacter; - final bool obscureText; - final bool autocorrect; - final SmartDashesType? smartDashesType; - final SmartQuotesType? smartQuotesType; - final bool enableSuggestions; - final bool? autovalidate; - final MaxLengthEnforcement maxLengthEnforced; - final int? maxLines; - final int? minLines; - final bool expands; - final int? maxLength; - final ValueChanged? onChanged; - final Function(String?)? onGenderChanged; - final GestureTapCallback? onTap; - final VoidCallback? onEditingComplete; - final ValueChanged? onFieldSubmitted; - final FormFieldSetter? onSaved; - final FormFieldValidator? validator; - final List? inputFormatters; - final bool enabled; - final double? cursorWidth; - final double? cursorHeight; - final Radius? cursorRadius; - final Color? cursorColor; - final Color? color; - final double? borderradius; - final Brightness? keyboardAppearance; - final EdgeInsets scrollPadding; - final bool enableInteractiveSelection; - final InputCounterWidgetBuilder? buildCounter; - final ScrollPhysics? scrollPhysics; - final Iterable? autofillHints; - final AutovalidateMode autovalidateMode; - final String? initialGender; - final String? question; - final String? acceptButtonText; - final String? declineButtonText; - final Function(String?)? onQuestionWidgetChanged; - - @override - _GfFormFieldState createState() => _GfFormFieldState(); -} - -class _GfFormFieldState extends State - with AutomaticKeepAliveClientMixin { - String value = 'India'; - final List countries = [ - 'Afghanistan', - 'Albania', - 'Algeria', - 'Andorra', - 'Angola', - 'Anguilla', - 'Antigua & Barbuda', - 'Argentina', - 'Armenia', - 'Aruba', - 'Australia', - 'Austria', - 'Azerbaijan', - 'Bahamas', - 'Bahrain', - 'Bangladesh', - 'Barbados', - 'Belarus', - 'Belgium', - 'Belize', - 'Benin', - 'Bermuda', - 'Bhutan', - 'Bolivia', - 'Bosnia & Herzegovina', - 'Botswana', - 'Brazil', - 'British Virgin Islands', - 'Brunei', - 'Bulgaria', - 'Burkina Faso', - 'Burundi', - 'Cambodia', - 'Cameroon', - 'Cape Verde', - 'Cayman Islands', - 'Chad', - 'Chile', - 'China', - 'Colombia', - 'Congo', - 'Cook Islands', - 'Costa Rica', - 'Cote D Ivoire', - 'Croatia', - 'Cruise Ship', - 'Cuba', - 'Cyprus', - 'Czech Republic', - 'Denmark', - 'Djibouti', - 'Dominica', - 'Dominican Republic', - 'Ecuador', - 'Egypt', - 'El Salvador', - 'Equatorial Guinea', - 'Estonia', - 'Ethiopia', - 'Falkland Islands', - 'Faroe Islands', - 'Fiji', - 'Finland', - 'France', - 'French Polynesia', - 'French West Indies', - 'Gabon', - 'Gambia', - 'Georgia', - 'Germany', - 'Ghana', - 'Gibraltar', - 'Greece', - 'Greenland', - 'Grenada', - 'Guam', - 'Guatemala', - 'Guernsey', - 'Guinea', - 'Guinea Bissau', - 'Guyana', - 'Haiti', - 'Honduras', - 'Hong Kong', - 'Hungary', - 'Iceland', - 'India', - 'Indonesia', - 'Iran', - 'Iraq', - 'Ireland', - 'Isle of Man', - 'Israel', - 'Italy', - 'Jamaica', - 'Japan', - 'Jersey', - 'Jordan', - 'Kazakhstan', - 'Kenya', - 'Kuwait', - 'Kyrgyz Republic', - 'Laos', - 'Latvia', - 'Lebanon', - 'Lesotho', - 'Liberia', - 'Libya', - 'Liechtenstein', - 'Lithuania', - 'Luxembourg', - 'Macau', - 'Macedonia', - 'Madagascar', - 'Malawi', - 'Malaysia', - 'Maldives', - 'Mali', - 'Malta', - 'Mauritania', - 'Mauritius', - 'Mexico', - 'Moldova', - 'Monaco', - 'Mongolia', - 'Montenegro', - 'Montserrat', - 'Morocco', - 'Mozambique', - 'Namibia', - 'Nepal', - 'Netherlands', - 'Netherlands Antilles', - 'New Caledonia', - 'New Zealand', - 'Nicaragua', - 'Niger', - 'Nigeria', - 'Norway', - 'Oman', - 'Pakistan', - 'Palestine', - 'Panama', - 'Papua New Guinea', - 'Paraguay', - 'Peru', - 'Philippines', - 'Poland', - 'Portugal', - 'Puerto Rico', - 'Qatar', - 'Reunion', - 'Romania', - 'Russia', - 'Rwanda', - 'Saint Pierre & Miquelon', - 'Samoa', - 'San Marino', - 'Satellite', - 'Saudi Arabia', - 'Senegal', - 'Serbia', - 'Seychelles', - 'Sierra Leone', - 'Singapore', - 'Slovakia', - 'Slovenia', - 'South Africa', - 'South Korea', - 'Spain', - 'Sri Lanka', - 'St Kitts & Nevis', - 'St Lucia', - 'St Vincent', - 'St. Lucia', - 'Sudan', - 'Suriname', - 'Swaziland', - 'Sweden', - 'Switzerland', - 'Syria', - 'Taiwan', - 'Tajikistan', - 'Tanzania', - 'Thailand', - 'Timor LEste', - 'Togo', - 'Tonga', - 'Trinidad & Tobago', - 'Tunisia', - 'Turkey', - 'Turkmenistan', - 'Turks & Caicos', - 'Uganda', - 'Ukraine', - 'United Arab Emirates', - 'United Kingdom', - 'Uruguay', - 'Uzbekistan', - 'Venezuela', - 'Vietnam', - 'Virgin Islands (US)', - 'Yemen', - 'Zambia', - 'Zimbabwe' - ]; - @override - Widget build(BuildContext context) { - super.build(context); - return getFormWidget(widget.gfFormFieldType); - } - - Widget getFormWidget(GfFormFieldType type) { - Widget retwidget = Container(); - switch (type) { - case GfFormFieldType.name: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: widget.shape ?? GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.name, - textCapitalization: TextCapitalization.words, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: widget.obscureText, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: - widget.validator ?? GfFormValidators().getnamevalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode), - ); - break; - case GfFormFieldType.password: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: - widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.visiblePassword, - textCapitalization: TextCapitalization.none, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: true, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: widget.validator ?? - GfFormValidators().getpasswordvalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode)); - break; - case GfFormFieldType.email: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: - widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.emailAddress, - textCapitalization: TextCapitalization.none, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: widget.obscureText, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: - widget.validator ?? GfFormValidators().getemailvalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode)); - break; - case GfFormFieldType.phone: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.phone, - textCapitalization: TextCapitalization.none, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: widget.obscureText, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: - widget.validator ?? GfFormValidators().getphonevalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode), - ); - break; - case GfFormFieldType.country: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: DropdownButtonFormField( - value: value, - decoration: GfFormFieldDecoration( - context: context, - shape: GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - validator: (value) => null, - items: countries - .map>( - (String value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - onChanged: (String? textx) { - setState(() { - value = textx.toString(); - }); - }), - ); - break; - case GfFormFieldType.text: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: widget.shape ?? GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: - widget.hintText.isNotEmpty ? widget.hintText : 'Value', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.text, - textCapitalization: TextCapitalization.words, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: widget.obscureText, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: - widget.validator ?? GfFormValidators().gettextvalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode), - ); - break; - case GfFormFieldType.number: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GFTextField( - decoration: GfFormFieldDecoration( - context: context, - shape: widget.shape ?? GFTextFieldShape.roundedsquare, - borderRadius: widget.borderradius ?? 6.0, - editingBorderColor: widget.editingbordercolor, - idleBorderColor: widget.idlebordercolor, - gfprefixIcon: widget.iconPrefix, - bgfilled: true, - bgcolor: widget.backgroundcolor, - hinttext: widget.hintText.isNotEmpty ? widget.hintText : 'Name', - ), - controller: widget.controller, - fieldinitialValue: widget.initialValue, - focusNode: widget.focusNode, - keyboardType: TextInputType.number, - textCapitalization: TextCapitalization.words, - textInputAction: widget.textInputAction, - style: widget.style, - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - textAlign: widget.textAlign, - textAlignVertical: widget.textAlignVertical, - autofocus: widget.autofocus, - readOnly: widget.readOnly, - toolbarOptions: widget.toolbarOptions, - showCursor: widget.showCursor, - obscuringCharacter: widget.obscuringCharacter, - obscureText: widget.obscureText, - autocorrect: widget.autocorrect, - smartDashesType: widget.smartDashesType, - smartQuotesType: widget.smartQuotesType, - enableSuggestions: widget.enableSuggestions, - autovalidate: widget.autovalidate, - maxLengthEnforced: widget.maxLengthEnforced, - maxLines: widget.maxLines, - minLines: widget.minLines, - expands: widget.expands, - maxLength: widget.maxLength, - onChanged: widget.onChanged, - onTap: widget.onTap, - onEditingComplete: widget.onEditingComplete, - onFieldSubmitted: widget.onFieldSubmitted, - onfieldSaved: widget.onSaved, - validatornew: - widget.validator ?? GfFormValidators().getnumbervalidator(), - inputFormatters: widget.inputFormatters, - fieldEnabled: widget.enabled, - cursorWidth: widget.cursorWidth, - cursorHeight: widget.cursorHeight, - cursorRadius: widget.cursorRadius, - cursorColor: widget.cursorColor, - color: widget.color, - keyboardAppearance: widget.keyboardAppearance, - scrollPadding: widget.scrollPadding, - enableInteractiveSelection: widget.enableInteractiveSelection, - buildCounter: widget.buildCounter, - scrollPhysics: widget.scrollPhysics, - autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode), - ); - break; - case GfFormFieldType.gender: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GfFormRadiobutton( - onChanged: widget.onGenderChanged ?? - (value) { - print('Gender changed $value'); - }, - initialSelectedValue: widget.initialGender ?? 'Male', - )); - break; - case GfFormFieldType.question: - retwidget = Container( - margin: EdgeInsets.symmetric( - vertical: widget.marginvertical ?? 2, - horizontal: widget.marginhorizontal ?? 2), - padding: EdgeInsets.symmetric( - vertical: widget.paddingvertical ?? 2, - horizontal: widget.paddinghorizontal ?? 2), - child: GfFormQuestionWidget( - onChanged: widget.onQuestionWidgetChanged ?? - (value) { - print('Question changed $value'); - }, - initialSelectedValue: 'Decline', - question: - widget.question ?? 'Do you accept the Terms and Condition?', - accepttext: widget.acceptButtonText ?? 'Accept', - declinetext: widget.declineButtonText ?? 'Decline', - )); - break; - } - return retwidget; - } - - @override - bool get wantKeepAlive => true; -} diff --git a/lib/components/form/form_field/gf_formhandler_widget.dart b/lib/components/form/form_field/gf_formhandler_widget.dart new file mode 100644 index 00000000..ee7ad966 --- /dev/null +++ b/lib/components/form/form_field/gf_formhandler_widget.dart @@ -0,0 +1,24 @@ + +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; + +class GfFormHandlerWidget extends InheritedWidget{ + const GfFormHandlerWidget({ + required this.gfFormHandler, + required Widget child + }) : super(child: child); + +final GfFormHandler gfFormHandler; + + + static GfFormHandlerWidget of(BuildContext context) { + final GfFormHandlerWidget? result = context.dependOnInheritedWidgetOfExactType(); + assert(result != null, 'No GfFormHandlerWidget found in context'); + return result!; + } + + @override + bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; + + +} \ No newline at end of file diff --git a/lib/components/form/form_field/validators/validators.dart b/lib/components/form/form_field/validators/validators.dart index 8b0e36bd..2716d39d 100644 --- a/lib/components/form/form_field/validators/validators.dart +++ b/lib/components/form/form_field/validators/validators.dart @@ -1,114 +1,100 @@ -class GfFormValidators { - String? Function(String?) getnamevalidator( - {String? emptyErrorText, String? errorText, int? length}) { - final int txtlength = length ?? 6; - emptyErrorText ??= 'Please enter name'; - errorText ??= 'Name should be $txtlength characters or more'; - String? nameValidator(String? value) { - if (value == null || value.isEmpty) { - return emptyErrorText; - } - if (value.length < txtlength) { - return errorText; - } - return null; - } - - return nameValidator; - } - String? Function(String?) getemailvalidator( - {String? emptyErrorText, String? errorText, int? length}) { - final int txtlength = length ?? 6; - emptyErrorText ??= 'Please enter email id'; - errorText ??= 'Check your email'; +class GfFormValidators{ + String? Function(String?) getnamevalidator({String? emptyErrorText,String? errorText,int? length}) { + final int txtlength=length??6; + emptyErrorText??='Please enter name'; + errorText??='Name should be $txtlength characters or more'; + String? nameValidator(String? value) { + if (value == null || value.isEmpty) { + return emptyErrorText; + } + if(value.length createState() => _GfDatePickerState(); + + + final String? errorText; + final String? confirmText; + final String? cancelText; + final String? helpText; + final String? hourLabelText; + final String? minuteLabelText; + final DateTime? defaultDate; + final DateTime? initialDate; + final DateTime? lastDate; + final Color? borderColor; + final String? headingText; + final String? labelText; + final double? borderWidth; + final String? buttonText; + final Icon? buttonIcon; + final EdgeInsets? margin; + final EdgeInsets? padding; + +} + +class _GfDatePickerState extends State { + late final GfFormHandler gfFormHandler; + DateTime selectedDate = DateTime.now(); + late final GfDatePickerData dataModel; + + @override + void initState() { + selectedDate = widget.defaultDate ?? DateTime.now(); + dataModel = GfDatePickerData(selectedDate: selectedDate); + super.initState(); + } + + Future _selectDate(BuildContext context) async { + final DateTime? picked = await showDatePicker( + context: context, + initialDate: selectedDate, + firstDate: widget.initialDate ?? DateTime(1950), + lastDate: widget.lastDate ?? DateTime.now(), + confirmText: widget.confirmText, + cancelText: widget.cancelText, + errorInvalidText: widget.errorText, + helpText: widget.helpText, + ); + if (picked != null && picked != selectedDate) { + dataModel.setDate(picked); + } + } + + + @override + Widget build(BuildContext context) { + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } + return Container( + margin: widget.margin ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + padding: widget.padding ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) { + selectedDate = dataModel.getDate(); + return InputDecorator( + decoration: InputDecoration( + label: widget.headingText != null ? Text( + widget.headingText.toString()) : null, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: widget.borderColor ?? Colors.black, + width: widget.borderWidth ?? 1.5) + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: widget.borderColor ?? Colors.black, + width: widget.borderWidth ?? 1.5) + ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Expanded(child: + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(widget.labelText ?? 'Selected Date', + style: const TextStyle( + color: Colors.black, fontWeight: FontWeight.w600),), + const SizedBox(height: 6,), + Text(selectedDate.toString().substring(0, 10), + style: const TextStyle(color: Colors.black,),), + ], + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + constraints: const BoxConstraints(minWidth: 64), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(60), + color: Colors.grey, + ), + child: + InkWell( + onTap: () => _selectDate(context), + child: + Row( + children: [ + widget.buttonIcon ?? const Icon( + Icons.date_range_sharp, color: Colors.black, + size: 16,), + const SizedBox(width: 8,), + Text(widget.buttonText ?? 'Pick date', + style: const TextStyle(color: Colors.black,),), + ], + ), + ), + ), + ], + ), + ); + }), + ); + } +} diff --git a/lib/components/form/form_field/widgets/gf_form_field.dart b/lib/components/form/form_field/widgets/gf_form_field.dart new file mode 100644 index 00000000..70eea2fe --- /dev/null +++ b/lib/components/form/form_field/widgets/gf_form_field.dart @@ -0,0 +1,615 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:getwidget/components/form/form_field/decorations/gf_formfield_decoration.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/validators/validators.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_formfieldprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; +import 'package:getwidget/components/text_field/gf_text_field.dart'; +import 'package:getwidget/shape/gf_textfield_shape.dart'; +import 'package:getwidget/types/gf_form_field_type.dart'; + + +class GfFormField extends StatefulWidget{ + const GfFormField({ + Key? key, + required this.gfFormFieldType, + this.editingbordercolor, + this.idlebordercolor, + this.borderwidth, + this.hintText, + this.shape, + this.backgroundcolor, + this.normalbordercolor=Colors.grey, + this.focusedbordercolor=Colors.green, + this.errorbordercolor=Colors.red, + this.disabledbordercolor=Colors.black, + this.iconPrefix, + this.paddingvertical=3, + this.paddinghorizontal=4, + this.marginvertical=3, + this.marginhorizontal=4, + this.controller, + this.initialValue='', + this.focusNode, + this.keyboardType=TextInputType.text, + this.textCapitalization=TextCapitalization.none, + this.textInputAction, + this.style=const TextStyle(), + this.strutStyle=const StrutStyle(), + this.textDirection=TextDirection.ltr, + this.textAlign=TextAlign.start, + this.textAlignVertical=TextAlignVertical.center, + this.autofocus=false, + this.readOnly=false, + this.toolbarOptions=const ToolbarOptions(copy: true,cut: true,paste: true,selectAll: true), + this.showCursor, + this.obscuringCharacter='.', + this.obscureText=false, + this.autocorrect=true, + this.smartDashesType, + this.smartQuotesType, + this.enableSuggestions=true, + this.autovalidate=true, + this.maxLengthEnforced=MaxLengthEnforcement.none, + this.maxLines=1, + this.minLines=1, + this.expands=false, + this.maxLength, + this.onChanged, + this.onTap, + this.onEditingComplete, + this.onFieldSubmitted, + this.onSaved, + this.validator, + this.inputFormatters, + this.enabled=true, + this.cursorWidth=2.0, + this.cursorHeight, + this.cursorRadius, + this.cursorColor, + this.color, + this.borderradius, + this.keyboardAppearance, + this.scrollPadding=const EdgeInsets.all(20), + this.enableInteractiveSelection=true, + this.buildCounter, + this.scrollPhysics, + this.autofillHints, + this.autovalidateMode=AutovalidateMode.disabled, + this.onGenderChanged, + + + }) :super(key: key); + final GfFormFieldType gfFormFieldType; + final Color? normalbordercolor; + final Color? editingbordercolor; + final Color? focusedbordercolor; + final Color? errorbordercolor; + final Color? idlebordercolor; + final Color? disabledbordercolor; + final double? borderwidth; + final double? paddingvertical; + final double? paddinghorizontal; + final double? marginvertical; + final double? marginhorizontal; + final Color? backgroundcolor; + final GFTextFieldShape? shape; + final String? hintText; + final Widget? iconPrefix; + final TextEditingController? controller; + final String initialValue; + final FocusNode? focusNode; + final TextInputType? keyboardType; + final TextCapitalization textCapitalization ; + final TextInputAction? textInputAction; + final TextStyle? style; + final StrutStyle? strutStyle; + final TextDirection? textDirection; + final TextAlign? textAlign ; + final TextAlignVertical? textAlignVertical; + final bool autofocus ; + final bool? readOnly ; + final ToolbarOptions? toolbarOptions; + final bool? showCursor; + final String obscuringCharacter; + final bool obscureText; + final bool autocorrect; + final SmartDashesType? smartDashesType; + final SmartQuotesType? smartQuotesType; + final bool enableSuggestions; + final bool? autovalidate; + final MaxLengthEnforcement maxLengthEnforced; + final int? maxLines; + final int? minLines; + final bool expands; + final int? maxLength; + final ValueChanged? onChanged; + final Function(String?)? onGenderChanged; + final GestureTapCallback? onTap; + final VoidCallback? onEditingComplete; + final ValueChanged? onFieldSubmitted; + final FormFieldSetter? onSaved; + final FormFieldValidator? validator; + final List? inputFormatters; + final bool enabled; + final double? cursorWidth ; + final double? cursorHeight; + final Radius? cursorRadius; + final Color? cursorColor; + final Color? color; + final double? borderradius; + final Brightness? keyboardAppearance; + final EdgeInsets scrollPadding ; + final bool enableInteractiveSelection; + final InputCounterWidgetBuilder? buildCounter; + final ScrollPhysics? scrollPhysics; + final Iterable? autofillHints; + final AutovalidateMode autovalidateMode; + + + @override + _GfFormFieldState createState()=> _GfFormFieldState(); +} + +class _GfFormFieldState extends State with AutomaticKeepAliveClientMixin{ + String value='India'; + final List countries = ['Afghanistan','Albania','Algeria','Andorra','Angola','Anguilla','Antigua & Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegovina','Botswana','Brazil','British Virgin Islands','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde','Cayman Islands','Chad','Chile','China','Colombia','Congo','Cook Islands','Costa Rica','Cote D Ivoire','Croatia','Cruise Ship','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','Ecuador','Egypt','El Salvador','Equatorial Guinea','Estonia','Ethiopia','Falkland Islands','Faroe Islands','Fiji','Finland','France','French Polynesia','French West Indies','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guam','Guatemala','Guernsey','Guinea','Guinea Bissau','Guyana','Haiti','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kuwait','Kyrgyz Republic','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Mauritania','Mauritius','Mexico','Moldova','Monaco','Mongolia','Montenegro','Montserrat','Morocco','Mozambique','Namibia','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Norway','Oman','Pakistan','Palestine','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Pierre & Miquelon','Samoa','San Marino','Satellite','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','South Africa','South Korea','Spain','Sri Lanka','St Kitts & Nevis','St Lucia','St Vincent','St. Lucia','Sudan','Suriname','Swaziland','Sweden','Switzerland','Syria','Taiwan','Tajikistan','Tanzania','Thailand','Timor LEste','Togo','Tonga','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos','Uganda','Ukraine','United Arab Emirates','United Kingdom','Uruguay','Uzbekistan','Venezuela','Vietnam','Virgin Islands (US)','Yemen','Zambia','Zimbabwe']; + + late final TextEditingController textEditingController; + late final GfFormHandler gfFormHandler; + late final GfFormFieldData dataModel; + @override + void initState(){ + textEditingController=widget.controller??TextEditingController(); + dataModel=GfFormFieldData(gfFormFieldController: textEditingController); + super.initState(); + } + + @override + Widget build(BuildContext context) { + super.build(context); + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } + return getFormWidget(widget.gfFormFieldType); + } + + + Widget getFormWidget(GfFormFieldType type){ + Widget retwidget=Container(); + switch(type){ + case GfFormFieldType.name: + retwidget= Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + GFTextField( + decoration: + GfFormFieldDecoration( + context: context, + shape: widget.shape??GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Name', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.name, + textCapitalization: TextCapitalization.words, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().getnamevalidator(), + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ), + ); + break; + case GfFormFieldType.password: + retwidget= Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + GFTextField( + decoration: GfFormFieldDecoration( + context: context, + shape: GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Name', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.visiblePassword, + textCapitalization: TextCapitalization.none, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: true, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().getpasswordvalidator(), + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ) + ); + break; + case GfFormFieldType.email: + retwidget= Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + + GFTextField( + decoration: GfFormFieldDecoration( + context: context, + shape: GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Name', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.emailAddress, + textCapitalization: TextCapitalization.none, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().getemailvalidator(), + + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ) + ); + break; + case GfFormFieldType.phone: + retwidget= + Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + GFTextField( + decoration:GfFormFieldDecoration( + context: context, + shape: GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Name', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.phone, + textCapitalization: TextCapitalization.none, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().getphonevalidator(), + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ), + ); + break; + case GfFormFieldType.text: + retwidget= Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + GFTextField( + decoration: + GfFormFieldDecoration( + context: context, + shape: widget.shape??GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Value', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.text, + textCapitalization: TextCapitalization.words, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().gettextvalidator(), + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ), + ); + break; + case GfFormFieldType.number: + retwidget= Container( + margin: EdgeInsets.symmetric(vertical: widget.marginvertical??2, + horizontal: widget.marginhorizontal??2), + padding: EdgeInsets.symmetric(vertical: widget.paddingvertical??2, + horizontal: widget.paddinghorizontal??2), + child: + GFTextField( + decoration: + GfFormFieldDecoration( + context: context, + shape: widget.shape??GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius??6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText!=null?widget.hintText:'Name', + ), + controller: textEditingController, + fieldinitialValue: widget.initialValue, + focusNode: widget.focusNode, + keyboardType: TextInputType.number, + textCapitalization: TextCapitalization.words, + textInputAction: widget.textInputAction, + style: widget.style, + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + textAlign: widget.textAlign, + textAlignVertical: widget.textAlignVertical, + autofocus: widget.autofocus, + readOnly: widget.readOnly, + toolbarOptions: widget.toolbarOptions, + showCursor: widget.showCursor, + obscuringCharacter: widget.obscuringCharacter, + obscureText: widget.obscureText, + autocorrect: widget.autocorrect, + smartDashesType: widget.smartDashesType, + smartQuotesType: widget.smartQuotesType, + enableSuggestions: widget.enableSuggestions, + autovalidate: widget.autovalidate, + maxLengthEnforced: widget.maxLengthEnforced, + maxLines: widget.maxLines, + minLines: widget.minLines, + expands: widget.expands, + maxLength: widget.maxLength, + onChanged: widget.onChanged, + onTap: widget.onTap, + onEditingComplete: widget.onEditingComplete, + onFieldSubmitted: widget.onFieldSubmitted, + onfieldSaved: widget.onSaved, + validatornew: widget.validator??GfFormValidators().getnumbervalidator(), + inputFormatters: widget.inputFormatters, + fieldEnabled: widget.enabled, + cursorWidth: widget.cursorWidth, + cursorHeight: widget.cursorHeight, + cursorRadius: widget.cursorRadius, + cursorColor: widget.cursorColor, + color: widget.color, + keyboardAppearance: widget.keyboardAppearance, + scrollPadding: widget.scrollPadding, + enableInteractiveSelection: widget.enableInteractiveSelection, + buildCounter: widget.buildCounter, + scrollPhysics: widget.scrollPhysics, + autofillHints: widget.autofillHints, + autoValidateMode: widget.autovalidateMode + ), + ); + break; + } + return retwidget; + } + + @override + bool get wantKeepAlive => true; +} + diff --git a/lib/components/form/form_field/widgets/gf_formdropdown.dart b/lib/components/form/form_field/widgets/gf_formdropdown.dart new file mode 100644 index 00000000..f109cc73 --- /dev/null +++ b/lib/components/form/form_field/widgets/gf_formdropdown.dart @@ -0,0 +1,99 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/decorations/gf_formfield_decoration.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_formdropdownprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; +import 'package:getwidget/shape/gf_textfield_shape.dart'; + +class GfFormDropDown extends StatefulWidget { + const GfFormDropDown({ + Key? key, + required this.values, + this.initialValue, + this.padding, + this.margin, + this.borderradius, + this.editingbordercolor, + this.idlebordercolor, + this.iconPrefix, + this.backgroundcolor, + this.hintText + }) : super(key: key); + final EdgeInsets? margin; + final EdgeInsets? padding; + final List values; + final String? initialValue; + final double? borderradius; + final Color? editingbordercolor; + final Color? idlebordercolor; + final Icon? iconPrefix; + final Color? backgroundcolor; + final String? hintText; + + @override + State createState() => _GfFormDropDownState(); +} + +class _GfFormDropDownState extends State { + + String selectedValue=''; + late final GfFormHandler gfFormHandler; + late final GfFormDropdownData dataModel; + + @override + void initState(){ + selectedValue=widget.initialValue??widget.values[0]; + dataModel=GfFormDropdownData(selectedValue: selectedValue); + super.initState(); + } + @override + Widget build(BuildContext context) { + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } + return + AnimatedBuilder( + animation: dataModel, + builder: (context, child) + { + selectedValue = dataModel.selectedValue; + return Container( + margin: widget.margin ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + padding: widget.padding ?? + const EdgeInsets.symmetric(vertical: 2, horizontal: 2), + child: DropdownButtonFormField( + value: selectedValue, + decoration: GfFormFieldDecoration( + context: context, + shape: GFTextFieldShape.roundedsquare, + borderRadius: widget.borderradius ?? 6.0, + editingBorderColor: widget.editingbordercolor, + idleBorderColor: widget.idlebordercolor, + gfprefixIcon: widget.iconPrefix, + bgfilled: true, + bgcolor: widget.backgroundcolor, + hinttext: widget.hintText != null ? widget.hintText : 'Name', + ), + validator: (value) => null, + items: widget.values + .map>((String value) => + DropdownMenuItem( + value: value, + child: Text(value), + ) + ).toList(), + onChanged: (String? textx) { + selectedValue = textx.toString(); + dataModel.setValue(selectedValue); + }), + ); + }); + } +} diff --git a/lib/components/form/form_field/widgets/gf_formradiobutton.dart b/lib/components/form/form_field/widgets/gf_formradiobutton.dart index 4e6e0cc2..ddb370c5 100644 --- a/lib/components/form/form_field/widgets/gf_formradiobutton.dart +++ b/lib/components/form/form_field/widgets/gf_formradiobutton.dart @@ -1,81 +1,106 @@ import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_radioprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; -class GfFormRadiobutton extends StatefulWidget { - const GfFormRadiobutton( - {Key? key, required this.onChanged, required this.initialSelectedValue}) - : super(key: key); - final Function(String?) onChanged; +class GfFormGenderbutton extends StatefulWidget { + const GfFormGenderbutton({ + Key? key, + required this.onChanged, + required this.initialSelectedValue + }) : super(key: key); + final Function(String?) onChanged; final String initialSelectedValue; @override - State createState() => _GfFormRadiobuttonState(); + State createState() => _GfFormGenderbuttonState(); } -class _GfFormRadiobuttonState extends State - with AutomaticKeepAliveClientMixin { - String selectedValue = ''; +class _GfFormGenderbuttonState extends State with AutomaticKeepAliveClientMixin{ + String selectedValue=''; + late final GfFormHandler gfFormHandler; + late final GfGenderButtonData dataModel; + @override - void initState() { - selectedValue = widget.initialSelectedValue; + void initState(){ + selectedValue=widget.initialSelectedValue; + dataModel=GfGenderButtonData(selectedValue: selectedValue); super.initState(); } - @override Widget build(BuildContext context) { super.build(context); + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } return Container( - child: Card( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - InkWell( - onTap: () { - setState(() { - selectedValue = 'Male'; - widget.onChanged(selectedValue); - }); - }, - child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Radio( - value: 'Male', - groupValue: selectedValue, - onChanged: (String? val) { - setState(() { - selectedValue = val.toString(); - widget.onChanged(selectedValue); - }); - }, - ), - const SizedBox( - width: 8, - ), - const Text('Male') - ]), - ), - InkWell( - onTap: () { - setState(() { - selectedValue = 'Female'; - widget.onChanged(selectedValue); - }); - }, - child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Radio( - value: 'Female', - groupValue: selectedValue, - onChanged: (String? val) { - setState(() { - selectedValue = val.toString(); + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) + { + selectedValue = dataModel.selectedValue; + return Card( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + InkWell( + onTap: () { + selectedValue ='Male'; widget.onChanged(selectedValue); - }); + dataModel.setValue(selectedValue.toString()); }, - ), - const SizedBox( - width: 8, - ), - const Text('Female') - ])), - ], - ))); + child: + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Radio( + value: 'Male', + groupValue: selectedValue, + onChanged: (String? val) { + if(val!=null&&val.isNotEmpty){ + selectedValue = val.toString(); + widget.onChanged(selectedValue); + dataModel.setValue(val.toString()); + } + }, + ), + const SizedBox(width: 8,), + const Text('Male') + ]),), + InkWell( + onTap: () { + selectedValue ='Female'; + widget.onChanged(selectedValue); + dataModel.setValue(selectedValue.toString()); + }, + child: + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Radio( + value: 'Female', + groupValue: selectedValue, + onChanged: (String? val) { + if(val!=null&&val.isNotEmpty){ + selectedValue = val.toString(); + widget.onChanged(selectedValue); + dataModel.setValue(val.toString()); + } + }, + ), + const SizedBox(width: 8,), + const Text('Female') + ])), + ], + )); + }), + ); } @override diff --git a/lib/components/form/form_field/widgets/gf_multichoicechip.dart b/lib/components/form/form_field/widgets/gf_multichoicechip.dart new file mode 100644 index 00000000..0f0b8141 --- /dev/null +++ b/lib/components/form/form_field/widgets/gf_multichoicechip.dart @@ -0,0 +1,109 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; +import 'package:getwidget/getwidget.dart'; + +class GfMultiChoiceChip extends StatelessWidget { + GfMultiChoiceChip({ + Key? key, + this.onSelected, + required this.onSelectedindex, + this.margin, + this.padding, + this.borderColor, + this.headingText, + this.borderWidth, + required this.values, + this.preSelected, + }) : super(key: key){ + dataModel=GfMultiChipSelectData(values: values,preselected: preSelected); + + } + final Function(List)? onSelected; + final Function(List) onSelectedindex; + final EdgeInsets? margin; + final EdgeInsets? padding; + final Color? borderColor; + final String? headingText; + final double? borderWidth; + final List values; + final List? preSelected; + late final GfMultiChipSelectData dataModel; + + @override + Widget build(BuildContext context) { + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch(e){print('Exception at attaching to handler : $e');} + + return Container( + margin: margin ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + padding: padding ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) { + final List chips = dataModel.getlist(); + return + InputDecorator( + decoration: InputDecoration( + label: headingText != null + ? Text(headingText.toString()) + : null, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: borderColor ?? Colors.black, + width: borderWidth ?? 1.5) + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: borderColor ?? Colors.black, + width: borderWidth ?? 1.5) + ), + ), + child: + Wrap( + children: [ + for(int j = 0; j < chips.length; j++)...[ + Padding( + padding: const EdgeInsets.only(left: 10, right: 5), + child: ChoiceChip( + label: Text(chips[j].text), + labelStyle: const TextStyle( + color: Colors.black), + backgroundColor: Colors.green, + selectedColor: Colors.orange, + disabledColor: Colors.white, + selected: chips[j].selected, + onSelected: (bool value) { + dataModel.onSelected(index: j, + value: value); + if (onSelected != null) { + onSelected!( + dataModel.getlistselected()); + } + onSelectedindex(dataModel + .getlistselectedindx()); + } + ) + ) + ] + ], + ) + ); + }), + ); + } + } + + + diff --git a/lib/components/form/form_field/widgets/gf_multiselectcheckbox.dart b/lib/components/form/form_field/widgets/gf_multiselectcheckbox.dart new file mode 100644 index 00000000..c5e0d9ca --- /dev/null +++ b/lib/components/form/form_field/widgets/gf_multiselectcheckbox.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; +import 'package:getwidget/getwidget.dart'; + +class GfMultiCheckbox extends StatelessWidget { + GfMultiCheckbox({ + Key? key, + this.onSelected, + required this.onSelectedindex, + this.margin, + this.padding, + this.borderColor, + this.headingText, + this.borderWidth, + required this.values, + this.preSelected, + }) : super(key: key){ + dataModel=GfMultiCheckboxData(values: values,preselected: preSelected); + } + final Function(List)? onSelected; + final Function(List) onSelectedindex; + final EdgeInsets? margin; + final EdgeInsets? padding; + final Color? borderColor; + final String? headingText; + final double? borderWidth; + final List values; + final List? preSelected; + late final GfMultiCheckboxData dataModel; + + + @override + Widget build(BuildContext context) { + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch(e){print('Exception at attaching to handler : $e');} + return Container( + margin: margin ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + padding: padding ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) { + final List chips = dataModel.getlist(); + return + InputDecorator( + decoration: InputDecoration( + label: headingText != null + ? Text(headingText.toString()) + : null, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: borderColor ?? Colors.black, + width: borderWidth ?? 1.5) + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: borderColor ?? Colors.black, + width: borderWidth ?? 1.5) + ), + ), + child: + Column( + children: [ + for(int j = 0; j < chips.length; j++)...[ + Padding( + padding: const EdgeInsets.only(left: 10, right: 5), + child: CheckboxListTile( + title: Text(chips[j].text), + tileColor: Colors.white, + onChanged: (bool? value) { + dataModel.onSelected(index: j, + value: value ?? false); + if (onSelected != null) { + onSelected!(dataModel.getlistselected()); + } + onSelectedindex(dataModel.getlistselectedindx()); + }, + value: chips[j].selected, + ),) + ] + ], + ) + ); + }), + ); + } + } diff --git a/lib/components/form/form_field/widgets/gf_questionwidget.dart b/lib/components/form/form_field/widgets/gf_questionwidget.dart index 5d2f918b..63208aa3 100644 --- a/lib/components/form/form_field/widgets/gf_questionwidget.dart +++ b/lib/components/form/form_field/widgets/gf_questionwidget.dart @@ -1,17 +1,20 @@ import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_questionbuttonprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; import 'package:getwidget/getwidget.dart'; class GfFormQuestionWidget extends StatefulWidget { - const GfFormQuestionWidget( - {Key? key, - required this.onChanged, - required this.initialSelectedValue, - required this.question, - this.accepttext, - this.declinetext}) - : super(key: key); - final Function(String?) onChanged; - final String initialSelectedValue; + const GfFormQuestionWidget({ + Key? key, + required this.onChanged, + this.initialSelectedValue, + required this.question, + this.accepttext, + this.declinetext + }) : super(key: key); + final Function(String?) onChanged; + final String? initialSelectedValue; final String question; final String? accepttext; final String? declinetext; @@ -20,90 +23,109 @@ class GfFormQuestionWidget extends StatefulWidget { State createState() => _GfFormQuestionWidgetState(); } -class _GfFormQuestionWidgetState extends State - with AutomaticKeepAliveClientMixin { - String selectedValue = ''; +class _GfFormQuestionWidgetState extends State with AutomaticKeepAliveClientMixin{ + String selectedValue=''; + late final GfFormHandler gfFormHandler; + late final GfQuestionButtonData dataModel; @override - void initState() { - selectedValue = widget.initialSelectedValue; + void initState(){ + selectedValue=widget.initialSelectedValue??'Yes'; + dataModel=GfQuestionButtonData(selectedValue: selectedValue); super.initState(); } - @override Widget build(BuildContext context) { super.build(context); + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } return Container( - child: Card( - child: Container( - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), - child: Column(children: [ - const SizedBox( - height: 8, - ), - GFTypography( - text: widget.question, - type: GFTypographyType.typo6, - showDivider: false, - ), - const SizedBox( - height: 8, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - InkWell( - onTap: () { - setState(() { - selectedValue = widget.accepttext ?? 'Yes'; - widget.onChanged(selectedValue); - }); - }, - child: - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Radio( - value: widget.accepttext ?? 'Yes', - groupValue: selectedValue, - onChanged: (String? val) { - setState(() { - selectedValue = widget.accepttext ?? 'Yes'; - widget.onChanged(selectedValue); - }); - }, - ), - const SizedBox( - width: 8, - ), - Text(widget.accepttext ?? 'Yes') - ]), - ), - InkWell( - onTap: () { - setState(() { - selectedValue = widget.declinetext ?? 'No'; - widget.onChanged(selectedValue); - }); - }, - child: - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Radio( - value: widget.declinetext ?? 'No', - groupValue: selectedValue, - onChanged: (String? val) { - setState(() { - selectedValue = widget.declinetext ?? 'No'; - widget.onChanged(selectedValue); - }); - }, - ), - const SizedBox( - width: 8, + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) + { + selectedValue = dataModel.selectedValue; + return Card( + child: + Container( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), + child: + Column( + children: [ + const SizedBox(height: 8,), + GFTypography( + text: widget.question, + type: GFTypographyType.typo6, + showDivider: false, ), - Text(widget.declinetext ?? 'No') - ])), - ], - ) - ]), - ))); + const SizedBox(height: 8,), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + InkWell( + onTap: () { + selectedValue = widget.accepttext ?? 'Yes'; + widget.onChanged(selectedValue); + dataModel.setValue(selectedValue.toString()); + }, + child: + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Radio( + value: widget.accepttext ?? 'Yes', + groupValue: selectedValue, + onChanged: (String? val) { + setState(() { + selectedValue = widget.accepttext ?? 'Yes'; + widget.onChanged(selectedValue); + dataModel.setValue(selectedValue.toString()); + }); + }, + ), + const SizedBox(width: 8,), + Text(widget.accepttext ?? 'Yes') + ]),), + InkWell( + onTap: () { + setState(() { + selectedValue = widget.declinetext ?? 'No'; + widget.onChanged(selectedValue); + dataModel.setValue(selectedValue.toString()); + }); + }, + child: + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Radio( + value: widget.declinetext ?? 'No', + groupValue: selectedValue, + onChanged: (String? val) { + setState(() { + selectedValue = widget.declinetext ?? 'No'; + widget.onChanged(selectedValue); + dataModel.setValue(selectedValue.toString()); + }); + }, + ), + const SizedBox(width: 8,), + Text(widget.declinetext ?? 'No') + ])), + ], + ) + ]), + ) + ); + }) + ); } @override diff --git a/lib/components/form/form_field/widgets/gf_timepicker.dart b/lib/components/form/form_field/widgets/gf_timepicker.dart new file mode 100644 index 00000000..f465cee6 --- /dev/null +++ b/lib/components/form/form_field/widgets/gf_timepicker.dart @@ -0,0 +1,160 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_timepickerprovider.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; + +class GfTimePicker extends StatefulWidget { + const GfTimePicker({ + Key? key, + this.errorText, + this.cancelText, + this.confirmText, + this.helpText, + this.hourLabelText, + this.minuteLabelText, + this.defaultTime, + this.labelText, + this.borderColor, + this.headingText, + this.borderWidth, + this.buttonText, + this.buttonIcon, + this.margin, + this.padding + }) : super(key: key); + @override + State createState() => _GfTimePickerState(); + + final String? errorText; + final String? confirmText; + final String? cancelText; + final String? helpText; + final String? hourLabelText; + final String? minuteLabelText; + final TimeOfDay? defaultTime; + final Color? borderColor; + final String? headingText; + final String? labelText; + final double? borderWidth; + final String? buttonText; + final Icon? buttonIcon; + final EdgeInsets? margin; + final EdgeInsets? padding; +} + +class _GfTimePickerState extends State { + late final GfFormHandler gfFormHandler; + TimeOfDay selectedTime = TimeOfDay.now(); + late final GfTimePickerData dataModel; + + @override + void initState() { + selectedTime = widget.defaultTime ?? TimeOfDay.now(); + dataModel = GfTimePickerData(selectedTime: selectedTime); + + super.initState(); + } + + Future _selectDate(BuildContext context) async { + final TimeOfDay? picked = await showTimePicker( + context: context, + initialTime: selectedTime, + helpText: widget.helpText, + errorInvalidText: widget.errorText, + cancelText: widget.cancelText, + confirmText: widget.confirmText, + hourLabelText: widget.hourLabelText, + minuteLabelText: widget.minuteLabelText, + ); + if (picked != null && picked != selectedTime) { + dataModel.setTime(picked); + } + } + + + @override + Widget build(BuildContext context) { + try { + final GfFormHandler gfFormHandler = GfFormHandlerWidget + .of(context) + .gfFormHandler; + gfFormHandler.setModel(dataModel); + } + on Exception catch (e) { + print('Exception at attaching to handler : $e'); + } + return Container( + margin: widget.margin ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + padding: widget.padding ?? const EdgeInsets.symmetric(vertical: 2, + horizontal: 2), + child: + AnimatedBuilder( + animation: dataModel, + builder: (context, child) { + selectedTime = dataModel.getTime(); + return InputDecorator( + decoration: InputDecoration( + label: widget.headingText != null ? Text( + widget.headingText.toString()) : null, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: widget.borderColor ?? Colors.black, + width: widget.borderWidth ?? 1.5) + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(6), + borderSide: BorderSide( + color: widget.borderColor ?? Colors.black, + width: widget.borderWidth ?? 1.5) + ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Expanded(child: + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(widget.labelText ?? 'Selected Time', + style: const TextStyle( + color: Colors.black, fontWeight: FontWeight.w600),), + const SizedBox(height: 6,), + Text(selectedTime.format(context).toString(), + style: const TextStyle(color: Colors.black,),), + ], + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + constraints: const BoxConstraints(minWidth: 64), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(60), + color: Colors.grey, + ), + child: + InkWell( + onTap: () => _selectDate(context), + child: + Row( + children: [ + widget.buttonIcon ?? const Icon( + Icons.punch_clock_outlined, color: Colors.black, + size: 16,), + const SizedBox(width: 8,), + Text(widget.buttonText ?? 'Pick Time', + style: const TextStyle(color: Colors.black,),), + ], + ), + ), + ), + ], + ), + ); + }), + ); + } +} diff --git a/lib/components/form/form_field/widgets/providers/gf_datepickerprovider.dart b/lib/components/form/form_field/widgets/providers/gf_datepickerprovider.dart new file mode 100644 index 00000000..0936012b --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_datepickerprovider.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class GfDatePickerData extends ChangeNotifier{ + GfDatePickerData({required this.selectedDate}); + DateTime selectedDate; + + void setDate(DateTime x){ + selectedDate=x; + notifyListeners(); + } + DateTime getDate()=>selectedDate; +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_formdropdownprovider.dart b/lib/components/form/form_field/widgets/providers/gf_formdropdownprovider.dart new file mode 100644 index 00000000..f398fd74 --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_formdropdownprovider.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +class GfFormDropdownData extends ChangeNotifier{ + GfFormDropdownData({required this.selectedValue}); + + String selectedValue; + + String getValue()=>selectedValue; + + void setValue(String valuenew){ + selectedValue=valuenew; + notifyListeners(); + } +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_formfieldprovider.dart b/lib/components/form/form_field/widgets/providers/gf_formfieldprovider.dart new file mode 100644 index 00000000..3341d120 --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_formfieldprovider.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class GfFormFieldData extends ChangeNotifier{ + GfFormFieldData({required this.gfFormFieldController}); + TextEditingController gfFormFieldController; + + void setText(String x){ + gfFormFieldController.text=x; + notifyListeners(); + } + String getData()=>gfFormFieldController.value.text; +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart b/lib/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart new file mode 100644 index 00000000..fa9b2843 --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +class CheckboxData{ + CheckboxData({required this.text,required this.selected}); + String text; + bool selected; +} +class GfMultiCheckboxData extends ChangeNotifier{ + GfMultiCheckboxData({ + required this.values, + this.lableStyle, + this.selectedColor, + this.unselectedColor, + this.preselected}){ + if(preselected!=null) { + for (int xb = 0; xb < values.length; xb++) { + if(preselected!.contains(xb)) { + checkboxdata.add(CheckboxData(text: values[xb], selected: true )); + } + else{ + checkboxdata.add(CheckboxData(text: values[xb], selected: false )); + } + } + } + else { + checkboxdata = values.map((e) => CheckboxData(text: e, selected: false)).toList(); + } + } + final List values; + List checkboxdata=[]; + TextStyle? lableStyle; + Color? selectedColor; + Color? unselectedColor; + List? preselected; + + + List getlist()=>checkboxdata; + List getlistselected() { + final List checked=[]; + final List xt=checkboxdata.where((element) => element.selected).toList(); + for (var element in xt) { + checked.add(element.text); + } + return checked; + } + // list.asMap().forEach((index, item) + List getlistselectedindx() { + final List checked=[]; + checkboxdata.asMap().forEach((index, item){ + if(item.selected) { + checked.add(index); + } + }); + return checked; + } + + Future onSelected({required int index,required bool value}) async{ + checkboxdata[index].selected=value; + notifyListeners(); + } + } + + diff --git a/lib/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart b/lib/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart new file mode 100644 index 00000000..bb3d35a4 --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +class ChipData{ + ChipData({required this.text,required this.selected}); + String text; + bool selected; +} +class GfMultiChipSelectData extends ChangeNotifier{ + GfMultiChipSelectData({ + required this.values, + this.lableStyle, + this.selectedColor, + this.unselectedColor, + this.preselected}){ + if(preselected!=null) { + for (int xb = 0; xb < values.length; xb++) { + if(preselected!.contains(xb)) { + chipsdata.add(ChipData(text: values[xb], selected: true )); + } + else{ + chipsdata.add(ChipData(text: values[xb], selected: false )); + } + } + } + else { + chipsdata = values.map((e) => ChipData(text: e, selected: false)).toList(); + } + } + final List values; + List chipsdata=[]; + TextStyle? lableStyle; + Color? selectedColor; + Color? unselectedColor; + List? preselected; + + List getlist()=>chipsdata; + + Future onSelected({required int index,required bool value}) async{ + chipsdata[index].selected=value; + notifyListeners(); + } + + List getlistselected() { + final List checked=[]; + final List xt=chipsdata.where((element) => element.selected).toList(); + for (var element in xt) { + checked.add(element.text); + } + return checked; + } + // list.asMap().forEach((index, item) + List getlistselectedindx() { + final List checked=[]; + chipsdata.asMap().forEach((index, item){ + if(item.selected) { + checked.add(index); + } + }); + return checked; + } + +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_questionbuttonprovider.dart b/lib/components/form/form_field/widgets/providers/gf_questionbuttonprovider.dart new file mode 100644 index 00000000..9195f91c --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_questionbuttonprovider.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +class GfQuestionButtonData extends ChangeNotifier{ + GfQuestionButtonData({required this.selectedValue}); + + String selectedValue; + + String getValue()=>selectedValue; + + void setValue(String valuenew){ + selectedValue=valuenew; + notifyListeners(); + } +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_radioprovider.dart b/lib/components/form/form_field/widgets/providers/gf_radioprovider.dart new file mode 100644 index 00000000..7cba3f4c --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_radioprovider.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class GfGenderButtonData extends ChangeNotifier{ + GfGenderButtonData({required this.selectedValue}); + + String selectedValue; + + String getValue()=>selectedValue; + void setValue(String valuenew){ + selectedValue=valuenew; + notifyListeners(); + } +} \ No newline at end of file diff --git a/lib/components/form/form_field/widgets/providers/gf_timepickerprovider.dart b/lib/components/form/form_field/widgets/providers/gf_timepickerprovider.dart new file mode 100644 index 00000000..01c7e844 --- /dev/null +++ b/lib/components/form/form_field/widgets/providers/gf_timepickerprovider.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class GfTimePickerData extends ChangeNotifier{ + GfTimePickerData({required this.selectedTime}); + TimeOfDay selectedTime; + + void setTime(TimeOfDay x){ + selectedTime=x; + notifyListeners(); + } + TimeOfDay getTime()=>selectedTime; +} \ No newline at end of file diff --git a/lib/components/form/gf_form.dart b/lib/components/form/gf_form.dart index dd04caab..f7ec0fc6 100644 --- a/lib/components/form/gf_form.dart +++ b/lib/components/form/gf_form.dart @@ -1,24 +1,28 @@ import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/gf_formhandler_widget.dart'; +import 'package:getwidget/components/form/gf_form_provider.dart'; import 'package:getwidget/getwidget.dart'; class GfForm extends StatefulWidget { - const GfForm( - {Key? key, - this.height, - this.width, - this.radius, - this.formHeading, - this.formkey, - this.validatesuccess, - this.validatefailed, - this.formAlignment = CrossAxisAlignment.center, - required this.formfields, - this.customSubmitButton, - required this.defaultSubmitButtonEnabled, - this.defaultSubmitButtontext = 'SUBMIT', - this.formBorderColor = Colors.black, - this.headingtype = GFTypographyType.typo5}) - : super(key: key); + + const GfForm({ + Key? key, + required this.onFormSubmitted, + this.height, + this.width, + this.radius, + this.formHeading, + this.formkey, + this.validatesuccess, + this.validatefailed, + this.formAlignment=CrossAxisAlignment.center, + required this.formfields, + this.customSubmitButton, + required this.defaultSubmitButtonEnabled, + this.defaultSubmitButtontext='SUBMIT', + this.formBorderColor=Colors.black, + this.headingtype=GFTypographyType.typo5 + }) : super(key: key); final double? height; final double? width; @@ -27,101 +31,128 @@ class GfForm extends StatefulWidget { final GlobalKey? formkey; final Function? validatesuccess; final Function? validatefailed; + final Function(List) onFormSubmitted; final List formfields; final Widget? customSubmitButton; final bool defaultSubmitButtonEnabled; final String defaultSubmitButtontext; final CrossAxisAlignment formAlignment; - final Color formBorderColor; + final Color formBorderColor; final GFTypographyType headingtype; @override State createState() => _GfFormState(); + + } class _GfFormState extends State with AutomaticKeepAliveClientMixin { - late final GlobalKey formskey; + late final GlobalKey formskey; + late final GfFormHandler gfFormHandler; @override void initState() { - formskey = widget.formkey ?? GlobalKey(); - super.initState(); + formskey= widget.formkey ??GlobalKey(); + gfFormHandler=GfFormHandler(formsKey: formskey); + super.initState(); } @override Widget build(BuildContext context) { super.build(context); - return Container( - width: widget.width ?? MediaQuery.of(context).size.width, - // height: widget.height??MediaQuery.of(context).size.height, - constraints: BoxConstraints( - maxHeight: MediaQuery.of(context).size.height, - ), - padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), - decoration: BoxDecoration( - border: Border.all(color: widget.formBorderColor, width: 2.5), - borderRadius: BorderRadius.circular(widget.radius ?? 0), - ), - child: Column( - crossAxisAlignment: widget.formAlignment, - children: [ - widget.formHeading != null - ? Container( - padding: - const EdgeInsets.symmetric(vertical: 4, horizontal: 8), - child: GFTypography( - text: widget.formHeading.toString(), - type: widget.headingtype, - )) - : Container(), - widget.formHeading != null - ? const SizedBox( - height: 8, - ) - : Container(), - Expanded( - child: SingleChildScrollView( - child: Form( - key: formskey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ...widget.formfields, - ], + return + GfFormHandlerWidget( + gfFormHandler: gfFormHandler, + child: + Container( + width: widget.width ?? MediaQuery + .of(context) + .size + .width, + // height: widget.height??MediaQuery.of(context).size.height, + constraints: BoxConstraints(maxHeight: MediaQuery + .of(context) + .size + .height,), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), + decoration: BoxDecoration( + border: Border.all(color: widget.formBorderColor, width: 2.5), + borderRadius: BorderRadius.circular(widget.radius ?? 0), + ), + child: + Column( + crossAxisAlignment: widget.formAlignment, + children: [ + widget.formHeading != null ? + Container( + padding: const EdgeInsets.symmetric( + vertical: 4, horizontal: 8), + child: + + GFTypography( + text: widget.formHeading.toString(), + type: widget.headingtype, + )): + Container(), + widget.formHeading != null ? + const SizedBox(height: 8,) : Container(), + AnimatedBuilder( + animation: gfFormHandler, + builder: (context,child)=> Expanded( + child: + SingleChildScrollView( + child: + Form( + key: formskey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ...widget.formfields, + ], + ), + ), + ), + ), ), - ), - ), - ), - (!widget.defaultSubmitButtonEnabled && - widget.customSubmitButton != null) - ? (widget.customSubmitButton ?? Container()) - : Container(), - (widget.defaultSubmitButtonEnabled) - ? GFButton( - text: widget.defaultSubmitButtontext, - onPressed: () { - if (formskey.currentState!.validate()) { - if (widget.validatesuccess != null) { - widget.validatesuccess!(); - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Validation Success')), - ); - } - } else { - if (widget.validatefailed != null) { - widget.validatefailed!(); - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Validation Failed')), - ); - } - } - }) - : Container(), - ], - )); - } + (!widget.defaultSubmitButtonEnabled && + widget.customSubmitButton != null) ? (widget + .customSubmitButton ?? Container()) : Container(), + (widget.defaultSubmitButtonEnabled) ? + GFButton( + text: widget.defaultSubmitButtontext, + onPressed: () async { + if (formskey.currentState!.validate()) + { + if (widget.validatesuccess != null) { + final List formValues= await gfFormHandler.getFormValues(); + widget.onFormSubmitted(formValues); + widget.validatesuccess!(); + } + else { + final List formValues= await gfFormHandler.getFormValues(); + widget.onFormSubmitted(formValues); + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Validation Success')),); + } + } + else { + if (widget.validatefailed != null) { + widget.validatefailed!(); + } + else { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Validation Failed')), + ); + } + } + }) + : Container(), + ], + ) + ) + ); +} @override bool get wantKeepAlive => true; -} + + } + + diff --git a/lib/components/form/gf_form_provider.dart b/lib/components/form/gf_form_provider.dart new file mode 100644 index 00000000..09d02c2a --- /dev/null +++ b/lib/components/form/gf_form_provider.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_datepickerprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_formdropdownprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_formfieldprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_questionbuttonprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_radioprovider.dart'; +import 'package:getwidget/components/form/form_field/widgets/providers/gf_timepickerprovider.dart'; + +class GfFormHandler extends ChangeNotifier{ + GfFormHandler({required this.formsKey,}); + final GlobalKey formsKey; + List models=[]; + void getModels()=>models; + + void setModel(ChangeNotifier modelx){ + print('Adding Model ::${modelx.runtimeType}'); + models.add(modelx); + print('Model List ${models.length}'); + } + + Future validateForm() async{ + if (formsKey.currentState!.validate()){ + return true; + } + else{ + return false; + } + } + + Future> getFormValues() async{ + final List values=[]; + if (formsKey.currentState!.validate()){ + for(ChangeNotifier xt in models){ + switch(xt.runtimeType){ + case GfFormFieldData: + final GfFormFieldData jx=xt as GfFormFieldData; + values.add(jx.getData()); + break; + case GfFormDropdownData: + final GfFormDropdownData jx=xt as GfFormDropdownData; + values.add(jx.getValue()); + break; + case GfGenderButtonData: + final GfGenderButtonData jx=xt as GfGenderButtonData; + values.add(jx.getValue()); + break; + case GfQuestionButtonData: + final GfQuestionButtonData jx=xt as GfQuestionButtonData; + values.add(jx.getValue()); + break; + case GfMultiCheckboxData: + final GfMultiCheckboxData jx=xt as GfMultiCheckboxData; + values.add(jx.getlistselectedindx()); + break; + case GfMultiChipSelectData: + final GfMultiChipSelectData jx=xt as GfMultiChipSelectData; + values.add(jx.getlistselectedindx()); + break; + case GfDatePickerData: + final GfDatePickerData jx=xt as GfDatePickerData; + values.add(jx.getDate()); + break; + case GfTimePickerData: + final GfTimePickerData jx=xt as GfTimePickerData; + values.add(jx.getTime()); + break; + } + } + } + return values; + } +} \ No newline at end of file diff --git a/lib/components/text_field/gf_text_field.dart b/lib/components/text_field/gf_text_field.dart index d9b7715f..6d282bc7 100644 --- a/lib/components/text_field/gf_text_field.dart +++ b/lib/components/text_field/gf_text_field.dart @@ -53,7 +53,7 @@ class GFTextField extends FormField { this.buildCounter, this.scrollPhysics, this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled}) + this.autoValidateMode = AutovalidateMode.disabled}) : super( key: key, builder: (FormFieldState field) => _GfTextFieldState( @@ -71,7 +71,7 @@ class GFTextField extends FormField { validator: validatornew, color: color, borderradius: borderradius, - autovalidateMode: autovalidateMode, + autoValidateMode: autoValidateMode, textAlign: textAlign ?? TextAlign.start, textAlignVertical: textAlignVertical, textDirection: textDirection, @@ -163,8 +163,7 @@ class GFTextField extends FormField { final InputCounterWidgetBuilder? buildCounter; final ScrollPhysics? scrollPhysics; final Iterable? autofillHints; - @override - final AutovalidateMode autovalidateMode; + final AutovalidateMode autoValidateMode; } class _GfTextFieldState extends StatefulWidget { @@ -219,7 +218,7 @@ class _GfTextFieldState extends StatefulWidget { this.buildCounter, this.scrollPhysics, this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled}); + this.autoValidateMode = AutovalidateMode.disabled}); final FormFieldState state; final TextEditingController? controller; @@ -272,7 +271,7 @@ class _GfTextFieldState extends StatefulWidget { final InputCounterWidgetBuilder? buildCounter; final ScrollPhysics? scrollPhysics; final Iterable? autofillHints; - final AutovalidateMode autovalidateMode; + final AutovalidateMode autoValidateMode; @override State<_GfTextFieldState> createState() => _GfTextFieldStateState(); diff --git a/lib/components/text_field/gf_text_field_pill.dart b/lib/components/text_field/gf_text_field_pill.dart index a5c6c53c..3c7469e4 100644 --- a/lib/components/text_field/gf_text_field_pill.dart +++ b/lib/components/text_field/gf_text_field_pill.dart @@ -67,7 +67,7 @@ class GFTextFieldPill extends StatefulWidget { this.buildCounter, this.scrollPhysics, this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled}) + this.autoValidateMode = AutovalidateMode.disabled}) : super(key: key); final Color normalbordercolor; @@ -131,7 +131,7 @@ class GFTextFieldPill extends StatefulWidget { final InputCounterWidgetBuilder? buildCounter; final ScrollPhysics? scrollPhysics; final Iterable? autofillHints; - final AutovalidateMode autovalidateMode; + final AutovalidateMode autoValidateMode; @override _GFTextFieldPillState createState() => _GFTextFieldPillState(); @@ -244,5 +244,5 @@ class _GFTextFieldPillState extends State { buildCounter: widget.buildCounter, scrollPhysics: widget.scrollPhysics, autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode)); + autoValidateMode: widget.autoValidateMode)); } diff --git a/lib/components/text_field/gf_text_field_rounded.dart b/lib/components/text_field/gf_text_field_rounded.dart index ac8e8173..c7df1c7e 100644 --- a/lib/components/text_field/gf_text_field_rounded.dart +++ b/lib/components/text_field/gf_text_field_rounded.dart @@ -68,7 +68,7 @@ class GFTextFieldRounded extends StatefulWidget { this.buildCounter, this.scrollPhysics, this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled}) + this.autoValidateMode = AutovalidateMode.disabled}) : super(key: key); final Color normalbordercolor; @@ -133,7 +133,7 @@ class GFTextFieldRounded extends StatefulWidget { final InputCounterWidgetBuilder? buildCounter; final ScrollPhysics? scrollPhysics; final Iterable? autofillHints; - final AutovalidateMode autovalidateMode; + final AutovalidateMode autoValidateMode; @override _GFTextFieldRoundedState createState() => _GFTextFieldRoundedState(); @@ -243,5 +243,5 @@ class _GFTextFieldRoundedState extends State { buildCounter: widget.buildCounter, scrollPhysics: widget.scrollPhysics, autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode)); + autoValidateMode: widget.autoValidateMode)); } diff --git a/lib/components/text_field/gf_text_field_squared.dart b/lib/components/text_field/gf_text_field_squared.dart index e7d150d4..8a3c3e3a 100644 --- a/lib/components/text_field/gf_text_field_squared.dart +++ b/lib/components/text_field/gf_text_field_squared.dart @@ -67,7 +67,7 @@ class GFTextFieldSquared extends StatefulWidget { this.buildCounter, this.scrollPhysics, this.autofillHints, - this.autovalidateMode = AutovalidateMode.disabled}) + this.autoValidateMode = AutovalidateMode.disabled}) : super(key: key); final Color normalbordercolor; @@ -131,7 +131,7 @@ class GFTextFieldSquared extends StatefulWidget { final InputCounterWidgetBuilder? buildCounter; final ScrollPhysics? scrollPhysics; final Iterable? autofillHints; - final AutovalidateMode autovalidateMode; + final AutovalidateMode autoValidateMode; @override _GFTextFieldSquaredState createState() => _GFTextFieldSquaredState(); @@ -241,5 +241,5 @@ class _GFTextFieldSquaredState extends State { buildCounter: widget.buildCounter, scrollPhysics: widget.scrollPhysics, autofillHints: widget.autofillHints, - autovalidateMode: widget.autovalidateMode)); + autoValidateMode: widget.autoValidateMode)); } diff --git a/lib/getwidget.dart b/lib/getwidget.dart index 814145ae..79d99c1f 100644 --- a/lib/getwidget.dart +++ b/lib/getwidget.dart @@ -25,8 +25,17 @@ export 'package:getwidget/components/drawer/gf_drawer_header.dart'; export 'package:getwidget/components/dropdown/gf_dropdown.dart'; export 'package:getwidget/components/dropdown/gf_multiselect.dart'; export 'package:getwidget/components/floating_widget/gf_floating_widget.dart'; -export 'package:getwidget/components/form/form_field/gf_form_field.dart'; export 'package:getwidget/components/form/form_field/validators/validators.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_datepicker.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_form_field.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_formdropdown.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_formradiobutton.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_multichoicechip.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_multiselectcheckbox.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_questionwidget.dart'; +export 'package:getwidget/components/form/form_field/widgets/gf_timepicker.dart'; +export 'package:getwidget/components/form/form_field/widgets/providers/gf_multicheckboxselectionprovider.dart'; +export 'package:getwidget/components/form/form_field/widgets/providers/gf_multichipselectionprovider.dart'; export 'package:getwidget/components/form/gf_form.dart'; export 'package:getwidget/components/image/gf_image_overlay.dart'; export 'package:getwidget/components/intro_screen/gf_intro_screen.dart'; diff --git a/lib/types/gf_form_field_type.dart b/lib/types/gf_form_field_type.dart index fd677412..da6f98e3 100644 --- a/lib/types/gf_form_field_type.dart +++ b/lib/types/gf_form_field_type.dart @@ -3,9 +3,6 @@ enum GfFormFieldType { password, email, phone, - country, - gender, - question, text, number }