web - Flutter WEB,布局模板。pop 返回 void 但期望 Bool
问题描述
我正在尝试跟随本教程。进度在这里: https ://github.com/vinceyoumans/flutweb001/tree/menu001
AssetNotFoundException: the_basics|lib/services/navigation_service.ddc.js
Error compiling dartdevc module:the_basics|lib/services/navigation_service.ddc.js
packages/the_basics/services/navigation_service.dart:12:38: Error: This expression has type 'void' and
can't be used.
return navigatorKey.currentState.pop();
代码在:/lib/services/navigation_services.dart
import 'package:flutter/material.dart';
class NavigationService {
final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
Future<dynamic> navigateTo(String routeName) {
return navigatorKey.currentState.pushNamed(routeName);
}
bool goBack() {
return navigatorKey.currentState.pop();
}
}
我得到的错误:
无法从方法“goBack”返回类型为“void”的值,因为该行的返回类型为“bool”.dart(return_of_invalid_type)”
navigatorKey.currentState.pop();
因此,当它需要一个布尔值时,它似乎返回了一个 void。关于如何解决这个问题的任何想法?
解决方案
更改返回类型时没有任何影响。您可以简单地从
navigatorKey.currentState.pop();
并更新您的函数以返回 void。我还没有看到它在我的项目中造成任何问题。
推荐阅读
- reactjs - 将 `console.log` 添加到所有 `useEffect`
- go - Go 例程后关闭冗余 sql.Rows 对象的推荐方法
- python - 是否可以使用 requests 模块从 Reverso Context 获取带有单词翻译的例句?
- javascript - JS - 强制打印死键
- powershell - 按数字动态分组对象Powershell
- javascript - 防止使用解构时出现属性未定义错误
- c# - C# 控制台应用程序 - 删除列表中以字符串开头的行
- winapi - 如何从文件句柄到客户端获取 Windows 管道服务器端的主机名?
- scala - 比较两个火花数据框列并检查另一个数据框中列中的每个字符串以生成新列
- r - 带降雪的导出功能