|
| 1 | +import 'dart:ui'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:getwidget/components/border/gf_dashed_border.dart'; |
| 4 | +import 'package:getwidget/types/gf_border_type.dart'; |
| 5 | + |
| 6 | +class GFBorder extends StatelessWidget { |
| 7 | + GFBorder({ |
| 8 | + @required this.child, |
| 9 | + this.color = Colors.black, |
| 10 | + this.strokeWidth = 1, |
| 11 | + this.type = GFBorderType.Rect, |
| 12 | + this.dashedLine = const <double>[3, 1], |
| 13 | + this.padding = const EdgeInsets.all(10), |
| 14 | + this.radius = const Radius.circular(0), |
| 15 | + this.customPath, |
| 16 | + }) : assert(child != null), |
| 17 | + assert(_isValiddashedLine(dashedLine), 'Invalid dash pattern'); |
| 18 | + |
| 19 | + /// child of type [Widget] which can be any component or text , etc |
| 20 | + final Widget child; |
| 21 | + |
| 22 | + /// padding of time [EdgeInsets] where in padding is given to the border types |
| 23 | + final EdgeInsets padding; |
| 24 | + |
| 25 | + /// storkeWidth of type [double] which is used to define the thickness of the border |
| 26 | + final double strokeWidth; |
| 27 | + |
| 28 | + /// color of type [Color] or GFColor which is used to change the color of the border type |
| 29 | + final Color color; |
| 30 | + |
| 31 | + /// dashedLine of type [List<double>] which is used for the linear and simple dashed line of border |
| 32 | + final List<double> dashedLine; |
| 33 | + |
| 34 | + /// type of [GFBorderType] which is used to define the different types of borders ie, circle, Rect, RRect and oval |
| 35 | + final GFBorderType type; |
| 36 | + |
| 37 | + /// radius of type [Radius] used to give a curved border only when the border type is RRect, in other cases radius will not work |
| 38 | + final Radius radius; |
| 39 | + |
| 40 | + /// customPath of type [PathBuilder] used for drawing the paths |
| 41 | + final PathBuilder customPath; |
| 42 | + |
| 43 | + @override |
| 44 | + Widget build(BuildContext context) => Stack( |
| 45 | + children: <Widget>[ |
| 46 | + Positioned.fill( |
| 47 | + child: CustomPaint( |
| 48 | + painter: DashedType( |
| 49 | + strokeWidth: strokeWidth, |
| 50 | + radius: radius, |
| 51 | + color: color, |
| 52 | + type: type, |
| 53 | + dashedLine: dashedLine, |
| 54 | + customPath: customPath, |
| 55 | + ), |
| 56 | + ), |
| 57 | + ), |
| 58 | + Container(padding: padding, child: child), |
| 59 | + ], |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +/// the value of dashedLine cannot be 0 or null, it should have some definite and proper value |
| 64 | +bool _isValiddashedLine(List<double> dash) { |
| 65 | + final Set<double> _dashSet = dash.toSet(); |
| 66 | + if (_dashSet == null) { |
| 67 | + return false; |
| 68 | + } |
| 69 | + if (_dashSet.length == 1 && _dashSet.elementAt(0) == 0.0) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + if (_dashSet.isEmpty) { |
| 73 | + return false; |
| 74 | + } |
| 75 | + return true; |
| 76 | +} |
0 commit comments