How Can I Disabled my Keyboard only not the TextFormField in flutter

40 Views Asked by At

I want to Disable the Keyboard Because I am getting input from RFID Device. But I dont want to Disabled TextFormField. So Is there anyway to that work ?? Basically the TextFormField getting value from RFID so it is it necessary to enable TextFormField for getting input. IF not then what is an another way to perform it ?? And if yes, then how can I enabled TextFormField only but not the Keyboard.

import 'package:flutter/material.dart';
import 'package:pos/constant/use_colors.dart';

class CheckBalance extends StatefulWidget {
  const CheckBalance({Key? key}) : super(key: key);

  @override
  State<CheckBalance> createState() => _CheckBalanceState();
}

class _CheckBalanceState extends State<CheckBalance> {
  late TextEditingController rfidController;
  late FocusNode rfidFocusNode;

  @override
  void initState() {
    super.initState();
    rfidController = TextEditingController();
    rfidFocusNode = FocusNode();
    // Set focus to RFID field when the screen is first displayed
    WidgetsBinding.instance.addPostFrameCallback((_) => rfidFocusNode.requestFocus());
  }

  @override
  void dispose() {
    // Clean up the controller and focus node when the widget is disposed
    rfidController.dispose();
    rfidFocusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: UseColors.textColor,
        title: const Text(
          'Check Balance',
          style: TextStyle(color: UseColors.baseColor),
        ),
    leading: IconButton(
      icon: const Icon(
        Icons.arrow_back_ios_new,
        color: UseColors.baseColor,
      ),
      onPressed: () {
        Navigator.of(context).pop();
      },
    ),
  ),
  body: Padding(
    padding: const EdgeInsets.all(20.0),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text(
          'RFID Data:',
          style: TextStyle(
            fontSize: 20.0,
            fontWeight: FontWeight.bold,
          ),
        ),
        const SizedBox(height: 10.0),
        TextFormField(
          focusNode: rfidFocusNode,
          controller: rfidController,
          obscureText: true,
          decoration: const InputDecoration(
            border: OutlineInputBorder(),
            enabledBorder: OutlineInputBorder(
                borderSide: BorderSide(color: UseColors.textColor)),
            focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(color: UseColors.textColor)),
            hintText: 'Place RFID here',
            hintStyle: TextStyle(
              fontStyle: FontStyle.normal,
            ),
          ),
        ),
      ],
    ),
  ),
);
0

There are 0 best solutions below