1

I want to calculate the total price of list , how can i do that.

code for entering price.

     Container(
            width: 60.0,
            alignment: Alignment.centerRight,
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10.0)
            ),
            child: Padding(
              padding: const EdgeInsets.only(top: 10.0, left: 16.0),
              child: TextFormField(
                maxLength: 3,
                controller: _amountController,
                keyboardType: TextInputType.numberWithOptions(),
                decoration: InputDecoration(
                  counter: Offstage(),
                  border: InputBorder.none,
                ),
              ),
            ),

if i am using .fold then i am getting _addfromInteger error..

               Container(
                        height: 40.0,
                        width: 100.0,
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(10.0)

                        ),
                        child: Center(
                            child: Text(listdynamicWidget.fold(0, (prev, el) => prev + el.productAmount).toString()),
                        )
                        ),
                    ],
                  ),

    

enter image description here

4
  • Usually, this list should not be so long, so you can use a normal ListView instead of a list builder. Commented Dec 29, 2020 at 4:45
  • ok thanks for this but how to calculate total price Commented Dec 29, 2020 at 4:48
  • you can add a list of controllers instead of individual controllers then iterate through them to access text field values. Commented Dec 29, 2020 at 5:06
  • _addfromInteger error. means some value is null... print the list data and see which value is empty Commented Dec 29, 2020 at 5:21

1 Answer 1

1

You should use TextField and onChanged at StatefulWidget like below.

TextField(
    onChanged: (inputText) {
      if (inputText.runtimeType == int) {
      // calculate method
      setState((){});
    }
  },
),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.