Dirty state error in flutter
Dirty state error in flutter
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): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (12737): The following assertion was thrown building FutureBuilder>(dirty, state:
I/flutter (12737): _FutureBuilderState>#b09b6):
I/flutter (12737): type 'NoSuchMethodError' is not a subtype of type 'String'
I/flutter (12737): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (12737): more information in this error message to help you determine and fix the underlying cause.
I/flutter (12737): In either case, please report this assertion by filing a bug on GitHub:
what is dirty state?
@JaswantSingh i have already commented the line and its still not working. The snapshot.hasError will return a text mentioning the error (snapshot.error). So this part will catch the error and will not contribute to fixing the error mentioned.
– steven sathish
Aug 23 at 5:52
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I guess the problem is here. return new Text(snapshot.error); Try to comment that line and check. It says, 'NoSuchMethodError' is not a subtype of type 'String' so I guess the problem is there
– Jaswant Singh
Aug 23 at 4:25