Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.6k views
in Technique[技术] by (71.8m points)

How to get rid of Invalid double error in flutter

This is my Sales page where I navigate to a form in Add sales page to add data

class _Sales extends State<SalesList>{
       final Color primaryColor = Color(0xff18203d);
       final Color secondaryColor = Color(0xff232c51);
    
 
  @override
  Widget build(BuildContext context) {
    // ignore: todo
    // TODO: implement build
    return Scaffold(
    appBar: AppBar(
      actions: [
        MaterialButton(
          child: Icon(Icons.add),
          onPressed: (){
            Navigator.push(context, MaterialPageRoute(
              builder: (context)=> AddSales()));
          })
      ],
    ),
    body: Container(
      child:_salesList(),
    ),
    floatingActionButton: FloatingActionButton(onPressed: () =>
    Navigator.push(context, MaterialPageRoute(builder: (context) => AddSales(ref: widget.snap,))),),
    );
    
  }

I keep getting the error invalid double when navigating to the next page (Add Sales page) containing the method (_getAvailable)below

class AddSales extends StatefulWidget{
  final ref;
  AddSales({this.ref});
  @override
  State<StatefulWidget> createState() => _AddSales();

}
class _AddSales extends State<AddSales>{
        final Color primaryColor = Color(0xff18203d);
      final Color secondaryColor = Color(0xff232c51);

DateTime dateTime = DateTime.now();
var formated = DateFormat.yMMMMd('en_US');
var month = DateFormat.MMM('en_US');
var year = DateFormat.y('en_US');

TextEditingController _opening = new TextEditingController();
TextEditingController _issued = new TextEditingController();
TextEditingController _returns = new TextEditingController();
TextEditingController _unitPrice = new TextEditingController();
TextEditingController _closing = new TextEditingController();
TextEditingController _comment = new TextEditingController();

        double available;
      _getAvailable(){
         setState(() {
           available =  VendorsSales(
         double.parse(_opening.text),
          double.parse(_issued.text),
          available,
          double.parse(_returns.text),
          double.parse(_closing.text),)
       .getAvailable();
       
         });
       
         
          return available;
      }

*Inorder to get the available I need to add double values of _issued and _opening stock which will be "parsed" from the textfield * class VendorsSales{ VendorsSales(this._opening, this._issued, this._available, this._returns ,this._closing); var id; DateTime dateTime; double _opening; double _issued; double _available; double _returns; double _closing; double _quantity; double _price; double _amount; String _comment;

var formated = DateFormat.yMMMMd('en_US');
var month = DateFormat.MMM('en_US');
var year = DateFormat.y('en_US');

 getAvailable( ){
_available = _opening + _issued;   
   return _available;
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...