首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

  • 24-11-26 09:06
  • 2114
  • 43183
juejin.cn

介绍

塔庙的每次在关于或登录页面需要用到logo都需要复制一个资源图到flutter的assets里面,下次改logo了又可能遗漏,干脆直接复用桌面的logo,但是找了一大圈都没人这样搞,好吧,自己动手,你们足食。

flutter_get_native_icon 插件出来了。

用法

  1. 导入插件到项目 打开项目的 pubspec.yaml
yaml
代码解读
复制代码
dependencies: flutter_get_native_icon: ^0.0.3

^0.0.3的话你们可以去 pub-web.flutter-io.cn/packages/fl… 看看最新版本是什么就写什么。

  1. 到dart文件导入包
dart
代码解读
复制代码
import 'package:flutter_get_native_icon/flutter_get_native_icon.dart';
  1. 使用 然后就简单了,直接用
less
代码解读
复制代码
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('App Icon Display'), ), body: Center(child: NativeAppIconWidget()), ); }

注意

别用 icons_launcher 去生成icon,生成之后是无法显示出组件的,具体看github.com/mrrhak/icon… 等作者修复。

推荐使用flutter_launcher_icons

属性

我就不翻译了,dddd【懂的都懂】

  • width: The width of the icon.
  • height: The height of the icon.
  • fit: How the icon should be inscribed into the space allocated during layout.
  • colorBlendMode: The blend mode applied to the icon.
  • color: The color to use when drawing the icon.
  • opacity: The opacity to apply to the icon.
  • alignment: How to align the icon within its bounds.

获取桌面的app名字

因为package_info_plus插件有了就不额外处理了。

dart
代码解读
复制代码
Future<void> _loadAppInfo() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); setState(() { appName = packageInfo.appName; }); }

完整demo

dart
代码解读
复制代码
import 'package:flutter/material.dart'; import 'package:flutter_get_native_icon/flutter_get_native_icon.dart'; class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('App Icon Display'), ), body: Center(child: NativeAppIconWidget()), ); } } void main() { runApp(MaterialApp( home: MyHomePage(), )); }

开源地址

github.com/fluttercand…

里面有demo,可以直接运行,环境flutter 3.24.3

效果图

image.png

最后一句

flutter candies牛逼

注:本文转载自juejin.cn的CrazyQ1的文章"https://juejin.cn/post/7439950923587207178"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

140
Android
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top