我正在使用将来的构建器来显示一些小部件上的信息-
Future _getTaskAsync;
// inside initstate
_getTaskAsync = getEventSubtasks(baseURL + getTodoDetailsUrl, widget.taskId);
// outside initstate
FutureBuilder(
future: _getTaskAsync,
builder: (context, snapshot){
if(snapshot.hasData) {
print(snapshot.data);
return listViewWidget(snapshot.data);
}else{
return CircularProgressIndicator();
}
}),
这是获取数据的方法-
Future getEventSubtasks(String url, String taskId) async {
String id = await secureStore.read(key: "userId");
String token = await secureStore.read(key: "userToken");
print("PRINTING USETOKEN FROM GET EVENT SUBTASK = $token");
print("PRINTING LINK FOR GET EVENT SUBTASKS = $baseURL/todos/find_one_todo_detail");
var res = await http.post(url, headers: {"Content-Type": "application/x-www-form-urlencoded", "x-access-code" : token}, body: {"todo_card_id" : taskId, "user_id" : id});
if(res.statusCode != 200){
loadMore = false;
loadmoreGroupDetails = false;
loadMoreGroupScreenTasks = false;
}
print("PRINTING GET EVENT SUBTASK RESBODY = ${res.body}");
//print("PRINTING RES BODY RUNTYPE = ${jsonDecode(res.body).runtimeType}");
print("AFTER RUNTYPE FOR GET ONE TODO DETAILS = ${jsonDecode(res.body)}");
var returnData = jsonDecode(res.body) as Map;
return returnData;
}
即使我成功获取了响应正文-
print(snapshot.data);
{
"error": "0",
"message": "Got it!",
"data": {
"status": "false",
"_id": "5e4ced2ae8b8a50006ce343c",
"group_id": "5e4ce9cfe8b8a50006ce3438",
"date": "2020-02-19T00:00:00.000Z",
"title": "fdjdbd",
"priority": 5,
"description": "eyehe",
"user_id": "5e37fa0625ba9678443d02ba",
"tasks": [],
"created_date": "2020-02-19T08:09:14.264Z",
"__v": 0
}
}
我收到此错误,它指向我在上面的代码片段中所附的FutureBuilder-
The following ArgumentError was thrown building Description_Screen(dirty, dependencies: [MediaQuery], state: _Description_ScreenState#88411):
Invalid argument(s)
当我完全删除FutureBuilder小部件时,我遇到了相同的错误,但是这次它指向的是navigator.push语句-
List<dynamic> result1 = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Description_Screen(
data[index].taskName,
// data[index].markComplete,
// data[index].date,
data[index].taskID,
data[index].priority,
data[index].groupID,
// data[index].description,
// data[index].subtasks,
dateToStringtime(setter),
data[index].description
),
)
);
“描述”屏幕的代码-
class Description_Screen extends StatefulWidget {
final String taskName;
final String taskId;
final int priority;
final String groupId;
final String dateValue;
final String description;
Description_Screen(
this.taskName ,
this.taskId,
this.priority,
this.groupId,
this.dateValue,
this.description
);
@override
_Description_ScreenState createState() => _Description_ScreenState();
}```
listview widget code -
```
List<dynamic> subtaskListAPI = [];
listViewWidget(Map<dynamic, dynamic> data) {
if(data["data"]["tasks"] != null) {
subtaskListAPI = data["data"]["tasks"];
}else{
subtaskListAPI = new List<dynamic>();
}
return Container(
color: Colors.white,
alignment: Alignment.topLeft,
margin: const EdgeInsets.all(13),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(height: 10,),
//Todo: remove sized box below and display tasks there
TextFormField(
keyboardType: TextInputType.text,
// initialValue: widget.title,
validator: (String value) {
return value.isEmpty ? "task must have a name" : null;
},
textAlign: TextAlign.start,
// maxLength: 100,
controller: newcontroller, // Just an ordinary TextController
onChanged: (value) {
setState(() {
value = newcontroller.text;
});
},
decoration: InputDecoration(
border: InputBorder.none,
errorText:
_validate // Just a boolean value set to false by default
? 'Value Can\'t Be Empty'
: null,
labelText: "name of task"
),
style: TextStyle(height: 1.2, fontSize: 18, color: Colors.black87),
),
TextField(
controller: descriptioncontroller,
onEditingComplete: (){
/// IMPLEMENT ADD DETAIL API CALL HERE
},
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(Icons.short_text),
labelText: "Add details"
),
),
SizedBox(height: 10,),
ListView.builder( // this listview builder is the only widget which is supposed to use the data fetched from the method
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data["data"]["tasks"].length,
itemBuilder: (BuildContext context, int index) {
int dataLength = data["data"]["tasks"].length;
// ignore: missing_return
Widget returnTextListTile() {
int i = 0;
while(i < dataLength){
Future.delayed(Duration(seconds: 2));
// refresh();
return blackfontstyleMont(
text: subtaskListAPI[index]["name"], size: 20,);
}
i++;
}
//bool confirmDismiss = false;
return Container(
width: MediaQuery.of(context).size.width,
height: 40,
child: ListTile(
title: Padding(
padding: const EdgeInsets.only(left: 24),
child: returnTextListTile(),
),
trailing: Container(
//color: Colors.black,
width: 40,
height: 40,
child: IconButton(
onPressed: (){
deleteSubtasks(widget.taskId, subtaskListAPI[index]["_id"]);
setState(() {
subtaskListAPI.removeAt(index);
});
},
icon: Icon(Icons.cancel),
color: Colors.grey,
),
),
),
);
}
),
// SizedBox(height: 20,),
SizedBox(height: 10,),
SizedBox(height: 20,),
blackfontstyleBebas(text: "Priority", size: 20,),
]
),
);
}
```
I have already tried flutter clean and have added a circular indicator widget to the FutureBuilder, Could i get some suggestions on how to fix this error?