本文介绍了错误:无法将参数类型'(int)→动态'分配给参数类型'(String)→空'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些字段发布 String int String 字段正常工作,并且在数据库中获取了这些值,在 int 类型字段中,我收到此错误消息.

I have some fields which post String and int, the String fields are working properly and I am getting these values at the db, the at the int type fields I'm getting this error message.

我正在使用 bloc 发布到Firebase数据库.

I'm using bloc to post to a firebase db.

这是它的外观.

Widget build(BuildContext context) {
    final trackerBloc = Provider.of<TrackerBloc>(context);
    String docId = DateTime.now().millisecondsSinceEpoch.toString();

    return Scaffold(
      appBar: AppBar(
        title: Text('Create'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.all(20.0),
          child: Column(
            children: <Widget>[
              Padding(
                padding: EdgeInsets.all(20.0),
                child: Text(
                  'Create',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              _buildNumberField(trackerBloc),
 ...

textField 本身看起来像这样:

  Widget _buildNumberField(TrackerBloc trackerBloc) {
    return StreamBuilder<Object>(
      stream: trackerBloc.numberStream,
      builder: (context, snapshot) {
        return TextField(
          controller: _controllerNumber,
          onChanged: trackerBloc.numberSink, /// <- The argument type '(int) → dynamic' can't be assigned to the parameter type '(String) → void'.
          decoration: InputDecoration(
              labelText: 'Equipment Number', errorText: snapshot.error),
        );
      },
    );
  }

用于创建数据的块 Future 如下所示.在这里,我已经从numberField中获取了 null value

The bloc Future to create the data looks like this. here I'm already getting null value from the numberField

  Future<void> createData(docId) {

    final Tracker createTracker = Tracker(
        id: docId,
        comment: _commentController.value,
        exercise: _exerciseController.value,
        number: _numberController.value,
        repetition: _repetitionController.value,
        sets: _setsController.value,
        weight: _weightController.value
    );

    print(_commentController.value + _numberController.value.toString());

    return trackerDb.createData(docId, createTracker);
  }

Sink 看起来像这样

final _numberController = BehaviorSubject<int>();

Stream<int> get numberStream => _numberController.stream.transform(validateNumbers);
Function(int) get numberSink => _numberController.sink.add;


// the vallidation process
Stream<bool> get submitValid => Observable.combineLatest6(commentStream, exerciseStream, numberStream, repStream, setsStream, weightStream, (e, m, p, q, r, t,) => true);

final validateNumbers = StreamTransformer<int, int>.fromHandlers(handleData: (numbers, sink){
  if(numbers > 1) {
    sink.add(numbers);
  } else {
    sink.addError('add at least something man');
  }

});

推荐答案

尝试使用:

 onChanged: (strNum) => trackerBloc.setsSink((int.parse(strNum))),

这篇关于错误:无法将参数类型'(int)→动态'分配给参数类型'(String)→空'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:37