BaseMaterialNumberValueAccessor<T> constructor

BaseMaterialNumberValueAccessor<T>(
  1. MaterialInputComponent input,
  2. NgControl control,
  3. bool changeUpdate,
  4. bool keypressUpdate,
  5. bool blurFormat, [
  6. NumberFormat? _numberFormat,
])

Implementation

BaseMaterialNumberValueAccessor(
    MaterialInputComponent input,
    NgControl control,
    bool changeUpdate,
    bool keypressUpdate,
    bool blurFormat,
    [this._numberFormat])
    : super(input, control) {
  // The type values set via number directives are invalid values for the
  // 'type' attribute on the underlying 'input' element, so set the value
  // back to 'text' instead.
  input.type = 'text';

  assert(!(changeUpdate && keypressUpdate),
      'Cannot update both on keypress and change.');
  if (changeUpdate) {
    _updateStream = input.onChange;
  } else if (keypressUpdate) {
    _updateStream = input.onKeypress;
  } else {
    _updateStream = input.onBlur;
  }
  if (blurFormat) {
    disposer.addStreamSubscription(input.onBlur.listen((_) {
      //if (input == null) return; // Input is no longer valid
      final parsedNumber = parseNumber(input.inputText);
      // If the value parses, it's a number so format it as such.
      if (parsedNumber != null) {
        super.writeValue(parsedNumber);
      }
    }));
  }
}