Is there a way to display Text in small caps in Flutter? - flutter

I'm searching for a way to display a Google Font in small caps.
I'm using the google_fonts package.

You can use the FontFeature property inside a TextStyle like this:
Text('This is a Google Font',
style: GoogleFonts.lato(
textStyle: TextStyle(fontFeatures:[FontFeature.enable('smcp')], color: Colors.blue, letterSpacing: .5),
//smcp as in small caps
),
),

Related

Why do parts of TextStyle trickle down the widget-tree while others don't?

I am fairly new to flutter and just stumbled across something that seems odd to me with regards to how style is affecting widgets further down the tree.
Consider the following example:
ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: const TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
color: Colors.red,
)
),
onPressed: () { print("testados"); },
child: const Text(
"some testadorian text",
style: TextStyle(color: Colors.red),
),
);
I could verify that changing fontSize and fontWeight in lines 4 and 5 did produce the
expected effect. But setting the color inside the textStyle of ElevatedButton.styleFrom didn't have any visible effect at all.
Setting the color inside style of Text did produce the expected result.
What I understood so far was that Text-widgets take what is available as default-theming further up the widget tree and override those defaults when a specific property is directly set on themselves.
What am I missing out to understand this behaviour?

How to localize text with TextSpan widget?

I am using Flutter Intl android studio plugin for ready made localization.
But in my scenario i have the widget like this,
Text.rich(
TextSpan(
text: 'It is time to',
children: [
TextSpan(
text: 'Stay Relaxed',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
)
So how can i translate a single message "It is time to Stay Relaxed" and use in Text.rich widget?
EDIT: More explanation
The text can not be handled as one piece. Each part of needs to be handled separately. Because from the TextSpans concern, those are different texts. So you need to create two different texts within the arb file.
From the Flutter Intl's perspective, these are two different components. TextSpan has its own drawing perspective. That is why you need to create two different components for these items.
There are packages out there like https://pub.dev/packages/localized_rich_text but I did not use it. In our app I use it like the following.
Flutter Intl creates the localized elements as follows:
AppLocalizations.of(context).tranlatedElement;
//or
AppLocalizations.current.tranlatedElement;
So your Code should be like the following
Text.rich(
TextSpan(
text: AppLocalizations.current.relaxTextPrefix,
children: [
TextSpan(
text: AppLocalizations.current.relaxTextSuffix,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
),
)

How to animate TextSpan or part of a text in Flutter like in this game screenshot?

Do you have any pointers on how to animate TextSpan or part of a text in Flutter to achieve the same effect than in this game screenshot?
I know how to animate a whole text with typewriter effect but not how to animate only part of the text.
Any help will be appreciated. Thanks so much!
There are packages that can do that, for example https://www.geeksforgeeks.org/animated-text-in-flutter/ using the animated_text_kit
AnimatedTextKit(
animatedTexts: [
TyperAnimatedText('This is Animated text,',
textStyle: const TextStyle(
color: Colors.white,
fontSize: 30,
backgroundColor: Colors.purple)),
TyperAnimatedText('You are viewing it here.',
textStyle: const TextStyle(
fontSize: 20, fontWeight: FontWeight.bold)),
],
onTap: () {
print("I am executing");
},
),

Text underline display line above text instead of below

As showing the given image After applying underline decoration text style to the text it shows line above text instead of below in flutter 2.2.
TextButton(
onPressed: () {},
child: Text(
getLocalValue(context, txtTermsNConditions),
style: TextStyle(
fontSize: 12.sp,
fontWeight: fwMedium,
color: Color(clrPrimary),
decoration: TextDecoration.underline),
),
)
style: TextStyle(decoration: TextDecoration.overline) will do the trick see this link for more information.
You can do with a shortcut just use a Stack and place both Text and a Divider Widget in it and gave then position according to your Requirements that's all.
That was a problem with fonts I have used, using another font it has been resolved.

Is there a way to paint inside the text in Flutter?

I am currently working on the Flutter package and want to add an outlined wavy liquid text as below.
Is there any feature to add this in the Text widget?
there is this flutter package animated_text_kit 2.2.0. Which could be used to give a wavy animation to the text. I am leaving the link down below
https://pub.dev/packages/animated_text_kit
width: 250.0,
child: TextLiquidFill(
text: 'LIQUIDY',
waveColor: Colors.blueAccent,
boxBackgroundColor: Colors.redAccent,
textStyle: TextStyle(
fontSize: 80.0,
fontWeight: FontWeight.bold,
),
boxHeight: 300.0,
),
);