Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

flutter - Add custom icon

Hi i am using the library : convex_bottom_bar to create my bottom bar

    StyleProvider(
  style: Style(),
  child: ConvexAppBar(
    initialActiveIndex: 1,
    height: 50,
    top: -30,
    curveSize: 100,
    style: TabStyle.fixedCircle,
    items: [
      TabItem(icon: Icons.link),
      TabItem(icon: Icons.import_contacts),
      TabItem(title: "2020", icon: Icons.work),
    ],
    backgroundColor: _tabBackgroundColor,
  ),
)

However, i want to change the icon and add my custom icon, i try this but it doesn' t work:

icon: index==1?new Image.asset('images/1.0x/icon2.png'):new Image.asset('images/1.0x/newIcon.png'),

Any idea how to do it ?

Thanks

question from:https://stackoverflow.com/questions/65842066/add-custom-icon

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have two options here you could either use some kind of font file for your icons which might in general be the better way because of various reasons such as app size and image scaling issues or you could use image files such as .png or .svg. You should have that in mind.

Looking at your code snippet it looks like you want to use image files. In convex-bottom-bar tab items are generic type since version 1.3.1 so both IconData and Widget can be used (see 1.3.1).

That means something like the following is possible:

TabItem(
        icon: Container(
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        color: Color(0xFFFF5722),
      ),
      child: Icon(Icons.add, color: Colors.white, size: 40),
    )), 

See this example example for more information.

So just replace the IconData with your Image widget and it should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...