Flutter 如何在flatter中添加图像

Flutter 如何在flatter中添加图像,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我是第一次开发颤振应用程序。。我在添加图像时遇到问题。我有以下问题: 在何处创建图像文件夹 在pubspec.ymal中的何处添加资产标记 此操作是否需要任何资产文件夹 我的尝试: assets: - images/lake.jpg #/properties/flutter/properties/uses-material-design: type: wanted [boolean] got true, Error detected in pubspec.yaml: Error bu

我是第一次开发颤振应用程序。。我在添加图像时遇到问题。我有以下问题:

  • 在何处创建图像文件夹
  • 在pubspec.ymal中的何处添加资产标记
  • 此操作是否需要任何资产文件夹
  • 我的尝试:

     assets:
        - images/lake.jpg
    
    #/properties/flutter/properties/uses-material-design: type: wanted [boolean] got true,
    Error detected in pubspec.yaml:
    Error building assets
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Script '/home/abc/Downloads/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 435
    
    * What went wrong:
    Execution failed for task ':app:flutterBuildDebug'.
    > Process 'command '/home/abc/Downloads/flutter/bin/flutter'' finished with non-zero exit value 1
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 1s
    Finished with error: Gradle build failed: 1
    
    // Copyright 2017 The Chromium Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    import 'package:flutter/material.dart';
    // Uncomment lines 7 and 10 to view the visual layout at runtime.
    //import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
    
    void main() {
      //debugPaintSizeEnabled = true;
      runApp(new MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        Widget titleSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Row(
            children: [
              new Expanded(
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    new Container(
                      padding: const EdgeInsets.only(bottom: 8.0),
                      child: new Text(
                        'Oeschinen Lake Campground',
                        style: new TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    new Text(
                      'Kandersteg, Switzerland',
                      style: new TextStyle(
                        color: Colors.grey[500],
                      ),
                    ),
                  ],
                ),
              ),
              new Icon(
                Icons.star,
                color: Colors.red[500],
              ),
              new Text('41'),
            ],
          ),
        );
    
        Column buildButtonColumn(IconData icon, String label) {
          Color color = Theme.of(context).primaryColor;
    
          return new Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              new Icon(icon, color: color),
              new Container(
                margin: const EdgeInsets.only(top: 8.0),
                child: new Text(
                  label,
                  style: new TextStyle(
                    fontSize: 12.0,
                    fontWeight: FontWeight.w400,
                    color: color,
                  ),
                ),
              ),
            ],
          );
        }
    
        Widget buttonSection = new Container(
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              buildButtonColumn(Icons.call, 'CALL'),
              buildButtonColumn(Icons.near_me, 'ROUTE'),
              buildButtonColumn(Icons.share, 'SHARE'),
            ],
          ),
        );
    
        Widget textSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Text(
            '''
    Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese Alps. Situated 1,578 meters above sea level, it is one of the larger Alpine Lakes. A gondola ride from Kandersteg, followed by a half-hour walk through pastures and pine forest, leads you to the lake, which warms to 20 degrees Celsius in the summer. Activities enjoyed here include rowing, and riding the summer toboggan run.
            ''',
            softWrap: true,
          ),
        );
    
        return new MaterialApp(
          title: 'Flutter Demo',
          home: new Scaffold(
            appBar: new AppBar(
              title: new Text('Top Lakes'),
            ),
            body: new ListView(
              children: [
                new Image.asset(
                  'images/lake.jpg',
                  width: 600.0,
                  height: 240.0,
                  fit: BoxFit.cover,
                ),
                titleSection,
                buttonSection,
                textSection,
              ],
            ),
          ),
        );
      }
    }
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
    
        var assetsImage = new AssetImage('assets/images/mountain.jpg'); //<- Creates an object that fetches an image.
        var image = new Image(image: assetsImage, fit: BoxFit.cover); //<- Creates a widget that displays an image.
    
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text("Climb your mountain!"),
              backgroundColor: Colors.amber[600], //<- background color to combine with the picture :-)
            ),
            body: Container(child: image), //<- place where the image appears
          ),
        );
      }
    }
    
    内部pubspec.ymal:

    完整文件:

    name: my_flutter_app
    description: A new Flutter application.
    
    dependencies:
      flutter:
        sdk: flutter
    
      cupertino_icons: ^0.1.2
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    flutter:
      uses-material-design: true,
      assets:
        - images/lake.jpg
    
    错误日志:

     assets:
        - images/lake.jpg
    
    #/properties/flutter/properties/uses-material-design: type: wanted [boolean] got true,
    Error detected in pubspec.yaml:
    Error building assets
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Script '/home/abc/Downloads/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 435
    
    * What went wrong:
    Execution failed for task ':app:flutterBuildDebug'.
    > Process 'command '/home/abc/Downloads/flutter/bin/flutter'' finished with non-zero exit value 1
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 1s
    Finished with error: Gradle build failed: 1
    
    // Copyright 2017 The Chromium Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    import 'package:flutter/material.dart';
    // Uncomment lines 7 and 10 to view the visual layout at runtime.
    //import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
    
    void main() {
      //debugPaintSizeEnabled = true;
      runApp(new MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        Widget titleSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Row(
            children: [
              new Expanded(
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    new Container(
                      padding: const EdgeInsets.only(bottom: 8.0),
                      child: new Text(
                        'Oeschinen Lake Campground',
                        style: new TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    new Text(
                      'Kandersteg, Switzerland',
                      style: new TextStyle(
                        color: Colors.grey[500],
                      ),
                    ),
                  ],
                ),
              ),
              new Icon(
                Icons.star,
                color: Colors.red[500],
              ),
              new Text('41'),
            ],
          ),
        );
    
        Column buildButtonColumn(IconData icon, String label) {
          Color color = Theme.of(context).primaryColor;
    
          return new Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              new Icon(icon, color: color),
              new Container(
                margin: const EdgeInsets.only(top: 8.0),
                child: new Text(
                  label,
                  style: new TextStyle(
                    fontSize: 12.0,
                    fontWeight: FontWeight.w400,
                    color: color,
                  ),
                ),
              ),
            ],
          );
        }
    
        Widget buttonSection = new Container(
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              buildButtonColumn(Icons.call, 'CALL'),
              buildButtonColumn(Icons.near_me, 'ROUTE'),
              buildButtonColumn(Icons.share, 'SHARE'),
            ],
          ),
        );
    
        Widget textSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Text(
            '''
    Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese Alps. Situated 1,578 meters above sea level, it is one of the larger Alpine Lakes. A gondola ride from Kandersteg, followed by a half-hour walk through pastures and pine forest, leads you to the lake, which warms to 20 degrees Celsius in the summer. Activities enjoyed here include rowing, and riding the summer toboggan run.
            ''',
            softWrap: true,
          ),
        );
    
        return new MaterialApp(
          title: 'Flutter Demo',
          home: new Scaffold(
            appBar: new AppBar(
              title: new Text('Top Lakes'),
            ),
            body: new ListView(
              children: [
                new Image.asset(
                  'images/lake.jpg',
                  width: 600.0,
                  height: 240.0,
                  fit: BoxFit.cover,
                ),
                titleSection,
                buttonSection,
                textSection,
              ],
            ),
          ),
        );
      }
    }
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
    
        var assetsImage = new AssetImage('assets/images/mountain.jpg'); //<- Creates an object that fetches an image.
        var image = new Image(image: assetsImage, fit: BoxFit.cover); //<- Creates a widget that displays an image.
    
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text("Climb your mountain!"),
              backgroundColor: Colors.amber[600], //<- background color to combine with the picture :-)
            ),
            body: Container(child: image), //<- place where the image appears
          ),
        );
      }
    }
    
    My main.dart代码:

     assets:
        - images/lake.jpg
    
    #/properties/flutter/properties/uses-material-design: type: wanted [boolean] got true,
    Error detected in pubspec.yaml:
    Error building assets
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Script '/home/abc/Downloads/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 435
    
    * What went wrong:
    Execution failed for task ':app:flutterBuildDebug'.
    > Process 'command '/home/abc/Downloads/flutter/bin/flutter'' finished with non-zero exit value 1
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 1s
    Finished with error: Gradle build failed: 1
    
    // Copyright 2017 The Chromium Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    import 'package:flutter/material.dart';
    // Uncomment lines 7 and 10 to view the visual layout at runtime.
    //import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
    
    void main() {
      //debugPaintSizeEnabled = true;
      runApp(new MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        Widget titleSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Row(
            children: [
              new Expanded(
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    new Container(
                      padding: const EdgeInsets.only(bottom: 8.0),
                      child: new Text(
                        'Oeschinen Lake Campground',
                        style: new TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    new Text(
                      'Kandersteg, Switzerland',
                      style: new TextStyle(
                        color: Colors.grey[500],
                      ),
                    ),
                  ],
                ),
              ),
              new Icon(
                Icons.star,
                color: Colors.red[500],
              ),
              new Text('41'),
            ],
          ),
        );
    
        Column buildButtonColumn(IconData icon, String label) {
          Color color = Theme.of(context).primaryColor;
    
          return new Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              new Icon(icon, color: color),
              new Container(
                margin: const EdgeInsets.only(top: 8.0),
                child: new Text(
                  label,
                  style: new TextStyle(
                    fontSize: 12.0,
                    fontWeight: FontWeight.w400,
                    color: color,
                  ),
                ),
              ),
            ],
          );
        }
    
        Widget buttonSection = new Container(
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              buildButtonColumn(Icons.call, 'CALL'),
              buildButtonColumn(Icons.near_me, 'ROUTE'),
              buildButtonColumn(Icons.share, 'SHARE'),
            ],
          ),
        );
    
        Widget textSection = new Container(
          padding: const EdgeInsets.all(32.0),
          child: new Text(
            '''
    Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese Alps. Situated 1,578 meters above sea level, it is one of the larger Alpine Lakes. A gondola ride from Kandersteg, followed by a half-hour walk through pastures and pine forest, leads you to the lake, which warms to 20 degrees Celsius in the summer. Activities enjoyed here include rowing, and riding the summer toboggan run.
            ''',
            softWrap: true,
          ),
        );
    
        return new MaterialApp(
          title: 'Flutter Demo',
          home: new Scaffold(
            appBar: new AppBar(
              title: new Text('Top Lakes'),
            ),
            body: new ListView(
              children: [
                new Image.asset(
                  'images/lake.jpg',
                  width: 600.0,
                  height: 240.0,
                  fit: BoxFit.cover,
                ),
                titleSection,
                buttonSection,
                textSection,
              ],
            ),
          ),
        );
      }
    }
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
    
        var assetsImage = new AssetImage('assets/images/mountain.jpg'); //<- Creates an object that fetches an image.
        var image = new Image(image: assetsImage, fit: BoxFit.cover); //<- Creates a widget that displays an image.
    
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text("Climb your mountain!"),
              backgroundColor: Colors.amber[600], //<- background color to combine with the picture :-)
            ),
            body: Container(child: image), //<- place where the image appears
          ),
        );
      }
    }
    
    我指的是本教程

    此外,我想问,有没有在颤振清洁重建的工具,因为我找不到任何选择这

    任何帮助都将不胜感激


    谢谢大家!

    我认为错误是由冗余的

    颤振:
    
    使用材质设计:true,#问题在于您的
    pubspec.yaml
    ,这里您需要删除最后一个逗号

    uses-material-design: true,
    
    如何在应用程序中包含图像 1.创建一个
    assets/images
    文件夹
    • 这应该位于项目的根目录中,与
      pubspec.yaml
      文件位于同一文件夹中
    • 在Android Studio中,您可以在项目视图中单击鼠标右键
    • 您不必将其称为
      资产
      图像
      。您甚至不需要将
      图像
      作为子文件夹。不过,无论您使用什么名称,都将在
      pubspec.yaml
      文件中注册
    2.将图像添加到新文件夹
    • 您只需将图像复制到
      资产/图像
      。例如,
      lake.jpg
      的相对路径将是
      assets/images/lake.jpg
    3.在
    pubspec.yaml
    • 打开项目根目录中的
      pubspec.yaml
      文件

    • 资产
      子部分添加到
      颤振
      部分,如下所示:

        flutter:
          assets:
            - assets/images/lake.jpg
      
    • 如果要包含多个图像,则可以省去文件名,只使用目录名(包括最终的
      /
      ):

    4.在代码中使用图像
    • 使用
      Image.asset('assets/images/lake.jpg')
      在图像小部件中获取资产

    • 整个
      main.dart
      文件如下:

        import 'package:flutter/material.dart';
      
        void main() => runApp(MyApp());
      
        class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return MaterialApp(
              home: Scaffold(
                appBar: AppBar(
                  title: Text("Image from assets"),
                ),
                body: Image.asset('assets/images/lake.jpg'), //   <--- image
              ),
            );
          }
        }
      
      导入“包装:颤振/材料.省道”;
      void main()=>runApp(MyApp());
      类MyApp扩展了无状态小部件{
      @凌驾
      小部件构建(构建上下文){
      返回材料PP(
      家:脚手架(
      appBar:appBar(
      标题:文本(“来自资产的图像”),
      ),
      
      body:Image.asset('assets/images/lake.jpg'),//将图像放入应用程序的另一种方式(对我来说,就是这样):

      1-创建资源/图像文件夹

      2-将图像添加到新文件夹

      3-在pubspec.yaml中注册资产文件夹

      4-使用以下代码:

       assets:
          - images/lake.jpg
      
      #/properties/flutter/properties/uses-material-design: type: wanted [boolean] got true,
      Error detected in pubspec.yaml:
      Error building assets
      
      FAILURE: Build failed with an exception.
      
      * Where:
      Script '/home/abc/Downloads/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 435
      
      * What went wrong:
      Execution failed for task ':app:flutterBuildDebug'.
      > Process 'command '/home/abc/Downloads/flutter/bin/flutter'' finished with non-zero exit value 1
      
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
      
      * Get more help at https://help.gradle.org
      
      BUILD FAILED in 1s
      Finished with error: Gradle build failed: 1
      
      // Copyright 2017 The Chromium Authors. All rights reserved.
      // Use of this source code is governed by a BSD-style license that can be
      // found in the LICENSE file.
      
      import 'package:flutter/material.dart';
      // Uncomment lines 7 and 10 to view the visual layout at runtime.
      //import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
      
      void main() {
        //debugPaintSizeEnabled = true;
        runApp(new MyApp());
      }
      
      class MyApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          Widget titleSection = new Container(
            padding: const EdgeInsets.all(32.0),
            child: new Row(
              children: [
                new Expanded(
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      new Container(
                        padding: const EdgeInsets.only(bottom: 8.0),
                        child: new Text(
                          'Oeschinen Lake Campground',
                          style: new TextStyle(
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                      new Text(
                        'Kandersteg, Switzerland',
                        style: new TextStyle(
                          color: Colors.grey[500],
                        ),
                      ),
                    ],
                  ),
                ),
                new Icon(
                  Icons.star,
                  color: Colors.red[500],
                ),
                new Text('41'),
              ],
            ),
          );
      
          Column buildButtonColumn(IconData icon, String label) {
            Color color = Theme.of(context).primaryColor;
      
            return new Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                new Icon(icon, color: color),
                new Container(
                  margin: const EdgeInsets.only(top: 8.0),
                  child: new Text(
                    label,
                    style: new TextStyle(
                      fontSize: 12.0,
                      fontWeight: FontWeight.w400,
                      color: color,
                    ),
                  ),
                ),
              ],
            );
          }
      
          Widget buttonSection = new Container(
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                buildButtonColumn(Icons.call, 'CALL'),
                buildButtonColumn(Icons.near_me, 'ROUTE'),
                buildButtonColumn(Icons.share, 'SHARE'),
              ],
            ),
          );
      
          Widget textSection = new Container(
            padding: const EdgeInsets.all(32.0),
            child: new Text(
              '''
      Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese Alps. Situated 1,578 meters above sea level, it is one of the larger Alpine Lakes. A gondola ride from Kandersteg, followed by a half-hour walk through pastures and pine forest, leads you to the lake, which warms to 20 degrees Celsius in the summer. Activities enjoyed here include rowing, and riding the summer toboggan run.
              ''',
              softWrap: true,
            ),
          );
      
          return new MaterialApp(
            title: 'Flutter Demo',
            home: new Scaffold(
              appBar: new AppBar(
                title: new Text('Top Lakes'),
              ),
              body: new ListView(
                children: [
                  new Image.asset(
                    'images/lake.jpg',
                    width: 600.0,
                    height: 240.0,
                    fit: BoxFit.cover,
                  ),
                  titleSection,
                  buttonSection,
                  textSection,
                ],
              ),
            ),
          );
        }
      }
      
      import 'package:flutter/material.dart';
      
      void main() => runApp(MyApp());
      
      class MyApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
      
          var assetsImage = new AssetImage('assets/images/mountain.jpg'); //<- Creates an object that fetches an image.
          var image = new Image(image: assetsImage, fit: BoxFit.cover); //<- Creates a widget that displays an image.
      
          return MaterialApp(
            home: Scaffold(
              appBar: AppBar(
                title: Text("Climb your mountain!"),
                backgroundColor: Colors.amber[600], //<- background color to combine with the picture :-)
              ),
              body: Container(child: image), //<- place where the image appears
            ),
          );
        }
      }
      
      导入“包装:颤振/材料.省道”;
      void main()=>runApp(MyApp());
      类MyApp扩展了无状态小部件{
      @凌驾
      小部件构建(构建上下文){
      
      var assetsmimage=new AssetImage('assets/images/mountain.jpg');//它们不需要创建资产目录和它下面的images目录,然后您就可以放置映像了。 更好的方法是在项目中存在pubspec.yaml的地方创建Images目录,并将图像放入其中 并访问该图像,如教程/文档中所示

      资产:
      -images/lake.jpg//inside pubspec.yaml

      在pubspec.yaml文件中添加资产目录时,请更多地注意空间

      这是错误的

      flutter:
         assets:
          - assets/images/lake.jpg
      
      这是正确的方式,

      flutter:
        assets:
          - assets/images/
      
    • 在项目的根级别创建
      图像
      文件夹

    • 将图像放到这个文件夹中,它应该是

    • 转到您的
      pubspec.yaml
      文件,添加
      assets
      标题并密切注意所有空格

      flutter:
      
        uses-material-design: true
      
        # add this
        assets:
          - images/profile.jpg
      
    • 点击IDE右上角的
      packagesget

    • 现在,您可以使用

      Image.asset("images/profile.jpg")
      

    • 创建与库级别相同的资产目录

      像这样

      projectName
       -android
       -ios
       -lib
       -assets
       -pubspec.yaml
      
      然后你的pubspec.yaml喜欢

        flutter:
        assets:
          - assets/images/
      

      现在您可以使用
      Image.asset(“/assets/images/”)

      在flatter中使用Image。请执行以下步骤

      1.在名为images的资产文件夹中创建一个目录

      2.将所需图像放入图像文件夹

      3.打开pubpsec.yaml文件。然后添加并声明您的图像。例如:--

      4.在代码中使用此图像作为

        Card(
                  elevation: 10,
                    child: Container(
                    decoration: BoxDecoration(
                      color: Colors.orangeAccent,
                    image: DecorationImage(
                    image: AssetImage("assets/images/dropbox.png"),
                fit: BoxFit.fitWidth,
                alignment: Alignment.topCenter,
                ),
                ),
                child: Text("$index",style: TextStyle(color: Colors.red,fontSize: 16,fontFamily:'LangerReguler')),
                      alignment: Alignment.center,
                ),
                );
      

      如果映像位于包依赖项内,则还应提供包名称,如果您正在引用来自同一依赖项的映像,则应提供事件

      Image.asset(“assets/pics/events\u empty.png”,包:“ui\u元素”),
      
      参考:

      谢谢您的回复。我已经创建了资产目录,在该目录中创建了图像目录,并在其中取出了一个图像。还删除了“,”…但是现在得到这个错误
      没有为asset:images/lake.jpg找到任何文件或变体。
      您仍然需要将
      assets
      目录添加到文件路径
      asset:assets/images/lake.jpg
      先生,我还有一个查询..因为我在main.dart中做了一个演示并成功完成了..现在我在同一个文件中做另一个演示e通过删除以前的代码..我得到了新演示的输出,但现在当我检查apk的应用程序时,它显示的是第一个演示,而不是当前的一个..我有什么做错了吗?你可能需要运行
      flatter clean
      来进行
      flatter run
      flatter build
      进行更改。我想flatter团队知道这个问题经常发生,但我不知道他们是否能很快解决。您需要在flift项目目录(where
      pubspec.ya)的命令行shell中执行它