0

I am new to flutter and trying to build a text field with basic options just as in word (underlineing, changing fontsize and weight,...)

I was able to write a code for changing the font size and I tried the same for font weight, but i wasn´t able to make it work. As I am also new to Stackoverflow I am having troubles with inserting my working code properly...

So my question is, if you could share your version of changing the fontweight of a text in a textfield via buttons just like in word.

Thank you!

Toby
  • 5
  • 2
  • See solution from [this answer](https://stackoverflow.com/questions/52132135/how-to-use-a-custom-font-style-in-flutter). – fartem Jan 18 '21 at 19:35

2 Answers2

0

You can change fontweight of the textfield by using style property of Textfield TextField( .... style: fontweight=Fontweight.bold), ...

ygzkrmtc
  • 177
  • 12
0

Firstly, use stateful widget, then make variable:

bool isBold = false;

Then use a Text widget like this:

Text(‘hello’, style: TextStyle(fontWeight: isBold ? FontWeight.bold : FontWeight.normal))

Next you need a button for user to toggle fontweight option:

MaterialButton(onPressed: () => setState(() => isBold = !isBold))
pasty
  • 380
  • 2
  • 8