Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

When setting both, onTextChanged and Controller the onTextChanged callback is called twice #66

Open
carlos-enzo opened this issue Mar 23, 2022 · 0 comments

Comments

@carlos-enzo
Copy link

carlos-enzo commented Mar 23, 2022

Describe the bug
When we set a callback for onTextChanged and a controller the callback is called twice.

To Reproduce
example code:

import 'package:flutter/material.dart';
import 'package:pin_code_text_field/pin_code_text_field.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _controller = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Connectivity example app'),
      ),
      body: Center(
        child: PinCodeTextField(
          onTextChanged: onTextChanged, //widget.onTextChanged,
          controller: _controller,
          pinBoxColor: Colors.transparent,
          pinBoxBorderWidth: 1.0,
          pinBoxOuterPadding: const EdgeInsets.all(2.5),
          pinBoxWidth: 40,
          pinBoxHeight: 40,
          pinBoxRadius: 2.0,
          focusNode: FocusNode(),
        ),
      ),
    );
  }

  void onTextChanged(String value) {
    print('value: $value');
  }
}

Expected behavior
We can set the controller and the callback and when the text changes, the callback is only called once.

** flutter doctor **
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.1 21C52 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.65.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant