RomanBase / code_field

Widget providing input code field to insert pin, sms and other auth codes.
https://pub.dev/packages/code_field
MIT License
5 stars 8 forks source link

is there any onChange alternative? #3

Closed cviali closed 4 years ago

cviali commented 4 years ago

I've been using this lib and the only thing I need right now is a way to track if the value changed. Is there any onChange equivalent in this lib?

RomanBase commented 4 years ago

InputCodeControl is ChangeNotifier so you can simply listen change notifications.

InputCodeControl.addListener((){ ... })

cviali commented 4 years ago

Thanks for the help @RomanBase

ricbermo commented 3 years ago

hello @RomanBase how you doing? I'm using your package but I'm such a beginner with Flutter that I have no idea of how to implement this. I'm seeing that the InputCodeControl has a value getter, a done and a addListener methods but IDK how to use them :( Any help would be rly appreciated.

This is my code.

Thanks in advance.

class CodeInput extends StatelessWidget {
  final codeControl = InputCodeControl(
    inputRegex: '^[0-9]',
  );

  @override
  Widget build(BuildContext context) {
    final h5 = Theme.of(context).textTheme.headline5;
    final textTheme = GoogleFonts.poppins(
      textStyle: h5.copyWith(
        color: kTextColor,
      ),
    );

    return InputCodeField(
      autofocus: true,
      control: codeControl,
      count: 4,
      spacing: 16,
      decoration: InputCodeDecoration(
        width: 74,
        height: 48,
        box: BoxDecoration(
          color: Colors.black.withOpacity(0.04),
          border: const Border(
            bottom: BorderSide(color: Colors.grey),
          ),
        ),
        focusedBox: BoxDecoration(
          color: Colors.black.withOpacity(0.04),
          border: const Border(
            bottom: BorderSide(color: kPrimaryColor),
          ),
        ),
        textStyle: textTheme,
      ),
    );
  }
}
ricbermo commented 3 years ago

I solved it like this

  final codeControl = InputCodeControl(
    inputRegex: '^[0-9]',
  );

  final VoidCallback onDone;
  CodeInput({this.onDone}) {
    codeControl.done(onDone);
  }