gpt4 book ai didi

flutter - 如何去除圆角的背景颜色

转载 作者:行者123 更新时间:2023-12-05 05:34:47 25 4
gpt4 key购买 nike


在我的应用程序中,我有一个可重新排序的网格,其中包含一些带有圆角的容器。
我的问题是,当我改变容器在网格上的位置时,我可以看到一个彩色的角。

enter image description here

我知道这是由于脚手架 backgroundcolor 属性。
我该如何处理?
这是我的代码:

ReorderableGridView.count(
padding: const EdgeInsets.all(16),
crossAxisSpacing: 4,
mainAxisSpacing: 4,
crossAxisCount: 2,
childAspectRatio: 1,
children: homeButtons
.map((index) => Container(
key: ValueKey(index),
alignment: Alignment.center,
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Color(0xFF4D4D64),
Color(0xFF363649)
],
stops: [0, 1],
begin: AlignmentDirectional(1, -1),
end: AlignmentDirectional(-1, 1),
),
borderRadius: BorderRadius.circular(30),
),
child: InkWell(
onTap: () {
String path = '/$index';
Get.toNamed(path);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SvgPicture.asset(
'assets/icons/$index.svg',
color: Colors.red,
),
Text(index),
],
),
),
))
.toList(),
onReorder: (oldIndex, newIndex) async {
String path = homeButtons.removeAt(oldIndex);
homeButtons.insert(newIndex, path);
setState(() {
box.remove(key);
box.write(key, homeButtons);
});
},
),

这是我尝试过的:

我尝试添加一个带有 Colors.transparent 背景的父 Container:

    .map((index) => Container(
key: ValueKey(index),
decoration: BoxDecoration(
color: Colors.transparent,
),
child: Container(
alignment: Alignment.center,
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Color(0xFF4D4D64),
Color(0xFF363649)
],
stops: [0, 1],
begin: AlignmentDirectional(1, -1),
end: AlignmentDirectional(-1, 1),
),
borderRadius: BorderRadius.circular(30),
),
child: InkWell(
onTap: () {
String path = '/$index';
Get.toNamed(path);
},
child: Column(..),
),
),
))

我也试过将 Inkwell 向上移动:

    .map((index) => Container(
key: ValueKey(index),
decoration: BoxDecoration(
color: Colors.transparent,
),
child: InkWell(
onTap: () {
String path = '/$index';
Get.toNamed(path);
},
child: Container(
alignment: Alignment.center,
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Color(0xFF4D4D64),
Color(0xFF363649)
],
stops: [0, 1],
begin: AlignmentDirectional(1, -1),
end: AlignmentDirectional(-1, 1),
),
borderRadius: BorderRadius.circular(30),
),
child: Column(...),
),
),
))

最后我尝试将这个透明的 Container 向上移动到 SafeArea 周围

  return Scaffold(
backgroundColor: const Color(0xFF2f2e3c),
appBar: AppBar(
backgroundColor: const Color(0xFF2f2e3c),
elevation: 0,
title: Text(
'Q.bit',
style: GoogleFonts.outfit(
textStyle: const TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
),
centerTitle: true,
),
body: Container(
decoration: BoxDecoration(
color: Colors.transparent,
),
child: SafeArea(...),

我总是在容器颜色上遇到同样的问题。
谁能帮帮我?
提前致谢

最佳答案

你应该使用dragWidgetBuilder,试试这个:

ReorderableGridView.count(
clipBehavior: Clip.antiAlias,
padding: const EdgeInsets.all(16),
crossAxisSpacing: 4,
mainAxisSpacing: 4,
crossAxisCount: 2,
childAspectRatio: 1,
dragStartBehavior: DragStartBehavior.down,
dragWidgetBuilder: (index, child) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Container(
clipBehavior: Clip.antiAlias,
alignment: Alignment.center,
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF4D4D64), Color(0xFF363649)],
stops: [0, 1],
begin: AlignmentDirectional(1, -1),
end: AlignmentDirectional(-1, 1),
),
borderRadius: BorderRadius.circular(30),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// SvgPicture.asset(
// 'assets/icons/$index.svg',
// color: Colors.red,
// ),
Text(homeButtons[index]),
],
),
),
);
},
children: homeButtons
.map((index) => Container(
clipBehavior: Clip.antiAlias,
key: ValueKey(index),
alignment: Alignment.center,
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF4D4D64), Color(0xFF363649)],
stops: [0, 1],
begin: AlignmentDirectional(1, -1),
end: AlignmentDirectional(-1, 1),
),
borderRadius: BorderRadius.circular(30),
),
child: InkWell(
focusColor: Colors.transparent,
splashColor: Colors.transparent,
onTap: () {
// String path = '/$index';
// Get.toNamed(path);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// SvgPicture.asset(
// 'assets/icons/$index.svg',
// color: Colors.red,
// ),
Text(index),
],
),
),
))
.toList(),
onReorder: (oldIndex, newIndex) async {
String path = homeButtons.removeAt(oldIndex);
homeButtons.insert(newIndex, path);
// setState(() {
// box.remove(key);
// box.write(key, homeButtons);
// });
},
)

enter image description here

关于flutter - 如何去除圆角的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73610354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com