错误:无法将参数类型'(int)→动态'分配给参数类型'(String)→空'

时间:2019-07-05 07:37:41

标签: flutter parameters textfield bloc

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

  

无法分配参数类型'(int)→动态'   设置为参数类型'((String)→void')。

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

这是它的外观。

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

  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);
  }

streamSink看起来像这样

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');
  }

});

1 个答案:

答案 0 :(得分:1)

尝试:

List<IPv6Address> ipList = new ArrayList<>();

IPv6AddressRange range = IPv6AddressRange.fromFirstAndLast(
  IPv6Address.fromString("2001:db8:0000:0000:0000:0000:0000:0000"), 
  IPv6Address.fromString("2001:db9:ffff:ffff:ffff:ffff:ffff:ffff"));

for (IPv6Address addr : range) {
  ipList.add(addr);
}