title: Trying to get a random quote from a php mysql, using flutter http
body: <p>I am new to flutter and php, and am trying to get my flutter app to display a random quote generated on a php file. This php file in turn gets it's quote from a mysql db(will have about 200 entries). On the php front, the quote appears and everything seems to work fine (except that it's displayed with [[]] but if got it right it's because I'm calling objects,instead of strings?).</p>
  
  <p>The problem is on the flutter side. I get the quote to appear on the screen as well as print, but it doesn't change to another quote if I press the floatingActionButton button. Unless I reload my php file in a browser.
  My guess is that I'm storing an existing php string instead of calling for a new http request. But I don't know how to correct it.</p>
  
  <p>PS. I've taken the code related to color out for better readability</p>
  
  <pre><code>//*****myphppage.php code:
  
  $makeQuery = "SELECT * FROM mytable ORDER BY RAND() LIMIT 1";
  $statement = $connection-&gt;prepare($makeQuery);
  $statement-&gt;execute();
  //stored in array bc originally had more quotes;
  $myarray = array();
  while ($resultsFrom = $statement -&gt;fetch()){
      array_push(
         $myarray,array(
          $resultsFrom['body']
         )
        );
  }
  echo json_encode($myarray);
  
  //////*******main.dart:
  
  import 'package:flutter/material.dart';
  import 'dart:async';
  import 'dart:convert';
  import 'dart:math';
  import 'package:http/http.dart' as http;
  import 'about_screen.dart';
  
  void main() =&gt; runApp(Ojogo());
  
  class Ojogo extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Quote app',
        theme: ThemeData(
          fontFamily: 'Imperator',
          textTheme: Theme.of(context).textTheme.apply(bodyColor: Colors.white),
        ),
        home: HomeScreen(),
      );
    }
  }
  
  class Quote {
    final String quote;
    Quote.fromJson(Map&lt;String, dynamic&gt; json) : quote = json['body'];
  }
  
  class HomeScreen extends StatefulWidget {
    @override
    _HomeScreenState createState() =&gt; _HomeScreenState();
  }
  ....
    Future&lt;void&gt; getQuote() async {
      String theUrl = 'http://mywebsite.com/myphppage.php';
      http.Response response = await http.get(theUrl);
      var myQuote = jsonDecode(response.body);
      setState(() {
        _quote = myQuote.toString();
        print(_quote);
      });
    }
  
    void _getNewQuote() {
      setState(() {
        _quote = null;
      });
      getQuote();
    }
  
    @override
    void initState() {
      super.initState();
      getQuote();
      }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Container(
          decoration: BoxDecoration(
            color: Colors.orange,
            gradient: LinearGradient(
                colors: [_colorOne, _colorTwo]), //take the gradients out
          ),
          child: Padding(
            padding: const EdgeInsets.all(24.0),
            child: Center(
              child: Column(
                children: &lt;Widget&gt;[
                  Stack(
                    children: &lt;Widget&gt;[
                      Align(
                        alignment: Alignment.bottomCenter,
                        child: Padding(
                          padding: const EdgeInsets.only(top: 24.0),
                          child: Text('QUOTE APP'),
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: IconButton(
                          padding: const EdgeInsets.only(top: 18.0),
                          icon: Icon(Icons.favorite,
                              color: Colors.white),
                          onPressed: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (context) =&gt; AboutScreen()));
                          },
                        ),
                      ),
                    ],
                  ),
                  Expanded(
                    child: Align(
                      alignment: Alignment.center,
                      child: _quote != null
                          ? Text('$_quote',
                              style: TextStyle(
                                fontSize: 34.0,
                                height: 1.25,
                              ))
                          : CircularProgressIndicator(),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: _getNewQuote, child: Icon(Icons.refresh)),
      );
    }
  }
  </code></pre>
  
  <p>I'd like my flutter dart file to renew the quote everytime I press floatingActionButton:
  Right now it does not refresh with new quote, unless I refresh the php page on a browser.</p>