bhrott / flutter-masked-text

A masked text for Flutter.

Home Page:https://pub.dartlang.org/packages/flutter_masked_text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warning on change value

gilvangobbato opened this issue · comments

I'm getting this warnings on change value

W/IInputConnectionWrapper( 9729): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 9729): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 9729): getTextAfterCursor on inactive InputConnection

This is my code

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

class InputRealField extends StatelessWidget {
  final IconData icon;
  final String hint;
  final String label;
  final bool obscure;
  final bool enable;
  final Stream<double> stream;
  final Function(double) onChanged;
  final dynamic initialData;
  final MoneyMaskedTextController _controller = new MoneyMaskedTextController(
      decimalSeparator: ',',
      thousandSeparator: '.',
      leftSymbol: "R\$ ",
      precision: 2);
  final bool alwaysCursorInEnd;

  InputRealField(
      {Key key,
      this.icon,
      this.hint,
      this.obscure = false,
      this.enable = true,
      this.stream,
      this.label,
      this.onChanged,
      this.initialData,
      this.alwaysCursorInEnd = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    _controller.addListener(_onChangeValue);
    return StreamBuilder(
        stream: this.stream,
        initialData: initialData,
        builder: (context, snapshot) {
          _controller.updateValue(snapshot.data);
          if (alwaysCursorInEnd) {
            _controller.selection = new TextSelection(
                baseOffset: _controller.value.text.length,
                extentOffset: _controller.value.text.length);
          }
          return TextField(
            enabled: this.enable,
            enableInteractiveSelection: false,
            autofocus: false,
            keyboardType: TextInputType.number,
            decoration: InputDecoration(
                labelText: this.label,
                hintText: this.hint,
                errorText: snapshot.hasError ? snapshot.error : null),
            obscureText: this.obscure,
            controller: _controller,
          );
        });
  }

  void _onChangeValue() {
    onChanged(_controller.numberValue);
  }
}

It also happens to me and nothing is put in TextField.
I also receive other error:

W/IInputConnectionWrapper( 3560): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 3560): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 3560): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 3560): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 3560): endBatchEdit on inactive InputConnection

I have found the problem, In my case I define more time the controller, In your case I think that is because you set the controller value in a stream builder.