开发过程中,有些图片是要放到本地资源文件中,然后本地加载,这样做需要两个步骤就可以实现

1.创建本地资源文件夹Images,然后添加图片 1.jpg,  2.jpg

2.配置pubspec.yaml 中的资源路径,必须配置,如果不配置,在程序中图片就会加载不出来

3.使用 Image.asset("images/1.jpg",width:500,height:50) 加载图片

pubspec.yaml配置

name: demoone
description: A new Flutter project.# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1environment:sdk: ">=2.0.0-dev.68.0 <3.0.0"dependencies:flutter:sdk: flutter# The following adds the Cupertino Icons font to your application.# Use with the CupertinoIcons class for iOS style icons.cupertino_icons: ^0.1.2dev_dependencies:flutter_test:sdk: flutter# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec# The following section is specific to Flutter.
flutter:# The following line ensures that the Material Icons font is# included with your application, so that you can use the icons in# the material Icons class.uses-material-design: true# To add assets to your application, add an assets section, like this:assets:- images/1.jpg- images/2.jpg# An image asset can refer to one or more resolution-specific "variants", see# https://flutter.io/assets-and-images/#resolution-aware.# For details regarding adding assets from package dependencies, see# https://flutter.io/assets-and-images/#from-packages# To add custom fonts to your application, add a fonts section here,# in this "flutter" section. Each entry in this list should have a# "family" key with the font family name, and a "fonts" key with a# list giving the asset and other descriptors for the font. For# example:# fonts:#   - family: Schyler#     fonts:#       - asset: fonts/Schyler-Regular.ttf#       - asset: fonts/Schyler-Italic.ttf#         style: italic#   - family: Trajan Pro#     fonts:#       - asset: fonts/TrajanPro.ttf#       - asset: fonts/TrajanPro_Bold.ttf#         weight: 700## For details regarding fonts from package dependencies,# see https://flutter.io/custom-fonts/#from-packages

程序代码

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(title: 'Flutter Positioned布局控件',home: Scaffold(appBar: AppBar(title: Text("Flutter资源图片"),),body: new Column(mainAxisAlignment: MainAxisAlignment.start,children: <Widget>[new Expanded(child:Image.asset("images/1.jpg",width:500,height:50) ,),new Expanded(child:Image.asset("images/2.jpg",width:500,height:100) ,)],)));}
}

Flutter入门学习--(18)添加本地资源图片相关推荐

  1. Android 将本地资源图片转换成Drawable,进行设置大小

    前言: 因为项目中显示图片是用Picasso,设置placeholder和error图片的时候发现,本地图片的大小无法满足我的需求,需要先对图片大小改变再显示. Picasso的placeholder ...

  2. android 获取drawable 对象,Android 实现将本地资源图片转换成Drawable的方法

    Android 实现将本地资源图片转换成Drawable的方法 发布时间:2020-11-06 16:37:09 来源:亿速云 阅读:255 作者:Leah 这篇文章将为大家详细讲解有关Android ...

  3. 微信小程序 本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64,或者使用image标签。

    微信小程序不能使用background-image问题解决. 报错信息: pages/index/index.wxss 中的本地资源图片无法通过 WXSS 获取,可以使用网络图片,或者 base64, ...

  4. 入门学习爬取贴吧图片(附完整代码),2021/1/27有效

    记录一下爬虫学习爬取贴吧图片,按照以下b站视频教学,2021/1/27亲测有效,不会被封ip. Python爬虫实战讲解:爬取百度贴吧全站图片 结果如下(手动打码): 源代码和笔记如下: #多页爬取' ...

  5. iOS WebView 加载本地资源(图片,文件等)

    NSString *path = [[NSBundle mainBundle] pathForResource:@"关于.docx" ofType:nil]; NSURL *url ...

  6. Flutter 入门学习(五)— Material Design风格组件

    文章目录 1. 概述 2. App结构和导航组件 2.1 MaterialApp(应用组件) 2.1.1 设置主页 2.1.2 路由处理 2.1.3 自定义主题 2.2 Scaffold(脚手架组件) ...

  7. Flutter入门学习--(16)布局定位控件Positioned

    Positioned控件主要用来设置绝对布局,必须配合Stack控件来使用, Positioned控件 通过设置left和top属性可以设置控件的绝对位置 import 'package:flutte ...

  8. 博弈入门学习的博客[资源汇总]

    kuangbin的博弈论 kuangbin的博弈论题解 kuangbin博弈论题单 博弈大佬的博客 博弈论题单 分割形博弈 SG函数

  9. 微信小程序 - “本地资源图片无法通过WXSS 获取,可以使用网络图片,或者 base64,或者使用标签” 解决

    报错过程 index.wxml <view class="bg"></view> index.wxss .bg {background:url('/imag ...

  10. android 点动态显示图片,Android用RecyclerView实现动态添加本地图片

    本文介绍了Android用RecyclerView实现动态添加本地图片,分享给大家,具体如下: 简单介绍一下用法: 1.跳转到图片选择页面: Intent intent = new Intent(Pa ...

最新文章

  1. Spring基础专题——第十章(基础注解编程——下)
  2. Navicat Premium 11.1.9在Linux系统下的安装
  3. 【杂谈】我在有三AI从学生到老师
  4. 给工厂分配销售组织/分销渠道
  5. 在C#2.0中使用Nullable可空类型(转帖)
  6. 32tomcat的目录结构
  7. 机器学习recall含义_机器学习的业务含义
  8. memcache使用方法测试
  9. 【小项目】Axios 实现前后端交互
  10. android升序降序按钮,创建一个按钮,将排序MYSQL查询升序和降序
  11. java8 lambda表达式Stream对List常用操作总结
  12. Linux的10个经典彩蛋
  13. QQ群技术:0成本创建2000人QQ群技巧
  14. 在jsp代码添加背景图片
  15. 陀螺仪、加速计、磁力计
  16. HBuilder打包
  17. Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)
  18. 2019 HZNU Winter Training Day 14 Comprehensive Training
  19. 让您的照片动起来first motion model(1)-关键点抽取模型深度解析
  20. Vue的快速入门通俗易懂(学习笔记)

热门文章

  1. mysql 在线优化工具_MySQL SQL查询优化工具EverSQL
  2. 计算机组成原理(白中英) 第三章 课后题答案
  3. 【Java】JavaSE JDK 及离线帮助文档下载链接
  4. sd卡写保护解除工具_手把手教你快速解除vivo手机高通系列屏幕锁(附短接拆机小视频)...
  5. vscode - 设置 Python 版本
  6. 全网最细JAVA窗口背景图片设置
  7. 《Perl语言入门》
  8. NetSpeedMonitor
  9. java Json转string方法
  10. Goto是关键?思考