Draw rectangle shape in flutter
We need CustomPainter class to draw the rectangular shape
class NetworkDiagnosis extends StatefulWidget {
@override
_NetworkDiagnosisState createState() => _NetworkDiagnosisState();
}
class _NetworkDiagnosisState extends State<NetworkDiagnosis> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Title'), centerTitle: true, backgroundColor: AppTheme.appBarColor),
body: Stack(
children: <Widget>[
Positioned(
left: 10,
top: 10,
child: CustomPaint(
painter: DrawRect(),
)
),
]
),
);
}
}
@override
_NetworkDiagnosisState createState() => _NetworkDiagnosisState();
}
class _NetworkDiagnosisState extends State<NetworkDiagnosis> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Title'), centerTitle: true, backgroundColor: AppTheme.appBarColor),
body: Stack(
children: <Widget>[
Positioned(
left: 10,
top: 10,
child: CustomPaint(
painter: DrawRect(),
)
),
]
),
);
}
}
DrawRect.dart
class DrawRect extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(
Rect.fromLTRB( 0.0, 0.0, 100.0, 100.0 ),
Paint()..color = Colors.green,
);
}
@override
bool shouldRepaint(DrawRect rect) {
return false;
}
}
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(
Rect.fromLTRB( 0.0, 0.0, 100.0, 100.0 ),
Paint()..color = Colors.green,
);
}
@override
bool shouldRepaint(DrawRect rect) {
return false;
}
}
ConversionConversion EmoticonEmoticon