title: In Dart/Flutter, how do I use a variable from a method so I can ouput it to a text field
body: <p>Hope somebody can help - I hit this dead end a few weeks ago and think that I've tried everything within my limited knowledge.</p>
  
  <p>I've set up a database that works OK - that is I can add data on one screen, review the data and edit the data on another screen.  Now I want to sum one of the columns (beef) which I've been able to do as proven in the 'debugPrint' to the console.  I want to access this variable 'beefTotal' from the 'sumBeef' method and print show this in a text field in the UI.  I just can't manage it though.  It just returns null.</p>
  
  <p>Thanks in advance for any help.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:take_note/utils/database_helper.dart';
  
  class Info extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; _InfoState();
  }
  
  DatabaseHelper helper = DatabaseHelper();
  var database = DatabaseHelper();
  
  class _InfoState extends State&lt;Info&gt; {
    List beefTotal;
  
    @override
    Widget build (BuildContext context) {
  
      return Scaffold(
          appBar: AppBar(
            title: Text("Beef Info"),
            backgroundColor: Colors.lightBlueAccent,
          ),
          body: Container(
            child: Column(
              children: &lt;Widget&gt;[
                Expanded(
                  child: Center(
                    child: RaisedButton(
                      onPressed: (){
                        sumBeef();
                      },
                    ),
                  ),
                ),
                Expanded(
                  child: Center(
                    child: Text("Total Beef is: £ $beefTotal", style: TextStyle(
                        color: Colors.lightBlueAccent,
                        fontSize: 30.0,
                        fontWeight: FontWeight.w400
                    ),),
                  ),
                ),
              ],
            ),
          )
      );
    }
  
    void sumBeef () async {
      beefTotal = await database.addBeef();
      debugPrint("Total beef: $beefTotal");
    }
  }
  </code></pre>
  
  <p>The code below is from a class called DatabaseHelper which the method sumBeef() uses</p>
  
  <pre><code>  Future&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt; addBeef()async{
      Database db = await this.database;
      var result = await db.rawQuery("SELECT SUM(beef) FROM $table");
  
      return result;
    }
  ```[enter image description here][1]
  
  
    [1]: https://i.stack.imgur.com/L46Gj.png
  </code></pre>