how to copy custom text in flutter to clipboard? - flutter

need a way to copy a custom text that i give it a font-style and other styles if possible in my flutter app, currently while working on my app i can copy the text i want to clipboard and use it later but with out any style.
this is how now i copy the text which dont work for me the way i want.
ClipboardData data = ClipboardData(text:sample);
Clipboard.setData(data);`
this is how i can copy the default text but insted i want to copy a custom text like next.
Text(
sample,
style: TextStyle(
fontSize: 20,
fontFamily: IndieFlower,
),
)`

Related

how can I use both sub font family in my app?

I am using font-family called "FFShamelFamily". I added two sub-font families as shown in the picture below. When I run my app, it uses the first sub-fontFamily: "SansOneBook" only. I try to use fontWeight to make use of the second sub-fontFamily:"SansOneBold" but it doesn't show. I mean that I want to use both of the sub-FontFamily, the bold one for titles and the other one for any text in the app. How can I do it?
When using a custom font you need to specify which FontFamily to use on a TextStyle. Your “sub” font FFShamelFamily-SansOneBold is correctly set up in your pubspec.yaml as a weight variation of the same Font Family.
To use it in a textStyle you simply have to use the weight you set it to with the correct family name:
Text(
“Hello, world”,
style: TextStyle(
fontFamily: “FFShamelFamily”,
fontWeight: FontWeight.w900,
),
)
Please check the official flutter documentation for using custom fonts to learn more.

Lost Connection to device as soon as I used custom fonts

This is the code inside the .YML file
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- Images/
fonts:
- family: Pacifico
fonts:
- asset: Fonts/Pacifico-Regular.ttf
and this is the part that I added before losing connection and crashes.
Text(
'Abdulrahman Hejazi',
style: TextStyle(
fontSize: 25,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Pacifico'
),
),
I noticed something, that If I build (run) the project from the start it crashes, but if I hot reload it, it works just fine.
you need to rename asset folder Fonts to lower case fonts because capital letters are not allowed in folder names
It may be either of the following:
Your font file name has space on it. If yes remove it.
Your font file name may be misspelled.
Your font file may be corrupted.Try adding new one.
PS. does it load the font when hot reload or it doesn't?

How to use GoogleFonts as default fonts in flutter app?

I'm using GoogleFonts api in my flutter app but right now I am setting the fontStyle for every text manually to GoogleFonts.roberto but I want to set that as default in ThemeData in main.dart. But the fontFamily: GoogleFonts.roberto throws an error saying expected an string value so how can I achive that?
You can use it like this to make or modify an entire text theme to use the "Roboto" font as mentioned in their official document:
MaterialApp(
theme:ThemeData(
textTheme: GoogleFonts.robotoTextTheme(
Theme.of(context).textTheme,
),
);

Flutter Text misaligned but textBaseline does not fix it

When trying to underline a mix of English and Japanese (or Chinese or Korean), the underline is not aligned, even when textBaseline is set to ideographic.
Code used to produce the above image:
Text(
"可愛い lovely",
style: TextStyle(
fontSize: 48,
decoration: TextDecoration.underline,
textBaseline: TextBaseline.ideographic,
),
),
I thought the main purpose of ideographic text baseline is to address problems like this, but it made no visible differences. How should textBaseline be used then? And, is there any way to solve the underline misalignment issue in this case?
Edit:
Thanks to user #AnasMohammed pointing out the issue cannot be reproduced on DartPad, I then tried both Android and iOS. Seems like the problem only exists on Android. Sample results and "full code" available: https://i.imgur.com/jOeO5th.png

Flutter : Restrict price localization to english only

My app supports two localizations 1] English 2] Arabic. Localization is working perfectly throughout the app.
But there are certain scenarios where I need to show text only in the English language but app changing it to as per selected localization. So all prices are shown in Arabic for Arabic localization.
I tried to put explicit Locale (NOT sure whether it is supposed to do like this) in a Text widget but still, that didn't work for me.
Text('3434', // Dynamic String from server
locale: Locale('en'),
style: TextStyle(fontSize: 16))
Actual Result When Arabic Localization is selected :
Expected Result :
set font-family specifically to those texts that doesn't need the arabic font. That way, it will override the default one.
We need to set fontFamily to Text Widget to whichever language-specific you want. For me, I just set the fontFamily like this,
Text(
value,
style: TextStyle(fontSize: 16, fontFamily: 'OpenSans'),
),
Hope this will be useful for someone.
Text(item.price, textDirection: TextDirection.ltr,) will make the TextDirection to be always in English 'ltr' left to right.
I hope that helps.