我正在使用Flutter,希望给小部件(在这种情况下是Text
小部件)添加边框。
我尝试过TextStyle
和Text
,但我没有看到如何添加边框。
我正在使用Flutter,希望给小部件(在这种情况下是Text
小部件)添加边框。
我尝试过TextStyle
和Text
,但我没有看到如何添加边框。
使用带有BoxDecoration的容器。
BoxDecoration(
border: Border.all(
width: 3.0
),
borderRadius: BorderRadius.circular(10.0)
);
Stack(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: const BorderRadius.only(
topLeft: Radius.zero,
topRight: Radius.zero,
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 1,
),
Text("Dummy text"),
const SizedBox(
height: 10,
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(left: 2, right: 2),
child: Container(
color: AppColors.highLighterBg,
width: size.width,
height: 10,
),
)
],
);
使用底部阴影实现圆角/边框
Container(
// child it's depend on your requirement
child: const Center(
child: Text(
'This is your Container',
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: <BoxShadow>[
// shadow color and radius
BoxShadow(
color: Colors.black54,
blurRadius: 15.0,
offset: Offset(0.0, 0.75)
)
],
),
// according your height ex. 50
height: 50,
);
文本边框样式:
Stack(
children: <Widget>[
// Stroked text as border.
Text(
'Greetings, planet!',
style: TextStyle(
fontSize: 40,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.blue[700]!,
),
),
// Solid text as fill.
Text(
'Greetings, planet!',
style: TextStyle(
fontSize: 40,
color: Colors.grey[300],
),
),
],
)
Container(
margin: margin,
padding: padding,
decoration: BoxDecoration(
border: Border.all(
color: color,
width: width,
),
),
child: Text(
data,
style: TextStyle(fontSize: 30.0),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.redAccent,
width: 1,
),
),
child: Text('Some Text'),
);
在容器内使用文本小部件,使用装饰来边框化文本:
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff000000),
width: 1,
)),
是的,有不同的方法可以实现。其中之一是:将其包装在容器中。并使用类似于以下的盒子装饰。
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
border: Border.all(width: 5, color: Colors.red),
borderRadius: BorderRadius.all(Radius.circular(50)),
),
child: const Text(
"Box decoration",
style: TextStyle(fontSize: 34.0),
),
)
Container(
height: height * 0.06,
width: width,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: primaryColor,
),
borderRadius: BorderRadius.circular(10),
),
child: Text(
"data",
style: const TextStyle(
fontWeight: FontWeight.bold
),
),
);