I want to make a custom pagination for swiper in flutter. Where i want to display 2 words in pagination rather then dots or fractions can anyone tell me a better way to do it as in my code i can't change the page on clicking on my custom pagination.
My code:-
Swiper(
controller: swiperController,
itemCount: 2,
itemBuilder: (context,index){
return index==0?A(context):B(context); //Here A and B are 2 pages to swipe between
},
pagination: new SwiperPagination(
margin: new EdgeInsets.all(0.0),
builder: new SwiperCustomPagination(builder:
(BuildContext context, SwiperPluginConfig config) {
return Container(
padding: EdgeInsets.only(bottom: 10),
child: config.activeIndex==0?Text.rich(
TextSpan(text: "",style: TextStyle(color: Colors.white54),children: [
TextSpan(text: "First ",style: TextStyle(fontSize: 25.0,fontWeight: FontWeight.bold),),
TextSpan(text: " Second ",recognizer: TapGestureRecognizer()..onTap=(){},style: TextStyle(fontSize: 17.0,),)
])
):Text.rich(
TextSpan(text: "",style: TextStyle(color: Colors.white54),children: [
TextSpan(text: "First ",style: TextStyle(fontSize: 17.0,),),
TextSpan(text: " Second ",style: TextStyle(fontSize: 25.0,fontWeight: FontWeight.bold),)
])
),
);
})),
),
There could be a better option by using pageview.builder() but if you want to make change in this code then simply use recognizer property of TextSpan.
SwiperCustomPagination(builder:
(BuildContext context, SwiperPluginConfig config) {
return Container(
padding: EdgeInsets.only(bottom: 10),
child: config.activeIndex==0?Text.rich(
TextSpan(text: "",style: TextStyle(color: Colors.white54),children: [
TextSpan(text: "First ",style: TextStyle(fontSize: 25.0,fontWeight: FontWeight.bold),),
TextSpan(
text: " Second ",
recognizer: TapGestureRecognizer()..onTap=(){swiperController.next();},
//added recognizer over here
style: TextStyle(fontSize: 17.0,),)
])
):Text.rich(
TextSpan(text: "",style: TextStyle(color: Colors.white54),children: [
TextSpan(
text: "First ",
recognizer: TapGestureRecognizer()..onTap=(){swiperController.next();},
//added recognizer over here
style: TextStyle(fontSize: 17.0,),
),
TextSpan(text: " Second ",style: TextStyle(fontSize: 25.0,fontWeight: FontWeight.bold),)
])
),
);
})
Related
I need to show the popup menu under the Text but it shows at top of the screen. How can I show it under the Text? I used showMenu() because I can't wrap the text with PopupMenuButton and I didn't find any alternative widget. My Code:
RichText(
text: TextSpan(
style: const TextStyle(
fontSize: 30.0,
color: Colors.black,
),
children: List.generate(
data.length,
(index) => TextSpan(
style: const TextStyle(),
children: [
TextSpan(
text: data[index].transcription + ' ',
style: TextStyle(color: Colors.yellow),
recognizer: TapGestureRecognizer()
..onTap = () async {
await showMenu(
position:
RelativeRect.fromLTRB(
100.0,
100.0,
100.0,
100.0),
context: context,
items: [
PopupMenuItem(
child: Text(data[index].id),
)
],
);
}),
TextSpan(
text: 'end',
)
],
)),
),
),
I'm trying to show a widget onFinished countdown timer but I can't seem to make it work.
I've added var reqPIN = false;
And here is my code:
children [
Countdown(
seconds: 3,
build: (_, double time) =>
RichText(
text: TextSpan(
text: 'Reset PIN in ',
style: TextStyle(
color: Theme.of(context).inputDecorationTheme.labelStyle?.color
),
children: <TextSpan>[
TextSpan(
text: time.toString(),
style: TextStyle(
color: Color(0xFF2481CF),
fontWeight: FontWeight.bold
)),
TextSpan(text: ' sec',
style: TextStyle(
color: Theme.of(context).inputDecorationTheme.labelStyle?.color
))
]
),
),
onFinished: () {
setState(() {
reqPIN = true;
});
},
),
SizedBox(
child: Visibility(
visible: reqPIN,
child: Text('Resend PIN',
style: TextStyle(
color: Colors.black
),),
),
)
]
Is there any solution?
onlySelectedBorderPinPut() is not getting called on setState...
to fix this, you can wrap your RichText with a Column, and add your Resend button there, you won't need to have a reqPin bool for managing the state, simply handle it with the remaining time like below
Countdown(
seconds: 3,
build: (_, double time) => Column(
children: [
RichText(
...
),
Visibility(
visible: time == 0,
child: SizedBox(
child: Text('Resend PIN',
style: TextStyle(color: Colors.black
)
),
),
),
],
),
),
Try this one.
if (reqPIN)
SizedBox(
child: Text('Resend PIN', style: TextStyle(color: Colors.black)),
),
in my flutter book app, I fetch a text from a JSON object and display it in PageView.builder. and after it fetches and displays on the first page and when it goes to the next page it duplicates the first page instead of displaying the remaining text file.
Container(
height: height,
width: width,
child: PageView.builder(
itemBuilder: (context, index){
return RichText(
textDirection: TextDirection.rtl,
text: TextSpan(
text: '',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
for (var i = 1; i <= count; i++) ...{
TextSpan(
text: quran.getVerse(widget.id, i, verseEndSymbol: false),
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
fontFamily: 'kitab'),
),
TextSpan(
text: quran.getVerseEndSymbol(i),
style: TextStyle(
color: Colors.cyanAccent,
fontSize: 26,
fontWeight: FontWeight.bold,
fontFamily: 'kitab',
),
),
}
],
),
);
}),
);
how can I split those text and display it on a page?
How can I tap on the second Text Span area even if it has rich text property? I am new to flutter driver and I found out rich text not supported...
Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 24.0),
child: Text.rich(
TextSpan(
text: s.refill_description,
style: primaryTextTheme.textSmall,
children: [
if (user.paymentDetails?.type == LegalEntityType.private)
TextSpan(
text: s.withdraw_label,
style: primaryTextTheme.textSmall.copyWith(color: FlAppStyles.linkTextColor),
recognizer: TapGestureRecognizer()..onTap = () => showRefundScreen(context),
)
You can do it like this
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Single tap',
style: TextStyle(color: Colors.red[300]),
recognizer: TapGestureRecognizer()..onTap = () {
// Single tapped.
},
),
],
),
)
Using the TextStyle() class in Flutter, how can I strike through an old price?
To apply strikethrough decoration to a Text widget directly:
Text('\$8.99', style: TextStyle(decoration: TextDecoration.lineThrough))
You can also style separate spans of a paragraph by using the RichText widget, or the Text.rich() constructor.
Based on this example code, to show a discounted price:
RichText()
new RichText(
text: new TextSpan(
text: 'This item costs ',
children: <TextSpan>[
new TextSpan(
text: '\$8.99',
style: new TextStyle(
color: Colors.grey,
decoration: TextDecoration.lineThrough,
),
),
new TextSpan(
text: ' \$3.99',
),
],
),
)
Text.rich()
Text.rich(TextSpan(
text: 'This item costs ',
children: <TextSpan>[
new TextSpan(
text: '\$8.99',
style: new TextStyle(
color: Colors.grey,
decoration: TextDecoration.lineThrough,
),
),
new TextSpan(
text: ' \$3.99',
),
],
),
)
style: TextStyle(decoration: TextDecoration.lineThrough),
i use this
Column(
children: [
Text(
"sample text"
),
Divider(color: Colors.red,)
],
),