【问题标题】:Flutter Ubuntu Android Studio -> can't find Target of URI doesn't existFlutter Ubuntu Android Studio - >找不到URI目标不存在
【发布时间】:2021-08-03 15:15:19
【问题描述】:

文件内声明的常量值:

import 'package:flutter/material.dart';
import 'package:flutter_complete_guide/models/category.dart';
import 'package:flutter_complete_guide/models/meal.dart';

const kDummyMeals = <Meal>[
   Meal(
    id: 'm1',
    categories: [
      'c1',
      'c2',
    ],
    title: 'Spaghetti with Tomato Sauce',
    affordability: Affordability.Affordable,
    complexity: Complexity.Simple,
    imageUrl:
        'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
    duration: 20,
    ingredients: [
      '4 Tomatoes',
      '1 Tablespoon of Olive Oil',
      '1 Onion',
      '250g Spaghetti',
      'Spices',
      'Cheese (optional)'
    ],
    steps: [
      'Cut the tomatoes and the onion into small pieces.',
      'Boil some water - add salt to it once it boils.',
      'Put the spaghetti into the boiling water - they should be done in about 10 to 12 minutes.',
      'In the meantime, heaten up some olive oil and add the cut onion.',
      'After 2 minutes, add the tomato pieces, salt, pepper and your other spices.',
      'The sauce will be done once the spaghetti are.',
      'Feel free to add some cheese on top of the finished dish.'
    ],
    isGlutenFree: false,
    isVegan: true,
    isVegetarian: true,
    isLactoseFree: true,
  ),
// some other values

]

我通过以下方式使用这个常量:

错误: URI 的目标不存在:'package:flutter_complete_guide/dummy_categories.dart'。 (文档)尝试创建由 URI 引用的文件,或尝试为确实存在的文件使用 URI。

结构

扑医生 医生摘要(要查看所有详细信息,请运行 flutter doctor -v):

[✓] Flutter (Channel stable, 2.0.6, on Linux, locale uk_UA.UTF-8)

[✓] Android 工具链 - 为 Android 设备开发(Android SDK 版本 30.0.3)

[✓] Chrome - 为网络开发

[✓] Linux 工具链 - 为 Linux 桌面开发

[✓] Android Studio [✓] 已连接设备(2 个可用)

• 未发现任何问题!

Android Studio 4.2

【问题讨论】:

    标签: flutter android-studio ubuntu


    【解决方案1】:

    您是否可以使用完整路径更改您的导入。不同的是“models”文件夹,像这样:

    package:flutter_complete_guide/models/dummy_categories.dart'. 
    

    这是一个例子:

    • 进口声明

    导入'package:todo_app/app/global/colors.dart';

    • 结构:

    【讨论】:

      【解决方案2】:

      我认为您应该使用自己的项目名称来导入项目中的文件。 您应该将 import 'package:flutter_complete_guide/... 替换为 import 'package:meals/...

      您也可以使用相对路径导入import '../dummy_categories.dart';等文件

      如果你想从一些未发布的包中导入,你可以将它添加到你的pubspec.yamllike this

      【讨论】:

        【解决方案3】:

        我也遇到过这个问题。我在 Windows 机器上创建一个文件。然后我也遇到了这个错误。

        我通过删除该文件并在 Mac 机器上创建一个具有不同文件名的新文件来解决问题,然后一切恢复正常。

        【讨论】:

          猜你喜欢
          • 2018-08-08
          • 2019-08-27
          • 2013-08-06
          • 1970-01-01
          • 2018-08-07
          • 2016-09-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多