Last active
April 6, 2020 09:54
-
-
Save JEuler/4d4b84151115e418f1b8db76235049ac to your computer and use it in GitHub Desktop.
DotDivider widget for Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
/// Dot divider for Calendar | |
class DotDivider extends StatelessWidget { | |
/// Constructor | |
const DotDivider( | |
{this.height = 1, this.color = Colors.black, this.countCoeff = 3}); | |
/// Color of divider | |
final Color color; | |
/// Height of divider | |
final double height; | |
/// Dash count coefficient | |
final double countCoeff; | |
@override | |
Widget build(BuildContext context) { | |
return LayoutBuilder( | |
builder: (BuildContext context, BoxConstraints constraints) { | |
final boxWidth = constraints.constrainWidth(); | |
const dashWidth = 2.0; | |
final dashHeight = height; | |
final dashCount = (boxWidth / (countCoeff * dashWidth)).floor(); | |
return Flex( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
direction: Axis.horizontal, | |
children: List.generate(dashCount, (_) { | |
return SizedBox( | |
width: dashWidth, | |
height: dashHeight, | |
child: DecoratedBox( | |
decoration: BoxDecoration(color: color), | |
), | |
); | |
}), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment