栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

flutter图片显示的几种方式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

flutter图片显示的几种方式

一.本地图片加载

1.在项目根目录下创建名为 images文件夹,也可以将images放在asserts文件夹下

2.在pubspec.yaml中配置images相关的路径,并执行pub get 使配置的文件生效

1).根目录下创建的images文件夹

# 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/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  assets:
      - images/jon.jpg //images和-之间有个空格 

2).asserts下创建的images文件夹

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/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  assets:
      - assets/images/jon.jpg //assets和-之间有个空格 

3.在代码中使用本地图片

1).Image(image: AssetImage('images/jon.jpg’)

2).Image.asset('images/jon.jpg’)

3).依赖包中的资源图片: new AssetImage('images/jon.jpg', package: 'my_icons')

4.demo展示

class MyLayoutApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {

    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: 10.0),
            child: new Text(
              label,
              style: new TextStyle(
                fontSize: 16.0,
                fontWeight: FontWeight.w400,
                color: color,
              ),
            ),
          ),
        ],
      );
    }

    var stack = Stack(
      alignment: Alignment.center,
      children: [
        CircleAvatar(
          backgroundImage: const AssetImage('images/jon.jpg'),
          radius: 100.0,
        ),
        Container(
          decoration: const BoxDecoration(
            color: Colors.black45,
          ),
          child: Text(
            'Jon A',
            style: const TextStyle(
              fontSize: 30.0,
              fontWeight: FontWeight.bold,
              color: Colors.white,
            ),
          ),
        ),
      ],
    );
    return stack;

  }

}

二.网络图片加载

1.加载方式:Image.network('https://...')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/731514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号