我想并排放置兩個線性漸變而不將它們分別放在不同的 Container() 中
我的代碼:
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
// Instead of two different colors here I want to have the two other Linear gradients
// with each having two other different colors that go from top to bottom
Color(0xff5a0dbe),
Color(0xff004773),
],
stops: [0.5, 0.5],
tileMode: TileMode.clamp,
),
),
child: const Center(
child: Text(
"sds",
style: TextStyle(color: Colors.white),
)),
),
我得到的是

我想要的是

uj5u.com熱心網友回復:
您可以使用 aColumn來放置您在評論中描述的小部件,無需擔心定位小部件。Stack與兩個一起使用Container
return Scaffold(
body: LayoutBuilder(
//for future purpose if needed
builder: (context, constraints) {
return Stack(
alignment: Alignment.topCenter, // defult topLeft
children: [
Row(
children: [
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xff5a0dbe),
Color(0xff004773),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
// stops: [0.5, 0.5],
// tileMode: TileMode.clamp,
),
),
),
),
Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xff00436D),
Color(0xff031420),
],
// stops: [0.5, 0.5],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
// tileMode: TileMode.clamp,
),
),
),
),
],
),
SizedBox(
// dont need it,
width: constraints.maxWidth,
height: constraints.maxHeight,
child: Column(
// do everything on column
children: [
],
),
)
],
);
},
),
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/394168.html
