0

I'm trying to calculate the sum of TotalPrice column in my table Items but it returns a null(waiting ...) in a text widget according to the condition I've given.

 Future calculateTotal(var order) async {
var dbClient = db;
var result = await dbClient.rawQuery(
    'select sum(TotalPrice) as Total from Items where refID = ?'[order]);

print(result.toList());

}

*above is the code in my database helper class**

    double _total;
  void _calcTotal() async {
    var total =
        (await OrderProvider().calculateTotal(widget.order))[0]['Total'];
    print(total);
    setState(() {
      _total = total;
    });
  }

  Widget showItems() {
    return Container(
      color: Colors.blueGrey,
      child: Column(
        children: <Widget>[
          Container(
              color: Colors.amberAccent,
              padding: EdgeInsets.only(
                top: 10,
                bottom: 10,
              ),
              child: Center(
                child: Text(
                  _total != null ? _total : 'waiting ...',
                  style: TextStyle(fontSize: 10),
                ),
              )),

above is the code in my widget class. I've used this example I've used this example

1 Answer 1

0

I added a comma in my future method in the database provider class

    Future calculateTotal(var order) async {
var dbClient = db;
var result = await dbClient.rawQuery(
    'select sum(TotalPrice) as Total from Items where refID = ?',[order]);

print(result.toList());

I also forgot to include quotation marks in my text widget,

Widget showItems() {
return Container(
  color: Colors.blueGrey,
  child: Column(
    children: <Widget>[
      Container(
          color: Colors.amberAccent,
          padding: EdgeInsets.only(
            top: 10,
            bottom: 10,
          ),
          child: Center(
            child: Text("
              _total != null ? _total : 'waiting ..."',
              style: TextStyle(fontSize: 10),
            ),
          )),
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.