fill the spaces of a paragraph in flutter - flutter

i'm stuck trying to design a text widget that have empty Text Field like below:
If you have an idea how to do this, I would be grateful

You can use rich text to achieve this
RichText(
text: TextSpan(
children: [
TextSpan(text: "some really big text which will have a textfield like this"),
WidgetSpan(child: Container(
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.orange
),
child:TextField(
style:TextStyle(fontSize:12))
)),
TextSpan(text:" to enter some text in between a text"),
]
)
)
You may have to align items. But this should work

Center(
child: RichText(
text: TextSpan(
text:
'Grout crack happens mainly due to movement between two surfaces. It can be as a ',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.bold),
children: [
TextSpan(
text: 'thin',
style: TextStyle(
color: Colors.red,
fontSize: 35,
fontStyle: FontStyle.italic)),
TextSpan(
text: ' of humidity',
style: TextStyle(color: Colors.black, fontSize: 40)),
]),
),
),

Related

make space between TextSpan

I am trying to make space between TextSpan
What is the best way to add space between TextSpan?
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
SizedBox widget can be used in between two widgets to add space between two widgets.
use the SizedBox by wrapping it with a WidgetSpan widgit
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(
child: SizedBox(width: 10),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
If you like to get maximum space between text, you might go for Row widget. For x amount of space inside RichText you can use
TextSpan(...),
WidgetSpan(child: SizedBox(width: x)),
TextSpan(...),
RichText(
text: const TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(child: SizedBox(width: 10)), ///this
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
You can use the height property on the TextStyle to create some spacing:
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
height: 1.5, //USE THIS PROPERTY
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
SizedBox(height: 10),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
More info in the docs: https://api.flutter.dev/flutter/painting/TextStyle/height.html

How Can I make a TextWidget wrap in Row?

How Can I make the orange text break to the start of the row instead of breaking to the start of itself?
TextWidget Wrap in Row:
If you use Richtext like that:
return Container(
height: 175,
width: 150,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: const EdgeInsets.only(left: 25, top: 100,),
child: RichText(
text: const TextSpan(children: <TextSpan>[
TextSpan(
text: 'I agree with the ',
style: TextStyle(
color: Colors.black,
fontSize: 12,
),
),
TextSpan(
text: 'privacy_policiesfkads;ljfklas;dj',
style: TextStyle(
color: Colors.orange,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
]))));
you should be able to achieve everything you want in terms of design and scaling and also positioning...
Why don't just use RichText instead of Row? Less code, more possibilities.

WidgetSpan is not proper align in Flutter

I want to set a black heart between "m" and "ms". and also I want to use "TextAlign.justify". if I use "TextAlign.center" then it's working fine. but if I use "TextAlign.justify" so the black heart is not set in the correct place. If I remove the "WidgetSpan" widget and add "TextSpan" for a black heart so also it's working. but I want to add bottom padding.
Please guys help me.
Thanks
Text.rich(
TextSpan(
children: <InlineSpan>[
TextSpan(
text: MyString.txtAboutUs ,
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_regular)),
TextSpan(
text: " m",
children: <InlineSpan>[
WidgetSpan(
baseline: TextBaseline.ideographic,
alignment: PlaceholderAlignment.top,
child: Container(
padding: EdgeInsets.only(bottom: 3),
child: Text("🖤", style: TextStyle(
fontSize: FontSize.size8,
fontFamily: MyFont.poppins_regular) ),
)
),
TextSpan(
text: "ms ",
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_medium,
color: Colors.black,
fontWeight: FontWeight.bold)),
],
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_medium,
color: Colors.black,
fontWeight: FontWeight.bold)),
TextSpan(
text: MyString.txtAboutImmediately,
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_regular)),
],
),
textAlign: TextAlign.justify,
),
Try to below simple Text Widget
Text('you add 🖤 here'),
// OR
Text('you add \u{2764} here} '),
Updated Answer using RichText
Center(
child: Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: 'You add ',
style: TextStyle(
fontSize: 10.0,
color: Colors.black,
),
),
TextSpan(
text: '🖤',
),
TextSpan(
text: 'Here',
),
],
),
textAlign: TextAlign.center,
style: TextStyle(fontSize: 10.0,),
),
),
Screen like
replace padding with transform.
WidgetSpan(
baseline: TextBaseline.ideographic,
alignment: PlaceholderAlignment.top,
child: Container(
transform: Matrix4.translationValues(0, -3, 0),
margin: EdgeInsets.only(bottom: 8),
child: Text(
"🖤",
style: TextStyle(
// fontSize: FontSize.size8,
// fontFamily: MyFont.poppins_regular,
),
),
),
),

Flutter how to screen just list in a bottom sheet

I am showing a simple list view builder in bottom sheet like this
showModalBottomSheet(
context: context,
builder: (BuildContext bc){
return SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 16.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Select ',
style: new TextStyle(
fontSize: 16,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: 'Patient',
style: TextStyle(
fontSize: 16,
fontFamily: 'PoppinsRegular', color: textGreyColor)),
],
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 13),
child: Container(
height: MediaQuery.of(context).size.height * 0.08,
width: MediaQuery.of(context).size.width * 0.92 ,
child: TextFormField(
onChanged: (value) {
},
onSaved: (value) {},
style: TextStyle(
fontSize: 15,
color: kPrimaryColor,
fontFamily: 'UbuntuRegular'),
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide:
const BorderSide(color: Color(0xffbdbdbd), width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
enabledBorder: new OutlineInputBorder(
borderSide:
const BorderSide(color: Color(0xffbdbdbd), width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(
color: Color(0xffbdbdbd), fontFamily: 'UbuntuRegular'),
hintText: "Search",
fillColor: Colors.white70,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: kPrimaryColor, width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
),
),
),
),
Container(
child: new ListView.builder(
itemCount: 8,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(bottom: 10, left: 15, right: 15),
child: Container(
child: GestureDetector(
// onTap: widget.onPressed,
onTap: () {},
child: Stack(children: [
Container(
width: double.infinity,
padding: EdgeInsets.all(15.0),
margin: EdgeInsets.only(bottom: 15.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: kPrimaryColor,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Name : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: 'Hamza Tariq',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular', color: textGreyColor)),
],
),
),
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Contact : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: '03323789263',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular', color: textGreyColor)),
],
),
),
],
),
SizedBox(height: 8.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Gender : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: 'Male',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular', color: textGreyColor)),
],
),
),
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Reg Date : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: '12-MAY-2021',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
],
),
SizedBox(height: 8.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Patient ID : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: 'C-200',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Email : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: 'abc.33#hotmail.com',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
],
),
],
),
),
]),
),
),
);
},
)
,
)
],
),
);
}
);
The issue is when i scroll the search bar and my header is also scrolling because I add SingleChildScrollView on the whole bottom sheet. What I need to do is I need to just scroll the listView not the whole content inside the bottom sheet. If I remove SingleChildScrollView from the bottom sheet it's showing an overflow error. Need to know what can I do here so I can get a scrollable listView with a sticky search bar and header.
Remove SingleChildScrollView and add Expanded on ListView.builder like this:
Dartpad to run the code online.

flutter richtext separated align

i see this code for rich text in flutter:
return Row(
children: <Widget>[
?
Container(
child: RichText(
text: TextSpan(
text: "Hello",
style: TextStyle(fontSize: 20.0,color: Colors.black),
children: <TextSpan>[
TextSpan(text:"Bold"),
style: TextStyle( fontSize: 10.0, color: Colors.grey),
),
],
),
),
)
this print
Hellobold
but i need to separe both text one aling to left other to right, like this
Hello bold
how i do this?
thanks
I don't know your exact Use Case - But One way of getting what you require:
Row(
children: <Widget>[
Expanded(
child: RichText(
text: TextSpan(children: [
TextSpan(text: 'Singh', style: TextStyle(fontSize: 22.0,color: Colors.grey))
])),
),
RichText(
text: TextSpan(children: [
TextSpan(text: 'Kaur', style: TextStyle(fontSize: 28.0,color: Colors.redAccent))
])),
],
),
if you want to use textalign in RichText use WidgetSpan and Text widget
WidgetSpan(
child: Text(
'your text',
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
),
),
I think this will can help you:
RichText(
text: TextSpan(
children: [
WidgetSpan(
child: Padding(
padding: const EdgeInsets.fromLTRB(1, 10, 10, 0),
child: Icon(
Icons.developer_mode_sharp,
),
),
),
TextSpan(
text: ' Tinkle is Powered By:',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black),
),
],
),
),
Text(
'Together Marketing Agency',
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 16, color: Colors.black, fontWeight: FontWeight.w500),
),
To Align your Text when using RichText widget, Simply add textAlign: TextAlign() to your RichText Property.
return Row(
children: <Widget>[
?
Container(
child: RichText(
textAlign: TextAlign.justify //You can change it to any aligment style that you want.
text: TextSpan(
text: "Hello",
style: TextStyle(fontSize: 20.0,color: Colors.black),
children: <TextSpan>[
TextSpan(text:"Bold"),
style: TextStyle( fontSize: 10.0, color: Colors.grey),
),
],
),
),
)
Container(
width: double.infinity,
child: Text.rich(
TextSpan(
text: 'This is a ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(
text: 'bold',
style: TextStyle(fontWeight: FontWeight.bold),
recognizer: TapGestureRecognizer()
..onTap = () {
// Handle the tap event
},
),
TextSpan(text: ' and normal text'),
],
),
textAlign: TextAlign.center,
),
)