Problem with Focus Shifting in TV Text Fields

I’m having trouble with the text fields on my TV. When I try to enter my email, password, and then click the button, the focus jumps around unexpectedly. It seems like the keyboard is automatically appearing and focusing on the button when I press keys. I’ve tried everything I can think of, but the focus is still not working correctly

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';

import 'package:get/get.dart';

import 'package:searchrtv/widgets/customTextFormField.dart';

import 'package:searchrtv/widgets/custombtn.dart';



class Login extends StatelessWidget {

  Login({super.key});



  final TextEditingController emailController = TextEditingController();

  final Rx<bool> isObscure = true.obs;

  final loginFormKey = GlobalKey<FormState>();

  final TextEditingController passwordController = TextEditingController();

  FocusNode? emailFocusNode;

  FocusNode? passwordFocusNode;

  FocusNode? btnFocusNode;



  @override

  Widget build(BuildContext context) {

    emailFocusNode = FocusNode(

      onKey: (node, event) {

        node.unfocus();

        if (event.isKeyPressed(LogicalKeyboardKey.arrowUp)) {

          emailFocusNode!.unfocus();

          btnFocusNode!.requestFocus();  

          return KeyEventResult.handled;    

        } else if (event.isKeyPressed(LogicalKeyboardKey.arrowDown)) {

          emailFocusNode!.unfocus();

          passwordFocusNode!.requestFocus();

          return KeyEventResult.handled;    

        }

        return KeyEventResult.ignored;

      },

    );



    passwordFocusNode = FocusNode(

      onKey: (node, event) {

        if (event.isKeyPressed(LogicalKeyboardKey.arrowUp)) {

          passwordFocusNode!.unfocus();

          emailFocusNode!.requestFocus();  

          return KeyEventResult.handled;    

        } else if (event.isKeyPressed(LogicalKeyboardKey.arrowDown)) {

          passwordFocusNode!.unfocus();

          btnFocusNode!.requestFocus();

          return KeyEventResult.handled;    

        }

        return KeyEventResult.ignored;

      },

    );



    btnFocusNode = FocusNode(

      onKey: (node, event) {

        if (event.isKeyPressed(LogicalKeyboardKey.arrowUp)) {

          btnFocusNode!.unfocus();

          passwordFocusNode!.requestFocus();  

          return KeyEventResult.handled;    

        } else if (event.isKeyPressed(LogicalKeyboardKey.arrowDown)) {

          btnFocusNode!.unfocus();

          emailFocusNode!.requestFocus();

          return KeyEventResult.handled;    

        }

        return KeyEventResult.ignored;

      },

    );



    final size = MediaQuery.of(context).size;

    return Scaffold(

      body: Container(

        height: size.height * 1,

        width: size.width * 1,

        child: Row(

          mainAxisAlignment: MainAxisAlignment.center,

          crossAxisAlignment: CrossAxisAlignment.center,

          children: [

            Container(

              padding: const EdgeInsets.symmetric(horizontal: 20),

              width: size.width * 0.4,

              height: size.height * 0.5,

              color: Colors.grey[900],

              child: Form(

                key: loginFormKey,

                child: Column(

                  crossAxisAlignment: CrossAxisAlignment.center,

                  children: [

                    const SizedBox(height: 10),

                    const Center(

                      child: Icon(

                        Icons.remove_red_eye_rounded,

                        size: 64,

                      ),

                    ),

                    const Text(

                      'Searchr.Tv',

                      style: TextStyle(

                        fontSize: 25.0,

                        fontWeight: FontWeight.w700,

                      ),

                    ),

                    const SizedBox(height: 10),

                    customTextFormField(

                      focusNode: emailFocusNode,

                      labelText: 'Email',

                      hintText: 'Email Address',

                      prefixIconData: Icons.email,

                      keyboardType: TextInputType.emailAddress,

                      textInputAction: TextInputAction.next,

                      validator: (value) {

                        return null;

                      },

                    ),

                    const SizedBox(height: 10.0),

                    customTextFormField(

                      focusNode: passwordFocusNode,

                      labelText: 'Password',

                      hintText: "****",

                      prefixIconData: Icons.vpn_key_rounded,

                      textInputAction: TextInputAction.next,

                      validator: (value) {

                        return null;

                      },

                    ),

                    const SizedBox(height: 6.0),

                    CustomButton(

                      focusNode: btnFocusNode,

                      text: 'Login',

                      onPressed: () async {

                      },

                      hasInfiniteWidth: true,

                    ),

                  ],

                ),

              ),

            ),           

            const Divider(

              height: 200,

              color: Colors.black,

            ),

            const SizedBox(width: 10),

            Container(

              width: size.width * 0.4,

              height: size.height * 0.4,

              color: Colors.green,

              child: const Text("data"),

            ),

          ],

        ),

      ),

    );

  }

}

New contributor

Najeeb Ullah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

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