title: How to setState http url?
body: <p>I want to create a news app and I've used newsapi.org as well but The </p>
  
  <p>problem is actually that I want to make something like search feature in my </p>
  
  <p>app and my idea is very simple.</p>
  
  <p>I've created a TextField in the AppBar and my idea is to take the input from</p>
  
  <p>user and setState with the new url of user input.</p>
  
  <p>My Code:  </p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  import 'package:newly/services/networking.dart';
  import 'package:newly/widgets/article.dart';
  
  class NewsScreen extends StatefulWidget {
    @override
    _NewsScreenState createState() =&gt; _NewsScreenState();
  }
  
  class _NewsScreenState extends State&lt;NewsScreen&gt; {
    List&lt;Article&gt; articles = [];
  
    String topic = 'google';
  
    var newsData;
  
    Future getNews(String topic) async {
      NetworkHelper networkHelper = NetworkHelper(
        url:
            'https://newsapi.org/v2/everything?q=$topic&amp;from=2019-11-04&amp;to=2019-11-04&amp;sortBy=popularity&amp;apiKey=392495172bab4b3885ae93760df54b91',
      );
  
      newsData = await networkHelper.getData();
  
      for (int i = 0; i &lt; newsData['articles'].length; i++) {
        var title =  newsData['articles'][i]['title'];
        var urlToImage =  newsData['articles'][i]['urlToImage'];
        var content =  newsData['articles'][i]['content'];
        var author =  newsData['articles'][i]['author'];
        var url =  newsData['articles'][i]['url'];
        setState(() {
          articles.add(
            Article(
              author: author,
              content: content,
              title: title,
              url: url,
              urlToImage: urlToImage,
            ),
          );
        });
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.black,
          centerTitle: true,
          title: TextField(
            textInputAction: TextInputAction.search,
            onChanged: (String text) async {
              setState(() {
                topic = text;
              });
              await getNews(topic);
              print(topic);
            },
            onSubmitted: (String text) async {
              setState(() {
                topic = text;
              });
              print(topic);
              await getNews(topic);
            },
            decoration: InputDecoration(
              suffixIcon: IconButton(
                onPressed: () async {
                  await getNews(topic);
                  print(topic);
                },
                icon: Icon(
                  Icons.search,
                ),
              ),
              hintText: 'Search',
              filled: true,
              fillColor: Colors.white,
            ),
          ),
        ),
        body: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(15.0),
            child: FutureBuilder(
              future: getNews(topic),
              builder: (context, snapshot) {
                return ListView.builder(
                  itemCount: newsData['articles'] == null
                      ? 0
                      : newsData['articles'].length,
                  itemBuilder: (BuildContext ctxt, int index) {
                    return Article(
                      author: articles[index].author,
                      content: articles[index].content,
                      title: articles[index].title,
                      url: articles[index].url,
                      urlToImage: articles[index].urlToImage,
                    );
                  },
                );
              },
            ),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  
  <p>Network Helper :</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:http/http.dart' as http;
  import 'dart:convert';
  
  class NetworkHelper {
    NetworkHelper({this.url});
  
    final String url;
  
    Future getData() async {
      http.Response response = await http.get(url);
  
      if (response.statusCode == 200) {
        String data = response.body;
  
        return json.decode(data);
      } else {
        print('something wrong');
        print(response.statusCode);
      }
    }
  }
  </code></pre>