Skip to content

Instantly share code, notes, and snippets.

@naonya3
Last active June 27, 2020 01:28
Show Gist options
  • Save naonya3/5ca1bbc1421e547447ee6fc83ab607ff to your computer and use it in GitHub Desktop.
Save naonya3/5ca1bbc1421e547447ee6fc83ab607ff to your computer and use it in GitHub Desktop.
点線が描きたい2020
import 'package:flutter/material.dart';
class DotLine extends StatelessWidget {
const DotLine({
this.height = 6,
this.color = const Color.fromRGBO(232, 232, 232, 1),
this.spacing = 10,
});
final double height;
final Color color;
final double spacing;
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
child: CustomPaint(
painter: _DotPainter(
color: color,
radius: height / 2,
basicSpacing: spacing,
),
),
);
}
}
class _DotPainter extends CustomPainter {
const _DotPainter({this.color, this.radius, this.basicSpacing});
final Color color;
final double radius;
final double basicSpacing;
@override
void paint(Canvas canvas, Size size) {
final int count = size.width ~/ (radius * 2 + basicSpacing);
final double spacing = (size.width - count * radius * 2) / (count - 1);
final Paint paint = Paint()..color = color;
for (int i = 0; i < count; i++) {
canvas.drawCircle(
Offset(i * (spacing + radius * 2) + radius, radius), radius, paint);
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
@naonya3
Copy link
Author

naonya3 commented Jun 27, 2020

Draw dot line

😄 😄 😄 😄

@naonya3
Copy link
Author

naonya3 commented Jun 27, 2020

LICENSE

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment