问题:
我遇到了一个我无法解决的有趣问题。当我更改颜色时,容器的边框会消失。
代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Color(0xff31353B),
body: Home(),
),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 50.0,
child: GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
//TODO: HERE IS THE PROBLEM.
color: Color(0xFFF05A22),
//style: BorderStyle.solid,
width: 3.0,
),
top: BorderSide(
//TODO: HERE IS THE PROBLEM.
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 3.0,
),
right: BorderSide(
//TODO: HERE IS THE PROBLEM.
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 3.0,
),
bottom: BorderSide(
//TODO: HERE IS THE PROBLEM.
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 3.0,
),
),
color: Colors.green,
borderRadius: BorderRadius.circular(30.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text(
"BUTTON",
style: TextStyle(
color: Color(0xFFF05A22),
fontFamily: 'Montserrat',
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 1,
),
),
),
],
),
),
),
),
],
),
);
}
}
我已经用// TODO标记了感兴趣的区域:
我什至不能将它们的颜色更改为白色或黑色而不会消失。我花了大约一个小时的时间自己尝试通过互联网搜索解决此问题,但是没有运气。
问题:
为什么我可以有一种颜色却不能有另一种颜色?
期望:
要将顶部和左侧边框更改为黑色,将底部和右侧更改为白色。
答案 0 :(得分:1)
扑朔迷离中:“只能为统一边界提供borderRadius。”因此,如果您删除半径,它将起作用。但是,如果要保持半径,仅用一条线就不容易了,此question中有一些示例: