title: How can I prevent my Build Method from looping?
body: <p>I am learning Flutter. I wrote small app to getting key from API and print it on screen. The problem is that my <code>getApiKey()</code> method is looping. </p>
  
  <p>Why? And How I can prevent it?</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  import 'package:flutter/widgets.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  import 'package:provider/provider.dart';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: ChangeNotifierProvider&lt;TenderApiData&gt;(
            builder: (_) =&gt; TenderApiData(), child: HomePage()),
      );
    }
  }
  
  class HomePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(appBar: AppBar(), body: MyContainer());
    }
  }
  
  class MyContainer extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Column(
        children: &lt;Widget&gt;[MyTestWidget()],
      );
    }
  }
  
  class TenderApiData with ChangeNotifier {
    String access_token;
    String url = "https://";
  
    getApiKey() async
    {
      var response = await http.post(url, headers: {"Accept": "application/json"});
      // await Future.delayed(Duration(seconds: 25));  
      if (response.statusCode == 200)
      {
        access_token = json.decode(response.body)['access_token'];
        notifyListeners();
      }
  
    }
  
  }
  
  class MyTestWidget extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      Provider.of&lt;TenderApiData&gt;(context).getApiKey();
      var result = Provider.of&lt;TenderApiData&gt;(context).access_token;
      return Row(
        children: &lt;Widget&gt;[
          Flexible(child: Text("Data: $result"))
        ],
  
      );
    }
  }
  </code></pre>