无法在颤振中导航到主页



我有一个由主屏幕和更新屏幕组成的应用程序。

我无法从更新屏幕导航回主屏幕。

请参阅以下主屏幕代码

// build the list widget
Widget _buildTaskWidget(task) {
return ListTile(
leading: Icon(Icons.assignment),
title: Text(task['name']),
subtitle: Text(task['created_at']),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UpdateTask(task: task),
),
);
}
);
}

有关更新屏幕,请参阅以下代码

@override
Widget build(BuildContext context) {
// final Task task = ModalRoute.of(context).settings.arguments;
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text('Update Task'),
),
body: ListView(
children: <Widget>[
inputWidget(),
inputWidgetForVendor(),
inputWidgetForAmount(),
Container(
margin: EdgeInsets.fromLTRB(45, 1, 45, 1),
child: RaisedButton(
color: Colors.blueAccent,
child: Text('Update Task', style: TextStyle(color: Colors.white)),
onPressed: () async {
var res = await updateNewTask(_taskTextInput.text, _vendorTextInput.text,  _amountTextInput.text, id);
print(res);
Navigator.pop(context);
},
),
)
],
)// This trailing comma makes auto-formatting nicer for build methods.
);
}

如果我删除当前的 onPressed 函数并在下面替换为此功能,它可以工作

onPressed: () { Navigator.pop(context); },

我在初始函数中做错了什么? 更新功能成功更新列表项,但我无法导航回来。 请参阅下面的错误日志:

E/flutter (27123): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'
E/flutter (27123): #0      updateNewTask (package:task/repository/services.dart:67:10)
E/flutter (27123): <asynchronous suspension>

请帮忙。

也许此时外包异步更新功能是一个简单的解决方案,当您想立即返回主屏幕时。然后,您可以直接在函数中打印更新。

只需保持 onpressed(( 原样即可。

onPressed: () {
updateNewTask(_taskTextInput.text, _vendorTextInput.text,  _amountTextInput.text, id);
Navigator.pop(context);
},