title: FutureBuilder : "Expected a value of type 'Future<Map<dynamic, dynamic>>?', but got one of type '_JsonMap'"
body: <p>On trying to pass a Future-Map to the future builder widget , it gives the error below.</p>
  <p>The JsonMap has been cast to a Future-Map using the <code>cast-as</code> operator and the value has been returned using <code>Future.value()</code>,but the below error still persists.</p>
  <p><em>More details:</em><br />
  The builder is supposed to get these initial values , if the values in sharedpreferences are not initialized.</p>
  <p>However on passing the Mapped intial values , Flutter treats the returned _JsonMap  not as a Future-Map and gives the error below.</p>
  <p>How to convert _JsonMap to Future-Map ?</p>
  <p>Error:</p>
  <pre><code>Expected a value of type 'Future&lt;Map&lt;dynamic, dynamic&gt;&gt;?', but got one of type '_JsonMap'
  </code></pre>
  <p>Code:</p>
  <pre><code>import 'dart:convert';
  import 'dart:js';
  import 'package:flutter/material.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  
  class User{
    String name;
    int age;
    bool subscribed;
  
    User({this.name, this.age, this.subscribed});
  }
  
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
  
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'JsonMap',
        theme: ThemeData.dark(),
  
        home: Scaffold(
  
  
          appBar: AppBar(
            title: Text(
              'SharedPreferences returns null values',
              style: TextStyle(),
            ),
          ),
          body: UserScreen1(),
          // body: UserScreen1( sessionDataScreen1 : _sessionDataMain ),
        ),
      );
    }
  }
  class UserScreen1 extends StatefulWidget {
    @override
    _UserScreen1State createState() =&gt; _UserScreen1State();
  }
  
  class _UserScreen1State extends State&lt;UserScreen1&gt; {
  
    =
  
      User _user = User();
      var _mapGet;
       var _mapSet;
  
  
      final _formKey = GlobalKey&lt;FormState&gt;();
  
  
      Future&lt;Map&lt;dynamic, dynamic&gt;&gt; _getSharedPreferences (_userDataKey)  async {
  
  
  
        var  _userJsonInitial = '''{
          &quot;name&quot; : &quot;Mock&quot;,
           &quot;age&quot; : 20,
           &quot;subscribed&quot; : true}''';
  
  
        final prefs =   await SharedPreferences.getInstance();
        final rawJsonGet =  prefs.getString(_userDataKey) ?? _userJsonInitial;
        _mapGet = await jsonDecode(rawJsonGet) as Future&lt;Map&lt;dynamic,dynamic&gt;&gt;;
        print('_mapGet = $_mapGet ');
  
  
        _mapGet.forEach((k, v) =&gt; print('${k}: ${v}'));
  
  
  
      // return   Future&lt;Map&lt;String, dynamic&gt;&gt;.from(json.decode(rawJsonGet));
  
        return Future.value(_mapGet);
  
     }
  
  
  
    void initState() {
      super.initState();
  
      _mapGet =   _getSharedPreferences ('_userDataKey');
      _mapGet.then((_mapGet){
      setState(() {
        _user =  User(name : _mapGet['name'], age : _mapGet['age'], subscribed : _mapGet['subscribed']);
        print(' User InitState : name = ${_user.name}, age = ${_user.age},subscribed = ${_user.subscribed},');
      });});
  
      }
  
  
  
    @override
    Widget build(BuildContext context) {
      return Column(
          mainAxisAlignment: MainAxisAlignment.center ,
          children: [
            Container(child:FutureBuilder&lt;Map&gt;(
            future: _mapGet,
            builder: (BuildContext context, AsyncSnapshot&lt;Map&gt; snapshot) {
              switch (snapshot.connectionState) {
                case ConnectionState.waiting:
                  return const CircularProgressIndicator();
                default:
                  if (snapshot.hasError) {
                    return Text('Error: ${snapshot.error}');
                  } else {
                    // return  Text(' User (BuildContext) : name = ${snapshot.data.['name']}, age = ${snapshot.data['age']},subscribed = ${snapshot.data['subscribed']},');
                    return  Text(' User (BuildContext) : nameMap = ${snapshot.data} , nameUser = ${_user.name},');
  
                  }
              }
            })),
  
      
  
      ]
      );
    }}
  </code></pre>