How can I import all files in a folder?

前端 未结 3 2003
余生分开走
余生分开走 2021-02-07 12:44

Say I got a bunch of dart scripts in a folder,

Is there anything I can do like import \'foo/*.dart\'?

P.S. What if I got an array of filenames and

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 13:38

    You could also use the "part of" library composition:

    Create 1 .dart file that is your lib eg.: lib.dart and add at the start of this file.:

    library lib
    

    For every file in your folder add a:

    part "somefile.dart"
    part "otherfile.dart"
    

    In all files that are part of this library add at the start:

    part of lib
    

    In other files and libs you can then import all those file just via:

    import "lib.dart"
    

    This will import all the parts of your library (folder). Keep in mind that the "lib.dart" file is now responsible for all the imports of your lib files. So to import something to "somefile.dart" you add the import to "lib.dart". All imports are then available in all the lib files.

提交回复
热议问题