131232134cfeaf23
131232134cfeaf23

Reputation: 11

Can I use an Icon by passing a string in a text widget like Html? flutter

I am trying to make a text which contains an icon. I found out Icon has a kind of code inside. Is it possible to get an icon by passing the code in a text? like Html does. Or should I use textspan and richtext?

 static const IconData logout = IconData(0xe848, fontFamily: 'MaterialIcons');

this is icons.dart in flutter

<input type="submit" class="search-submit" value="&#xf002;" />

In Html.

I would like to get a material icon by using the code in icons.dart. I think if there is a way to implement an icon in text widget. Its gonna be an easier way than to use richtext.

Iconbutton may work but my text is in already inkwell widget(the container widget is wrapped with an inkwell). I have some memos which contain tags. And I would like to show tags with an icon before getting in content screen. So like this Text(icon + memo.tags.join(icon)) I am trying to add the text in the column.

Container(
                width: MediaQuery.of(context).size.width,
                height: 120,
                child: Row(
                  children: [
                    setImage(memo.imageByte),
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.all(8.0),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Text(
                              memo.title == null ? "" : memo.title,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  fontSize: 32, fontWeight: FontWeight.bold),
                            ),
                            Text(
                              memo.content == null ? "" : memo.content,
                              maxLines: 4,
                              overflow: TextOverflow.ellipsis,
                            ),
                            Text(
                              memo.editTime.split('.')[0],
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),

Upvotes: 0

Views: 519

Answers (1)

Janvi Patel
Janvi Patel

Reputation: 252

You can simply use named constructors for creating different types of buttons with icons. For instance

    FlatButton.icon(
     onPressed: null, 
     icon:  icon: Icon(Icons.add), 
      label: Text("Submit")
);

Upvotes: 1

Related Questions