How to draw a Horizontal line in Flutter?

This Article is posted by seven.srikanth at 12/27/2018 2:15:50 PM



Hello Guys,
In this article, I'm going to show you how to draw a horizontal line in Flutter. See below images on how the output is going to look. Nothing fancy.
If you looking for a decorative horizontal line as shown below ( ---------- or ----------- ), then here is the link for that article. 
How to draw a Decorative Horizontal line in Flutter? - https://fluttercentral.com/Articles/Post/1148
Here is the full code for this example. All you need is to copy paste this code to your main.dart file in newly created flutter project.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
child: CustomPaint(painter: Drawhorizontalline()),
),
);
}
}
class Drawhorizontalline extends CustomPainter {
Paint _paint;
Drawhorizontalline() {
_paint = Paint()
..color = Colors.white
..strokeWidth = 1
..strokeCap = StrokeCap.round;
}
@override
void paint(Canvas canvas, Size size) {
canvas.drawLine(Offset(-90.0, 0.0), Offset(90.0, 0.0), _paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
Actually, by changing a few things. You can draw vertical and cross lines too using this class. 
Hope this is useful to you.
Thanks,
Srikanth

Tags: How to draw a Horizontal line in Flutter?








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com