问题
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.
The argument type '(int) → dynamic' can't be assigned to the parameter type '(String) → void'.
I'm using bloc
to post to a firebase db.
here is how it looks.
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),
...
the textField
itself looks like this:
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),
);
},
);
}
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);
}
The stream
and Sink
looks like this
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:
Try with:
onChanged: (strNum) => trackerBloc.setsSink((int.parse(strNum))),
来源:https://stackoverflow.com/questions/56898595/error-the-argument-type-int-%e2%86%92-dynamic-cant-be-assigned-to-the-parameter-ty