0

在我的应用程序中,有一个用于以双格式输入特定值的字段,但这不起作用。

我究竟做错了什么?

我的集团

 class BudgetBloc extends BlocBase {
   String _documentId;
   double _movimentos;

   BudgetBloc() {
     _movimentosController.listen((value) => _movimentos = value);
   }

   void setBudget(Budget budget) {
     _documentId = budget.documentId();
     setMovimentos(budget.movimentos);
   }

   var _movimentosController = BehaviorSubject<double>();
   Stream<double> get outMovimentos => _movimentosController.stream;

   void setMovimentos(double value) => _movimentosController.sink.add(value);

   bool insertOrUpdate() {
      var budget = Budget()
     ..movimentos = _movimentos;

     if (_documentId?.isEmpty ?? true) {
       _repository.add(budget);
     } else {
       _repository.update(_documentId, budget);
     }

    return true;
  }

   @override
   void dispose() {   
     _movimentosController.close();
     super.dispose();
   }
 }

我的预算页面

 class BudgetPage extends StatefulWidget {

   BudgetPage(this.budget);
   final Budget budget;

   @override
   _BudgetPageState createState() => _BudgetPageState();
 }
 class _BudgetPageState extends State<BudgetPage> {

   TextEditingController _movimentosController;
   final _bloc = BudgetBloc();

   @override
   void initState() {
   _movimentosController =
      TextEditingController(text: widget.budget.movimentos.toString());
   super.initState();
  }

  @override
  void dispose() {
   _movimentosController.dispose();
  super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Add Movimento"),
      ),
      body: Container(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: ListView(
          children: <Widget>[

            Container(
              child: TextField(
                decoration: InputDecoration(labelText: "Movimento"),
                controller: _movimentosController,
                onChanged: _bloc.setMovimentos,
              ),
            ),

            Container(
              height: 20,
            ),

            RaisedButton(
              child: Text("Save"),
              onPressed: () {
                if (_bloc.insertOrUpdate()) {
                  Navigator.pop(context);
                }
              },
            )
          ],
        ),
      ),
    ),
  );
 }

 }

谢谢

4

1 回答 1

1

Function(double) 不能分配给参数类型 void Function(String)

该错误告诉您,String当它需要 a 时,您正在提供 a double

我会尝试将 a 传递double给 BLoC,如下所示:

onChanged: (value) => _bloc.setMovimentos(double.parse(value)),
于 2020-01-19T15:46:18.950 回答