我偶然发现了在Flutter中导入软件包的问题,我试图通过运行flutter软件包get并在Android Studio中关闭项目并重新打开它来解决此问题。
import 'package:task_02_category_widget/category.dart';
这是上面的行,运行时遇到的错误在控制台中显示以下错误。
Your application could not be compiled, because its dependencies could
not be established.
The following Dart file:
/Users/username/Documents/flutter_rectangle_2/lib/main.dart
...refers, in an import, to the following library:
package:task_02_category_widget/category.dart
That library is in a package that is not known. Maybe you forgot to
mention it in your pubspec.yaml file?
答案 0 :(得分:0)
如果task_02_category_widget / category.dart是旧项目的一部分,则在重复使用时,应将其放在flutter应用程序的文件夹中,并包括“ ../ folder /task_02_category_widget/category.dart”。如果它是您复制粘贴源的github存储库的一部分,则只需复制文件并使用上述步骤即可。很可能您正在寻找that。在任何其他情况下,请检查here以找到源代码。
答案 1 :(得分:0)
您应该在项目的var sessionStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_SECRET")))
var sessionPointer *sessions.Session;
func initSession(r *http.Request) *sessions.Session {
if sessionPointer == nil {
} else{
return sessionPointer;
}
temp, err := sessionStore.Get(r,os.Getenv("SESSION_NAME"))
sessionPointer = temp;
sessionPointer.Options = &sessions.Options{
Path: "/",
MaxAge: 86400 * 1,
HttpOnly: false,
}
if err != nil {
panic(err)
}
return sessionPointer
}
文件中具有如下定义:
pubspec.yaml
假设您的包裹布置如下:
name: my_app
dependencies:
task_02_category_widget:
然后,您可以导入它:
task_02_category_widget/
lib/
category.dart
更多信息:
https://www.dartlang.org/tools/pub/get-started
https://www.dartlang.org/guides/libraries/create-library-packages