Filter by Widgets


How to draw a Decorative Horizontal line in Flutter?

This Article is posted by seven.srikanth at 04-06-2019 22:51:47


Hello Guys,

Today, I have come across a requirement to create a horizontal line.

I'm trying to create something like below. ---------- or ----------- (it's not a dotted line, but a continuous line). See below. 



So, I have created a class to create this line. Here is the code for drawing a line in the flutter.


import 'package:flutter/material.dart';

class Drawhorizontalline extends CustomPainter {

Paint _paint;
bool reverse;

Drawhorizontalline(this.reverse) {
_paint = Paint()
..color = Colors.white
..strokeWidth = 0.5
..strokeCap = StrokeCap.round;
}

@override
void paint(Canvas canvas, Size size) {
if(!reverse){
canvas.drawLine(Offset(10.0, 0.0), Offset(90.0, 0.0), _paint);
}
else
{
canvas.drawLine(Offset(-90.0, 0.0), Offset(-10.0, 0.0), _paint);
}
}

@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}

You need to call it like this.

CustomPaint(painter: Drawhorigontalline(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


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.




Recent articles

Horizontal List View

Check out this article on Horizontal List View

Read full post

How to get the Width and Height of the Screen in Flutter?

Check out this article on How to get the Width and Height of the Screen in Flutter?

Read full post

How to add a Footer Buttons in Flutter?

Check out this article on How to add a Footer Buttons in Flutter?

Read full post

TextField in Flutter

Check out this article on TextField in Flutter

Read full post

How to Draw a Triangle using Canvas in Flutter?

Check out this article on How to Draw a Triangle using Canvas in Flutter?

Read full post

url_launcher Package - Lets Launch URL, Send Email, Make Call or Send SMS in Flutter

Check out this article on url_launcher Package - Lets Launch URL, Send Email, Make Call or Send SMS in Flutter

Read full post

Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Check out this article on Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Read full post

How to create a persistent bottom sheet in Flutter?

Check out this article on How to create a persistent bottom sheet in Flutter?

Read full post

How to draw a Decorative Horizontal line in Flutter?

Check out this article on How to draw a Decorative Horizontal line in Flutter?

Read full post

How to fetch an Image from Internet in Flutter

Check out this article on How to fetch an Image from Internet in Flutter

Read full post

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

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License , and code samples are licensed under the BSD License.