Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid include min and max value #1150

Open
sgshivamgarg8 opened this issue Sep 22, 2022 · 3 comments
Open

Grid include min and max value #1150

sgshivamgarg8 opened this issue Sep 22, 2022 · 3 comments
Labels
enhancement New feature or request Fundamental good first issue Good for newcomers

Comments

@sgshivamgarg8
Copy link

sgshivamgarg8 commented Sep 22, 2022

Can we include min and max values for drawing grid lines?

I want to show grid lines for outer box also like for 0 and max value.

I know border is supposed to be used for this use case but I want the same style as grid lines (dotted / dashed)
and flutter dont allow dotted / dashed border.

Can we have something proper for this?

@sgshivamgarg8 sgshivamgarg8 changed the title Grid include min and max Grid include min and max value Sep 22, 2022
@imaNNeo
Copy link
Owner

imaNNeo commented Jan 16, 2023

Hi. We separated the grid (called FlGridData) and border (called FlBorderData) concepts to be able to have some specific features for them.

To solve this issue, we need to make FlBorderData more customizable to support dashed line. (just like what we do in FlGridData)

@imaNNeo imaNNeo added enhancement New feature or request good first issue Good for newcomers Fundamental labels Jan 16, 2023
@sinyu1012
Copy link

I solved the problem by customizing the DashdedBorder and passing in FlBorderData


import 'package:flutter/material.dart';

class DashedBorder extends Border {
  final double dashWidth;
  final double dashSpace;

  const DashedBorder({
    super.top,
    super.right,
    super.bottom,
    super.left,
    this.dashWidth = 5.0,
    this.dashSpace = 5.0,
  });

  void _paintDashedSide(Canvas canvas, Rect rect, BorderSide side, {required bool horizontal}) {
    final paint = side.toPaint()
      ..style = PaintingStyle.stroke;
    final double totalWidth = horizontal ? rect.width : rect.height;
    final path = Path();
    double startX = horizontal ? rect.left : rect.top;
    final double endX = horizontal ? rect.right : rect.bottom;
    final double posY = horizontal ? rect.top : rect.left;

    while (startX < endX) {
      path.moveTo(horizontal ? startX : posY, horizontal ? posY : startX);
      path.lineTo(horizontal ? startX + dashWidth : posY, horizontal ? posY : startX + dashWidth);
      startX += dashWidth + dashSpace;
    }

    canvas.drawPath(path, paint);
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection, BoxShape shape = BoxShape.rectangle, BorderRadius? borderRadius}) {
    if (top != BorderSide.none) {
      _paintDashedSide(canvas, Rect.fromLTWH(rect.left, rect.top, rect.width, top.width), top, horizontal: true);
    }
    if (right != BorderSide.none) {
      _paintDashedSide(canvas, Rect.fromLTWH(rect.right - right.width, rect.top, right.width, rect.height), right, horizontal: false);
    }
    if (bottom != BorderSide.none) {
      _paintDashedSide(canvas, Rect.fromLTWH(rect.left, rect.bottom - bottom.width, rect.width, bottom.width), bottom, horizontal: true);
    }
    if (left != BorderSide.none) {
      _paintDashedSide(canvas, Rect.fromLTWH(rect.left, rect.top, left.width, rect.height), left, horizontal: false);
    }
  }
}

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 6, 2024

Is it related to #494 issue? If yes please close this issue and let's follow it in one place.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fundamental good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants