我如何建立像下图这样的自由手边界线?
想要实现这个形象:
但我只知道建立简单的直线/圆形边框,
像这样:
代码:
// CORNER ROUNDED BORDER DROP DOWN:
_buildDropDownField() {
return Container(
padding: const EdgeInsets.only(left: 8, right: 8),
alignment: Alignment.center,
height: 60,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.black),
// color:Colors.white,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
selectedTopic == null
? Text(
"Select Topic",
style: TextStyle(
color: Colors.black),
)
: Text(
selectedTopic.title,
style: TextStyle(
color:
Colors.black,
),
),
DropdownButton<TopicModel>(
underline: Container(),
dropdownColor: Colors.white,
icon: Icon(Icons.arrow_drop_down),
items: TOPICS.map((TopicModel value) {
return new DropdownMenuItem<TopicModel>(
value: value,
child: new Text(
value.title,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
onChanged: (val) {
setState(() {
selectedTopic = val;
});
},
)
],
),
);
}
//CORNER ROUNDED BORDER TEXT FIELD:
new TextFormField(
controller: _option1Controller,
decoration: new InputDecoration(
// suffixText: "2",
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[800]),
hintText: "Option 1",
labelText: "Option 1",
fillColor: Colors.white70),
validator: (value) {
if (value.isEmpty) {
return 'Can\'t not be empty';
}
return null;
},
),
我认为这将是可能的CustomPainter
。但只知道画一些形状,如环形、圆形、直线、正方形、矩形。
直线与自定义画家:
class DrawCustomShape extends CustomPainter{
@override
void paint(Canvas canvas, Size size) {
var paint = Paint();
paint.color = Colors.red;
paint.strokeWidth = 5;
canvas.drawLine(
Offset(0, size.height / 2),
Offset(size.width, size.height / 2),
paint,
);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
带有自定义画家的圆圈:
class DrawCustomShape extends CustomPainter{
@override
void paint(Canvas canvas, Size size) {
var paint = Paint();
paint.color = Colors.amber;
paint.strokeWidth = 5;
paint.color = Colors.blue;
paint.style = PaintingStyle.stroke;
canvas.drawCircle(Offset(size.width/2, size.height/2), size.width/4, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}