简体   繁体   English

在flutter导入dart文件

[英]Import dart file in flutter

I'm working on a flutter project and I want to import a dart file in my main file but I don't know how to do it.我正在处理一个 flutter 项目,我想在我的主文件中导入一个 dart 文件,但我不知道该怎么做。 I import my dart file first import 'package:splash/Categories.dart';我首先导入我的 dart 文件import 'package:splash/Categories.dart'; and I initialized it like that final Category _category = Category();然后我像final Category _category = Category(); but I have this error Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports Please how can I fix it.但我有这个错误Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports请问我该如何修复它。 Thank you in advance先感谢您

This happens when the same class is in two different files.当相同的 class 在两个不同的文件中时,就会发生这种情况。 So if you want to use a specific class in specific file we need to use aliases.因此,如果您想在特定文件中使用特定的 class,我们需要使用别名。

Example:例子:

import 'package:splash/Categories.dart';
import 'package:something/Something.dart' as name;

Use classname in Something.dart as name.class_nameSomething.dart中使用类名作为name.class_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将其他 dart 文件导入 flutter 中的有状态小部件? - How can I import other dart file to stateful widget in flutter? 如何在flutter文件中获取一个.dart文件到另一个.dart文件的变量 - How to get a variable of .dart file to another .dart file in flutter 在dart / flutter项目中包含C文件 - Include C file in a dart/flutter project Dart:将 html 文件加载到 Flutter Webview 中 - Dart: Load an html file into a Flutter Webview Flutter / Dart FFI existing.so文件为Android - Flutter / Dart FFI existing .so file for Android 地理编码 Flutter,无法导入“package:geocoding/geocoding.dart” - geocoding Flutter, can't import 'package:geocoding/geocoding.dart' Flutter 导入 'package:flutter_svg/flutter_svg.dart'; 不适用于 VS 代码和 Android 工作室 - Flutter import 'package:flutter_svg/flutter_svg.dart'; not working on the VS code and Android studio Flutter 构建失败:未找到:'dart:html' import 'dart:html' http-0.12.2 - Flutter Build failure: Not found: 'dart:html' import 'dart:html' http-0.12.2 如何从flutter dart中firebasestorage中该文件的链接获取文件名 - How to get name of a file from the link of that file in firebasestorage in flutter dart 安装 Flutter 和 Dart 后 Build.Gradle 文件损坏 - Build.Gradle file broken after install of Flutter and Dart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM