无法快速浏览到主页

时间:2020-06-02 10:54:47

标签: flutter dart flutter-layout flutter-test dart-webui

我有一个包含主屏幕和更新屏幕的应用。

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

请参见下面的主屏幕代码

  // 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>

请帮助。

1 个答案:

答案 0 :(得分:0)

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

只需保持onpressed()不变。

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