dotted_border 2.0.0+3 dotted_border: ^2.0.0+3 copied to clipboard
A flutter package to let users easily add a dashed border around any widget.
import 'package:flutter/material.dart';
import 'package:dotted_border/dotted_border.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Dotted Border'),
),
body: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
children: <Widget>[
_rectBorderWidget,
_rectBorderWithPaddingWidget,
_roundedRectBorderWidget,
customBorder,
_roundStrokeCap,
_solidBorder,
_fullWidthPath,
],
),
),
),
),
),
);
}
/// Draw a border with rectangular border
Widget get _rectBorderWidget {
return DottedBorder(
dashPattern: [8, 4],
strokeWidth: 2,
child: Container(
height: 200,
width: 120,
color: Colors.red,
),
);
}
/// Use [DottedBorder.borderPadding] to prevent the border from being drawn
/// outside the widget.
Widget get _rectBorderWithPaddingWidget {
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: DottedBorder(
dashPattern: [8, 4],
strokeWidth: 8,
padding: EdgeInsets.all(8),
borderPadding: EdgeInsets.all(4),
child: Container(
height: 200,
width: 120,
color: Colors.red.withOpacity(0.5),
),
),
);
}
/// Draw a border with a rounded rectangular border
Widget get _roundedRectBorderWidget {
return DottedBorder(
borderType: BorderType.RRect,
radius: Radius.circular(12),
padding: EdgeInsets.all(6),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)),
child: Container(
height: 200,
width: 120,
color: Colors.amber,
),
),
);
}
/// Draw a border with custom path border
Widget get customBorder {
Path customPath = Path()
..moveTo(20, 20)
..lineTo(50, 100)
..lineTo(20, 200)
..lineTo(100, 100)
..lineTo(20, 20);
return DottedBorder(
customPath: (_) => customPath,
color: Colors.indigo,
dashPattern: [8, 4],
strokeWidth: 2,
child: Container(
height: 220,
width: 120,
color: Colors.green.withAlpha(20),
),
);
}
/// Set border stroke cap
Widget get _roundStrokeCap {
return DottedBorder(
dashPattern: [8, 4],
strokeWidth: 2,
strokeCap: StrokeCap.round,
borderType: BorderType.RRect,
radius: Radius.circular(5),
child: Container(
height: 200,
width: 120,
color: Colors.red,
),
);
}
Widget get _solidBorder {
return DottedBorder(
dashPattern: [4, 3],
strokeWidth: 2,
strokeCap: StrokeCap.round,
child: Container(
color: Colors.green,
height: 200,
width: 120,
),
);
}
Widget get _fullWidthPath {
return DottedBorder(
customPath: (size) {
return Path()
..moveTo(0, 20)
..lineTo(size.width, 20);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(),
),
);
}
}