Flutter_Pinput icon indicating copy to clipboard operation
Flutter_Pinput copied to clipboard

Duplicate keys found [Ios] [Android]

Open apiorno opened this issue 2 years ago • 2 comments

Duplicate keys found is thrown while typing quickly in both Android and Ios emulators using this code:

Pinput(
          length: 4,
          pinAnimationType: PinAnimationType.none,
          controller: controller,
          focusNode: focusNode,
          showCursor: false,
          autofocus: true,
          inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
          defaultPinTheme: PinTheme(
            width: 30,
            height: 30,
            decoration: BoxDecoration(),
          ),
          preFilledWidget: _preFilledCircle(),
          obscureText: true,
          obscuringWidget: _filledCircle(),
          onCompleted: (text) {// Do stuff}
        )

apiorno avatar Apr 22 '22 18:04 apiorno

Hi @apiorno, unfortunately, I'm not able to reproduce the issue, could you provide more info?

Tkko avatar May 13 '22 06:05 Tkko

Hi, this isolated code example reproduces the problem:


  @override
  Widget build(BuildContext context) {
    var controller = TextEditingController();
    return Scaffold(
      body:
          Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [
        Padding(
            padding: const EdgeInsets.symmetric(horizontal: 125.0, vertical: 12.0),
            child: Pinput(
              length: 6,
              pinAnimationType: PinAnimationType.none,
              controller: controller,
              focusNode: FocusNode(),
              showCursor: false,
              autofocus: true,
              inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
              defaultPinTheme: const PinTheme(
                width: 30,
                height: 30,
                decoration: BoxDecoration(),
              ),
              preFilledWidget: Container(
                width: 13.0,
                height: 13.0,
                decoration: BoxDecoration(
                  color: Colors.transparent,
                  shape: BoxShape.circle,
                  border: Border.all(
                    color: Colors.black,
                    width: 1,
                  ),
                ),
              ),
              obscureText: true,
              obscuringWidget: Container(
                width: 13.0,
                height: 13.0,
                decoration: BoxDecoration(
                  color: Colors.black,
                  shape: BoxShape.circle,
                  border: Border.all(
                    color: Colors.black,
                    width: 1,
                  ),
                ),
              ),
              onCompleted: (text) => controller.clear(),
            ))
      ]),
    );
  }

apiorno avatar May 24 '22 22:05 apiorno

I'm sorry for the late reply, I'm pretty sure you solved the issue on your own, one thing to keep in mind, you should create a controller outside of build method, in the statefullWidget, and dispose it.

  final pinController = TextEditingController();

  @override
  void dispose() {
    pinController.dispose();
    super.dispose();
  }

Closing this issue, feel free to reopen it if you need to.

Tkko avatar Oct 03 '22 17:10 Tkko