@@ -40,38 +40,65 @@ class _GridPaperPainter extends CustomPainter {
...
@@ -40,38 +40,65 @@ class _GridPaperPainter extends CustomPainter {
returnoldPainter.color!=color
returnoldPainter.color!=color
||oldPainter.interval!=interval
||oldPainter.interval!=interval
||oldPainter.divisions!=divisions
||oldPainter.divisions!=divisions
||oldPainter.subDivisions!=subDivisions;
||oldPainter.subdivisions!=subdivisions;
}
}
@override
@override
boolhitTest(Offsetposition)=>false;
boolhitTest(Offsetposition)=>false;
}
}
/// A widget that draws a rectilinear grid of 1px wide lines.
/// A widget that draws a rectilinear grid of lines one pixel wide.
///
///
/// Useful with a [Stack] for visualizing your layout along a grid.
/// Useful with a [Stack] for visualizing your layout along a grid.
///
/// The grid's origin (where the first primary horizontal line and the first
/// primary vertical line intersect) is at the top left of the widget.
///
/// The grid is drawn over the [child] widget.
classGridPaperextendsStatelessWidget{
classGridPaperextendsStatelessWidget{
/// Creates a widget that draws a rectilinear grid of 1px wide lines.
/// Creates a widget that draws a rectilinear grid of 1-pixel-wide lines.
constGridPaper({
constGridPaper({
Keykey,
Keykey,
this.color:constColor(0x7FC3E8F3),
this.color:constColor(0x7FC3E8F3),
this.interval:100.0,
this.interval:100.0,
this.divisions:2,
this.divisions:2,
this.subDivisions:5,
this.subdivisions:5,
this.child
this.child,
}):super(key:key);
}):assert(divisions>0,'The "divisions" property must be greater than zero. If there were no divisions, the grid paper would not paint anything.'),
assert(subdivisions>0,'The "subdivisions" property must be greater than zero. If there were no subdivisions, the grid paper would not paint anything.'),
super(key:key);
/// The color to draw the lines in the grid.
/// The color to draw the lines in the grid.
///
/// Defaults to a light blue commonly seen on traditional gridpaper.
finalColorcolor;
finalColorcolor;
/// The distance between the primary lines in the grid, in logical pixels.
/// The distance between the primary lines in the grid, in logical pixels.
///
/// Each primary line is one logical pixel wide.
finaldoubleinterval;
finaldoubleinterval;
/// The number of major divisions within each primary grid cell.
/// The number of major divisions within each primary grid cell.
///
/// This is the number of major divisions per [interval], including the
/// primary grid's line.
///
/// The lines after the first are half a logical pixel wide.
///
/// If this is set to 2 (the default), then for each [interval] there will be
/// a 1-pixel line on the left, a half-pixel line in the middle, and a 1-pixel
/// line on the right (the latter being the 1-pixel line on the left of the
/// next [interval]).
finalintdivisions;
finalintdivisions;
/// The number of minor divisions within each major division.
/// The number of minor divisions within each major division, including the
finalintsubDivisions;
/// major division itself.
///
/// If [subdivisions] is 5 (the default), it means that there will be four
/// lines between each major ([divisions]) line.
///
/// The subdivision lines after the first are a quarter of a logical pixel wide.
finalintsubdivisions;
/// The widget below this widget in the tree.
/// The widget below this widget in the tree.
finalWidgetchild;
finalWidgetchild;
...
@@ -83,9 +110,9 @@ class GridPaper extends StatelessWidget {
...
@@ -83,9 +110,9 @@ class GridPaper extends StatelessWidget {