Flutter 颤振圆形矩形边框,每边颜色不同
我试图重新创建一个我用React Native制作的按钮,每一面都有不同的颜色,给它一种凿刻的效果,有点像Photoshop斜面和浮雕,但也有圆角。现在我在按钮外面有一个容器,上面有边框,在里面我使用的是Flutter 颤振圆形矩形边框,每边颜色不同,flutter,dart,Flutter,Dart,我试图重新创建一个我用React Native制作的按钮,每一面都有不同的颜色,给它一种凿刻的效果,有点像Photoshop斜面和浮雕,但也有圆角。现在我在按钮外面有一个容器,上面有边框,在里面我使用的是RawMaterialButton。容器的代码如下所示: Container( BoxDecoration( border: Border( left: BorderSide( color: Colors.black, width: 1.0, ),
RawMaterialButton
。容器的代码如下所示:
Container(
BoxDecoration(
border: Border(
left: BorderSide(
color: Colors.black,
width: 1.0,
),
top: BorderSide(
color: Colors.black,
width: 1.0,
),
),
),
)
如何使此边框/容器的角变圆
像这样,但有圆角:
这不是一个100%有效的解决方案。我刚刚编写了一些路径函数,使用
CustomPainter
绘制所有边
圆形凿边
类rounded凿岩边界扩展小部件{
最后一个孩子;
最终颜色为左边框颜色;
最终颜色为右边框颜色;
最终色底边框色;
最终的颜色;
最终双边界半径;
最终双边界宽度;
圆凿边({
@需要这个孩子,
此.borderRadius=1,
此.borderWidth=2,
this.bottomBorderColor=Colors.black,
this.topBorderColor=Colors.black,
this.rightBorderColor=Colors.black,
this.leftBorderColor=Colors.black,
});
@凌驾
小部件构建(构建上下文){
返回堆栈(
儿童:[
定位填充(
孩子:定制油漆(
画家:圆边画家(
半径:边界半径,
strokeWidth:borderWidth,
bottomBorderColor:bottomBorderColor,
leftBorderColor:leftBorderColor,
rightBorderColor:rightBorderColor,
topBorderColor:topBorderColor,
),
),
),
小孩
],
);
}
}
圆边画师顺序
import'package:vector\u math/vector\u math.dart'作为虚拟机;
类RoundedBorderPainter扩展了CustomPainter{
最终颜色为左边框颜色;
最终颜色为右边框颜色;
最终色底边框色;
最终的颜色;
最终双冲程宽度;
最终冲程盖冲程盖=冲程盖圆;
双半径;
大小;
圆边画家({
this.leftBorderColor=Colors.black,
this.rightBorderColor=Colors.black,
this.topBorderColor=Colors.black,
this.bottomBorderColor=Colors.black,
此参数为.strokeWidth=2,
这个半径=1,
}) {
if(radius这不是一个100%有效的解决方案。我只是编写了一些路径函数,使用CustomPainter
绘制所有边
圆形凿边
类rounded凿岩边界扩展小部件{
最后一个孩子;
最终颜色为左边框颜色;
最终颜色为右边框颜色;
最终色底边框色;
最终的颜色;
最终双边界半径;
最终双边界宽度;
圆凿边({
@需要这个孩子,
此.borderRadius=1,
此.borderWidth=2,
this.bottomBorderColor=Colors.black,
this.topBorderColor=Colors.black,
this.rightBorderColor=Colors.black,
this.leftBorderColor=Colors.black,
});
@凌驾
小部件构建(构建上下文){
返回堆栈(
儿童:[
定位填充(
孩子:定制油漆(
画家:圆边画家(
半径:边界半径,
strokeWidth:borderWidth,
bottomBorderColor:bottomBorderColor,
leftBorderColor:leftBorderColor,
rightBorderColor:rightBorderColor,
topBorderColor:topBorderColor,
),
),
),
小孩
],
);
}
}
圆边画师顺序
import'package:vector\u math/vector\u math.dart'作为虚拟机;
类RoundedBorderPainter扩展了CustomPainter{
最终颜色为左边框颜色;
最终颜色为右边框颜色;
最终色底边框色;
最终的颜色;
最终双冲程宽度;
最终冲程盖冲程盖=冲程盖圆;
双半径;
大小;
圆边画家({
this.leftBorderColor=Colors.black,
this.rightBorderColor=Colors.black,
this.topBorderColor=Colors.black,
this.bottomBorderColor=Colors.black,
此参数为.strokeWidth=2,
这个半径=1,
}) {
如果(radiusAjil的解决方案看起来是正确的方向,那么你是对的,对于这样一件小事来说,这是一个惊人的工作量
这是我单调乏味的工作,需要简化以整理它,但它可以更准确地表示您的图像
class Example extends StatefulWidget {
@override
_ExampleState createState() {
return _ExampleState();
}
}
class _ExampleState extends State<Example> {
double height;
double width;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
height = MediaQuery.of(context).size.height;
width = MediaQuery.of(context).size.width;
const double pi = 3.1415926535897932;
return Scaffold(
appBar: AppBar(
title: Text("Some project"),
),
body: Center(
child:
Container(
width: width = 350,
height: height = 300,
child: Stack(children: <Widget>[
Align(
alignment: Alignment.center,
child: Container(
width: 300,
height: 300,
// color: Colors.red,
child: FlatButton(
onPressed: () {
print('button pressed');
},
child: Text(
'BUTTON',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
)),
)),
Align(
//TOP BORDER
alignment: Alignment.topCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.blue[200],
border:
Border.all(width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0)),
),
height: 50,
width: width,
),
),
Align(
//LEFT BORDER
alignment: Alignment.topLeft,
child: Container(
height: height,
width: 30,
decoration: BoxDecoration(
color: Colors.blue[100],
border: Border.all(
width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0))),
),
),
Align(
//RIGHT BORDER
alignment: Alignment.topRight,
child: Container(
height: height,
width: 15,
decoration: BoxDecoration(
color: Colors.blue[300],
border: Border.all(
width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
topRight: Radius.circular(10.0),
bottomRight: Radius.circular(10.0))),
),
),
Align(
//BOTTOM BORDER
alignment: Alignment.bottomCenter,
child: Container(
height: 15,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(
width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0))),
),
),
Align(
//TOPLEFT BORDER
alignment: Alignment.topLeft,
child: Container(
decoration: BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.bottomRight,
startAngle: pi * 1.349,
endAngle: pi * 1.35,
colors: [
Colors.blue[100],
Colors.blue[200],
]),
border:
Border.all(width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
),
),
width: 30,
height: 50,
),
),
Align(
//TOP RIGHT BORDER
alignment: Alignment.topRight,
child: Container(
decoration: BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.topRight,
startAngle: 1.86,
endAngle: 1.87,
colors: [
Colors.blue[300],
Colors.blue[200],
]),
border: Border.all(
width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
topRight: Radius.circular(10.0),
)),
width: 15,
height: 50,
)),
Align(
//BOTTOMLEFT BORDER
alignment: Alignment.bottomLeft,
child: Container(
decoration: BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.bottomLeft,
startAngle: 5.8,
endAngle: 5.81,
colors: [
Colors.blue[100],
Colors.blue,
]),
border:
Border.all(width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
),
),
width: 30,
height: 15,
),
),
Align(
//BOTTOM RIGHT BORDER
alignment: Alignment.bottomRight,
child: Container(
decoration: BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.bottomRight,
startAngle: 3.99,
endAngle: 4,
colors: [
Colors.blue,
Colors.blue[300],
]),
border: Border.all(
width: 3.0, color: Colors.transparent),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(10.0),
// bottomRight: Radius.circular(10.0)
)),
width: 15,
height: 15,
))
])),
));
}
}
类示例扩展了StatefulWidget{
@凌驾
_ExampleState createState(){
返回_ExampleState();
}
}
类_示例状态扩展状态{
双高;
双倍宽度;
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
height=MediaQuery.of(context).size.height;
宽度=MediaQuery.of(context).size.width;
常数双pi=3.1415926535897932;
返回脚手架(
appBar:appBar(
标题:文本(“某些项目”),
),
正文:中(
儿童:
容器(
宽度:宽度=350,
高度:高度=300,
子:堆栈(子:[
对齐(
对齐:对齐.center,
子:容器(
宽度:300,
身高:300,
//颜色:颜色,红色,
孩子:扁平按钮(
已按下:(){
打印(“按下按钮”);
},
子:文本(
“按钮”,
textAlign:textAlign.center,