fifth.dart

import 'package:flutter/material.dart';
import 'package:emas_app/Dependant.dart' as Dep;
import 'package:emas_app/crm_dependent_list_model.dart';
import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:emas_app/crm_dep_entitlement_model.dart';

final String url = "http://crm.emastpa.com.my/MemberInfo.json";

//Future to get list of dependent names
Future<List<DependantModel>> fetchUserInfo() async{

  http.Response response = await http.get(url);
  var responsejson = json.decode(response.body);

  return(responsejson[0]['Dependents'] as List)
      .map((user) => DependantModel.fromJson(user))
      .toList();
}

class Fifth extends StatefulWidget {
  @override
  _FifthState createState() => _FifthState();
}

class _FifthState extends State<Fifth> {

  static Future<List<DependantModel>> depState;

  @override
  void initState() {
    depState = fetchUserInfo();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    //ListView.builder inside FutureBuilder
    var futureBuilder = new FutureBuilder<List<DependantModel>>(
        future: depState,
        builder: (context, snapshot){
          switch(snapshot.connectionState){
            case ConnectionState.none:
            case ConnectionState.waiting:
              return new Center(
                child: new CircularProgressIndicator(),
              );
            default:
              if(snapshot.hasError){
                return new Text(snapshot.error);
              }else{

                List<DependantModel> user = snapshot.data;

                return new ListView.builder(
                    itemCount: user.length,
                    itemBuilder: (context, index){
                      return new Column(
                        children: <Widget>[
                          new ListTile(
                            title: new Text(user[index].name,
                                style: TextStyle(fontSize: 20.0)),
                            subtitle: new Text(user[index].relationship,
                                style: TextStyle(fontSize: 15.0)),
                            trailing: new MaterialButton(color: Colors.greenAccent,
                                textColor: Colors.white,
                                child: new Text("More"),
                                onPressed: (){
                                  Navigator.push(context,
                                      new MaterialPageRoute(builder: (context) => Dep.Dependents(name: user[index].name)));
                                }
                            ),
                          )
                        ],
                      );
                    });
              }
          }
        });

    return new Scaffold(
      body: futureBuilder,
    );
  }
}

I've just had the following error occurring in my flutter project. I / flutter(12737):══╡WIDGETS LIBRARY的例外情况╞══════════════════════════════════════════════════════════════════════════════════════════════════════════ ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ _FutureBuilderState>#b09b6):I / flutter(12737):类型'NoSuchMethodError'不是'String'类型的子类型I / flutter(12737):断言表示框架本身有错误,或者我们应该提供大幅I / flutter(12737) ):此错误消息中的更多信息可帮助您确定并修复根本原因 . I / flutter(12737):在任何一种情况下,请通过在GitHub上提交错误来报告此断言:

what is dirty state?