flutter how can create the common textformfield to validate different input text(Multiple widgets used the same GlobalKey.)

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:test/config/app_theme.dart';

class LoginInfoFormField extends StatelessWidget {
  const LoginInfoFormField(
      {required this.controller,
      required this.hintText,
      required this.labelText,
      this.validator,
      this.onChanged,
      this.inputFormatters,
      this.focusNode,
      this.enableSuggestions = true,
      this.autocorrect = true,
      this.obscureText = false,
      this.suffixIcon,
      super.key});
  final TextEditingController? controller;
  final String? Function(String?)? validator;
  final void Function(String)? onChanged;
  final List<TextInputFormatter>? inputFormatters;
  final FocusNode? focusNode;
  final String labelText;
  final String hintText;
  final bool enableSuggestions;
  final bool autocorrect;
  final bool obscureText;
  final Widget? suffixIcon;

  @override
  Widget build(BuildContext context) {
    print('Key: ${key.toString()}');
    return Theme(
      data: ThemeData(),
      child: TextFormField(
        key: key,
        controller: controller,
        focusNode: focusNode,
        obscureText: obscureText,
        validator: validator,
        onChanged: onChanged,
        enableSuggestions: enableSuggestions,
        autocorrect: autocorrect,
        inputFormatters: inputFormatters,
        style: TextStyle(color: Theme.of(context).colorScheme.secondaryContainer),
        decoration: InputDecoration(
            enabledBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: AppTheme.grayColor)),
            labelText: tr(labelText),
            labelStyle: TextStyle(
                fontSize: context.locale == const Locale('my', 'MM') ? 13 : 16,
                color: Theme.of(context).colorScheme.secondaryContainer),
            hintText: tr(hintText),
            hintStyle: TextStyle(
              fontSize: context.locale == const Locale('my', 'MM') ? 15 : 16,
            ),
            suffixIcon: suffixIcon),
      ),
    );
  }
}

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:test/widgets/formfield/login_info_form_field.dart';

class Login extends StatefulWidget {
  const Login({super.key});

  @override
  State<Login> createState() => _LoginState();
}

class _LoginState extends State<Login> {
  
  final GlobalKey<FormFieldState> _userNameKey = GlobalKey<FormFieldState>();
  final GlobalKey<FormFieldState> _emailKey = GlobalKey<FormFieldState>();


  TextEditingController userNameController = TextEditingController();
  TextEditingController emailController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    
    return Column(
                          children: [
                            Padding(
                              padding: const EdgeInsets.fromLTRB(32, 0, 32, 10),
                                child: LoginInfoFormField(
                                 key: _userNameKey,
                                  controller: userNameController,
                                  validator: (value) {
                                    if ((value!).trim().isEmpty) {
                                      return tr('userNameRequired');
                                    }
                                    return null;
                                  },
                                  onChanged: (val) =>
                                      _userNameKey.currentState!.validate(),
                                  labelText: 'UserName',
                                  hintText: 'UserName',
                                ),
                            ),
                            Padding(
                                padding: const EdgeInsets.fromLTRB(
                                            32, 0, 32, 10),
                                  child: LoginInfoFormField(
                                    key: _emailKey,
                                    validator: (value) {
                                      if ((value!).trim().isEmpty) {
                                        return tr('emailIsRequired');
                                      }
                                      return null;
                                    },
                                    onChanged: (val) {
                                      _emailKey.currentState!.validate();
                                    },
                                    controller: emailController,
                                    inputFormatters: [
                                      FilteringTextInputFormatter
                                          .singleLineFormatter
                                    ],
                                    labelText: 'EnterYourEmail',
                                    hintText: 'EnterYourEmail',
                                  ),
                              )
                          ]
                        );
  }
}

I am facing the error and don’t work validation.

Multiple widgets used the same GlobalKey.

The key [LabeledGlobalKey<FormFieldState<dynamic>>#c646e] was used by multiple widgets. The parents of those widgets were: – DefaultSelectionStyle – _FormScope A GlobalKey can only be specified on one widget at a time in the widget tree.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật