Open insinfo opened 1 month ago
You should remove the Row. You can replace the Container by a Padding too.
Try this one:
// pw.Row(
// mainAxisAlignment: pw.MainAxisAlignment.start,
// crossAxisAlignment: pw.CrossAxisAlignment.start,
// children: [
// pw.Container(
// width: double.infinity,
// padding: pw.EdgeInsets.fromLTRB(150, 0, 0, 0),
// child:
pw.Padding(padding: pw.EdgeInsets.fromLTRB(150, 0, 50, 0),
child:
pw.RichText(
textDirection: pw.TextDirection.ltr,
textAlign: pw.TextAlign.justify,
// softWrap: true,
maxLines: 10,
text: pw.TextSpan(
style: bodyTextStyle,
children: [
pw.TextSpan(
style: strongTextStyle,
text: 'Certificamos que ',
),
pw.TextSpan(
style: strongTextStyle,
text: nomeCandidato.toUpperCase(),
),
pw.TextSpan(
style: bodyTextStyle,
text: ' concluiu com aproveitamento o curso ',
),
pw.TextSpan(
style: strongTextStyle,
text: nomeCurso.toUpperCase(),
),
pw.TextSpan(
style: bodyTextStyle,
text: ' do Programa Municipal de Qualificação Profissional de Rio das Ostras, ministrado pela Secretaria de Gestão Pública, perfazendo um total de ',
),
pw.TextSpan(
style: strongTextStyle,
text: '102 horas/aula.',
),
]) //) ),
), ),
The output:
Note this in your code:
import 'package:pdf/pdf.dart' as pw; // <-- pw HERE
import 'package:pdf/widgets.dart' as pw; // <-- pw HERE TOO
Thanks for the help, that works, the only problem with this approach is that if you need to put something next to the text you will need a Row and then the problem will happen again.
In this case I think you can use a WidgetSpan or a Row combined with Flexible.
For example:
pw.Padding(
padding: pw.EdgeInsets.fromLTRB(150, 0, 50, 0),
child:
pw.RichText(
textDirection: pw.TextDirection.ltr,
textAlign: pw.TextAlign.justify,
// softWrap: true,
maxLines: 10,
text: pw.TextSpan(
style: bodyTextStyle,
children: [
pw.WidgetSpan(
child: pw.Icon( pw.IconData( 0xe87d ) ),
),
pw.WidgetSpan(
child: pw.Text( ' WidgetSpan '),
),
pw.TextSpan( style: strongTextStyle, text: 'Certificamos que ', ),
pw.TextSpan( style: strongTextStyle, text: nomeCandidato.toUpperCase(), ),
pw.TextSpan( style: bodyTextStyle, text: ' concluiu com aproveitamento o curso ', ),
pw.TextSpan( style: strongTextStyle, text: nomeCurso.toUpperCase(), ),
pw.TextSpan( style: bodyTextStyle, text: ' do Programa Municipal de Qualificação Profissional de Rio das Ostras, ministrado pela Secretaria de Gestão Pública, perfazendo um total de ', ),
pw.TextSpan( style: strongTextStyle, text: '102 horas/aula.', ),
]) //) ),
), ),
pw.SizedBox(height: 20),
pw.Padding( padding: pw.EdgeInsets.fromLTRB(100, 0, 50, 0),
child:
pw.Row( children: [
pw.Icon( pw.IconData( 0xe87d ) ),
pw.Text( ' Text '),
pw.Flexible(child:
pw.RichText(
textDirection: pw.TextDirection.ltr,
textAlign: pw.TextAlign.justify,
// softWrap: true,
maxLines: 10,
text: pw.TextSpan(
style: bodyTextStyle,
children: [
pw.TextSpan( style: strongTextStyle, text: 'Certificamos que ', ),
pw.TextSpan( style: strongTextStyle, text: nomeCandidato.toUpperCase(), ),
pw.TextSpan( style: bodyTextStyle, text: ' concluiu com aproveitamento o curso ', ),
pw.TextSpan( style: strongTextStyle, text: nomeCurso.toUpperCase(), ),
pw.TextSpan( style: bodyTextStyle, text: ' do Programa Municipal de Qualificação Profissional de Rio das Ostras, ministrado pela Secretaria de Gestão Pública, perfazendo um total de ', ),
pw.TextSpan( style: strongTextStyle, text: '102 horas/aula.', ),
]) //) ),
), ), ] ), ),
Output:
with the RichText widget the text is not breaking the line and adjusting with the textAlign justify
pdf: ^3.11.0
pdf_test.pdf
expected behavior