title: StackOverflowError was thrown building FutureBuilder<List<dynamic>>
body: <p>I am consuming the New York Times Best Sellers API, so that I can get the list of books for each category in the Best Sellers. My code goes thus:</p>
  
  <pre><code>import "dart:convert";
  import "package:flutter/material.dart";
  import "package:http/http.dart" as http;
  import "package:best_sellers/api.dart";
  
  class BestSellersList extends StatefulWidget {
    final API api;
    final List&lt;dynamic&gt; categories;
  
    BestSellersList({Key key, @required this.api, @required this.categories}) : super(key: key);
  
    @override
    _BestSellersList createState() =&gt; _BestSellersList();
  }
  
  class _BestSellersList extends State&lt;BestSellersList&gt; {
    String base, key;
    List&lt;dynamic&gt; categories;
    Future&lt;List&lt;dynamic&gt;&gt; books;
  
    Future&lt;List&lt;dynamic&gt;&gt; fetchBooks() async {
      try {
        final books = categories.map((category) async {
          final listNameEncoded = category["list_name_encoded"];
          final uri = "$base/$listNameEncoded?api-key=$key";
          final response = await http.get(uri);
          if (response.statusCode == 200) {
            final responseBody = json.decode(response.body);
            final books = responseBody["results"]["books"];
            return books;
          } else { throw Exception(); }
        }).toList();
  
        if (books.isNotEmpty) {
          return books;
        }
        throw Exception();
      } catch(e) { /**/ }
    }
  
    void updateBooks() {
      setState(() {
        books = updateBooks();
      });
    }
  
    @override
    initState() {
      super.initState();
      base = widget.api.base;
      key = widget.api.key;
      categories = widget.categories;
      print("categories.length: ${categories.length}"); // categories.length: 55
      updateBooks();
    }
  
    @override
    Widget build(BuildContext context) {
      return FutureBuilder(
        future: books,
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, index) {
                final displayName = snapshot.data[index]["display_name"];
                return ListTile(title: Text(displayName));
              }
            );
          } else if (snapshot.hasError) {
            return Center(child: Column(
              children: [
                Text(snapshot.error.toString()),
                RaisedButton(
                  onPressed: () =&gt; updateBooks(),
                  child: Text("RETRY"),
                ),
              ],
            ));
          }
  
          return Center(child: CircularProgressIndicator());
        }
      );
    }
  }
  </code></pre>
  
  <p>On running my code, I get this stack trace:</p>
  
  <pre><code>    I/flutter ( 5231): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
  ╞═══════════════════════════════════════════════════════════
  I/flutter ( 5231): The following StackOverflowError was thrown building FutureBuilder&lt;List&lt;dynamic&gt;&gt;(state:
  I/flutter ( 5231): _FutureBuilderState&lt;List&lt;dynamic&gt;&gt;#a3252):
  I/flutter ( 5231): Stack Overflow
  I/flutter ( 5231): When the exception was thrown, this was the stack:
  I/flutter ( 5231): #0      State.mounted (package:flutter/src/widgets/framework.dart:969:3)
  I/flutter ( 5231): #1      State.setState.&lt;anonymous closure&gt;
  (package:flutter/src/widgets/framework.dart:1113:63)
  I/flutter ( 5231): #2      State.setState (package:flutter/src/widgets/framework.dart:1123:6)
  I/flutter ( 5231): #3      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #4      _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #5      State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #6      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #7      _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #8      State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #9      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #10     _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #11     State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #12     _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #13     _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
                  ...................................................
                  ...................................................
                  ...................................................
      I/flutter ( 5231): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
  ╞═══════════════════════════════════════════════════════════
  I/flutter ( 5231): The following StackOverflowError was thrown building FutureBuilder&lt;List&lt;dynamic&gt;&gt;(state:
  I/flutter ( 5231): _FutureBuilderState&lt;List&lt;dynamic&gt;&gt;#a3252):
  I/flutter ( 5231): Stack Overflow
  I/flutter ( 5231): When the exception was thrown, this was the stack:
  I/flutter ( 5231): #0      State.mounted (package:flutter/src/widgets/framework.dart:969:3)
  I/flutter ( 5231): #1      State.setState.&lt;anonymous closure&gt;
  (package:flutter/src/widgets/framework.dart:1113:63)
  I/flutter ( 5231): #2      State.setState (package:flutter/src/widgets/framework.dart:1123:6)
  I/flutter ( 5231): #3      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #4      _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #5      State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #6      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #7      _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #8      State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #9      _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #10     _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  I/flutter ( 5231): #11     State.setState (package:flutter/src/widgets/framework.dart:1124:30)
  I/flutter ( 5231): #12     _BestSellersList.updateBooks (package:best_sellers/best_sellers_list.dart:44:9)
  I/flutter ( 5231): #13     _BestSellersList.updateBooks.&lt;anonymous closure&gt;
  (package:best_sellers/best_sellers_list.dart:45:19)
  </code></pre>
  
  <p>I understand that the bug is located in the <code>fetchBooks()</code> method, which in turn is invoked by the <code>updateBooks()</code> method, and that a <code>StackoverflowError</code> is caused by an excessively deep or infinite recursion. The <code>categories</code> list I'm iterating over has 55 items.</p>