From f5b4d303f2145a216498a391d4cfce2dddab6382 Mon Sep 17 00:00:00 2001 From: Nandan Wewhare Date: Fri, 25 Dec 2020 13:12:20 +0530 Subject: [PATCH] Added a key to the form. Adding a key to the form will help in using validators in case the user decides to proceed by leaving the field(s) empty. --- lib/credit_card_form.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/credit_card_form.dart b/lib/credit_card_form.dart index 63ec643..c60896a 100755 --- a/lib/credit_card_form.dart +++ b/lib/credit_card_form.dart @@ -14,6 +14,7 @@ class CreditCardForm extends StatefulWidget { this.themeColor, this.textColor = Colors.black, this.cursorColor, + this.formKey }) : super(key: key); final String cardNumber; @@ -24,6 +25,7 @@ class CreditCardForm extends StatefulWidget { final Color themeColor; final Color textColor; final Color cursorColor; + final var formKey = GlobalKey(); @override _CreditCardFormState createState() => _CreditCardFormState(); @@ -65,7 +67,8 @@ class _CreditCardFormState extends State { creditCardModel = CreditCardModel( cardNumber, expiryDate, cardHolderName, cvvCode, isCvvFocused); } - + + get getFormKey => formKey; @override void initState() { super.initState(); @@ -123,6 +126,7 @@ class _CreditCardFormState extends State { primaryColorDark: themeColor, ), child: Form( + key: formKey, child: Column( children: [ Container(