banner



How To Draw Text In Doodletoo

enter image description here

To paint in Palpitate you lot apply the CustomPaint widget. The CustomPaint widget takes a CustomPainter object as a parameter. In that grade you lot accept to override the paint method, which gives y'all a canvass that you can paint on. Here is the code to draw the text in the image above.

          @override void paint(Canvas canvas, Size size) {   concluding textStyle = TextStyle(     color: Colors.blackness,     fontSize: xxx,   );   terminal textSpan = TextSpan(     text: 'Hello, world.',     style: textStyle,   );   final textPainter = TextPainter(     text: textSpan,     textDirection: TextDirection.ltr,   );   textPainter.layout(     minWidth: 0,     maxWidth: size.width,   );   final xCenter = (size.width - textPainter.width) / ii;   final yCenter = (size.height - textPainter.height) / 2;   terminal first = Offset(xCenter, yCenter);   textPainter.paint(canvas, offset); }                  

Notes:

  • If you are using a white background, be sure to gear up the text colour to another color besides white, which is the default.
  • Flutter makes an effort to non assume a text direction, and then you demand to set it explicitly. The abbreviation ltr stands for left-to-right, which languages like English apply. The other option is rtl (correct-to-left), which languages like Arabic and Hebrew use. This helps to reduce bugs when the lawmaking is used in language contexts that developers were not thinking most.

Context

Here is the main.dart lawmaking so that yous can see it in context.

          import 'parcel:palpitate/material.dart';  void main() => runApp(MyApp());  class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       home: Scaffold(         body: HomeWidget(),       ),     );   } }  class HomeWidget extends StatelessWidget {   @override   Widget build(BuildContext context) {     return Middle(       child: CustomPaint( //                       <-- CustomPaint widget         size: Size(300, 300),         painter: MyPainter(),       ),     );   } }  class MyPainter extends CustomPainter { //         <-- CustomPainter class   @override   void paint(Canvas canvas, Size size) {     //                                             <-- Insert your painting code here.   }      @override   bool shouldRepaint(CustomPainter former) {     return simulated;   } }                  

See also

See this article for my fuller answer.

Source: https://stackoverflow.com/questions/41371449/how-do-you-use-a-textpainter-to-draw-text

Posted by: chapmanjecome.blogspot.com

0 Response to "How To Draw Text In Doodletoo"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel