Flutter 在小部件中使用圆形创建颜色-颤振
我无法在香蕉图片下方实现此圆形设计 当我尝试添加渐变时,它并没有产生明显的差异 我怎样才能在颤振中实现这一点Flutter 在小部件中使用圆形创建颜色-颤振,flutter,flutter-layout,Flutter,Flutter Layout,我无法在香蕉图片下方实现此圆形设计 当我尝试添加渐变时,它并没有产生明显的差异 我怎样才能在颤振中实现这一点 您只需要一个堆栈小部件&放置一个圆形的容器 要创建圆,可以使用Container的shape属性并将其设置为BoxShape.circle。然后,将其余的小部件放在彼此的顶部 以下代码的结果输出如下所示: 您的代码应该如下所示: return Stack( children: [ // Green Background Container( height
您只需要一个
堆栈
小部件&放置一个圆形的容器
要创建圆,可以使用Container
的shape
属性并将其设置为BoxShape.circle
。然后,将其余的小部件放在彼此的顶部
以下代码的结果输出如下所示:
您的代码应该如下所示:
return Stack(
children: [
// Green Background
Container(
height: 400,
decoration: BoxDecoration(
color: Colors.green,
),
),
// Circle
Positioned(
right: -50,
top: -50,
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
),
Positioned(
top: 20,
right: 20,
left: 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: TextFormField(
decoration: InputDecoration(
filled: true,
hintText: 'Search for products',
),
)),
IconButton(icon: Icon(Icons.search), onPressed: () {}),
],
),
Container(
margin: const EdgeInsets.only(top: 40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text('BANANA 5% OFF',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
),),
),
Expanded(
child: Container(
height: 150,
width: 150,
color: Colors.white10,
alignment: Alignment.center,
child: Text('Image'),
),
),
],
),
),
],
),
),
],
);
您只需要一个
堆栈
小部件&放置一个圆形的容器
要创建圆,可以使用Container
的shape
属性并将其设置为BoxShape.circle
。然后,将其余的小部件放在彼此的顶部
以下代码的结果输出如下所示:
您的代码应该如下所示:
return Stack(
children: [
// Green Background
Container(
height: 400,
decoration: BoxDecoration(
color: Colors.green,
),
),
// Circle
Positioned(
right: -50,
top: -50,
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
),
Positioned(
top: 20,
right: 20,
left: 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: TextFormField(
decoration: InputDecoration(
filled: true,
hintText: 'Search for products',
),
)),
IconButton(icon: Icon(Icons.search), onPressed: () {}),
],
),
Container(
margin: const EdgeInsets.only(top: 40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text('BANANA 5% OFF',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
),),
),
Expanded(
child: Container(
height: 150,
width: 150,
color: Colors.white10,
alignment: Alignment.center,
child: Text('Image'),
),
),
],
),
),
],
),
),
],
);
尝试堆栈和定位Widgetry堆栈和定位小部件