最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dart - flutter importexport - Stack Overflow

programmeradmin0浏览0评论

Due to the missing concept of namespaces in dart ¯\(ツ)/¯ one have to fight with imports/exports in flutter. Maybe I was not searching long enough but I didn't find any simple and good explanation on this topic (without boiling the ocean).

Anyway, could someone please help why below does not work :

The file is definitely there:

Due to the missing concept of namespaces in dart ¯\(ツ)/¯ one have to fight with imports/exports in flutter. Maybe I was not searching long enough but I didn't find any simple and good explanation on this topic (without boiling the ocean).

Anyway, could someone please help why below does not work :

The file is definitely there:

Share Improve this question asked Feb 2 at 12:09 László FrankLászló Frank 451 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

The convention is that implementation files are placed in the folder lib and package private files in the folder lib/src. For an app, the public file directly in lib is commonly main.dart and everything else models, screens, ... is located in lib/src.

For more information see package layout.

It is highly recommended that you only import files in lib or through packages, including local packages.

  dependencies:
    packageA:
      path: ../packageA/

I couldn't find the offical documentation for the following at all, so processed with caution.

It appears that library(.dart file) in lib cannot import files outside lib using a relative path. (You can import anything through relative path in other directories like test)

However, you can use absolute path to import file anywhere like this

import 'file:///Users/bob/weather/home.dart';
发布评论

评论列表(0)

  1. 暂无评论