【发布时间】:2020-06-02 18:28:04
【问题描述】:
我正在尝试创建一个透明的底部导航栏,这是我的底部栏部分:
Align(
alignment: Alignment.bottomCenter,
child: Theme(
data: Theme.of(context)
.copyWith(canvasColor: Colors.transparent),
child: BottomNavigationBar(
currentIndex: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.location_on),
title: Text('Map')),
BottomNavigationBarItem(
icon: Icon(Icons.line_style),
title: Text('List')),
BottomNavigationBarItem(
icon: Icon(Icons.add), title: Text('Add Property'))
],
))),
这是我完整的Scafold Widget:
return Scaffold(
backgroundColor: AppTheme.white,
body: FutureBuilder<bool>(
future: getData(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
} else {
return Padding(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
appBar(),
// tabBar(),
Expanded(
child: FutureBuilder<bool>(
future: getData(),
builder:
(BuildContext context, AsyncSnapshot<bool> snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
} else {
return ChangeNotifierProvider(
create: (context) => Properties(),
child: PropertiesGrid(_showOnlyFavorites),
);
}
},
),
),
Align(
alignment: Alignment.bottomCenter,
child: Theme(
data: Theme.of(context)
.copyWith(canvasColor: Colors.transparent),
child: BottomNavigationBar(
currentIndex: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.location_on),
title: Text('Map')),
BottomNavigationBarItem(
icon: Icon(Icons.line_style),
title: Text('List')),
BottomNavigationBarItem(
icon: Icon(Icons.add), title: Text('Add Property'))
],
))),
],
),
);
}
},
),
);
}
Widget appBar() {
return SizedBox(
height: AppBar().preferredSize.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8, left: 8),
child: Container(
width: AppBar().preferredSize.height - 8,
height: AppBar().preferredSize.height - 8,
),
),
Expanded(
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 4),
child:
Image.asset('assets/images/logo.png', fit: BoxFit.contain),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 8, right: 8),
child: Container(
width: AppBar().preferredSize.height - 8,
height: AppBar().preferredSize.height - 8,
color: Colors.white,
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius:
BorderRadius.circular(AppBar().preferredSize.height),
child: Icon(
Icons.location_on,
color: AppTheme.dark_grey,
),
onTap: () {
setState(() {
multiple = !multiple;
});
},
),
),
),
),
],
),
);
}
Widget tabBar() {
return SizedBox(
height: AppBar().preferredSize.height,
);
}
}
但我发现它没有像透明条那样显示页面背景,如下图所示
我希望有人能帮我找出问题到底出在哪里..
【问题讨论】:
-
你试过 backgroundColor : Colors.transparent 吗?
-
@PeterHaddad 是的,我试过了,结果是一样的
-
将属性 elevation: 0.0 添加到您的 BottomNavigationBar,您看到的是一个阴影,因为海拔是 8.0 默认值。你也可以只添加属性 background: Colors.transparent 而不是用 Theme Widget 包装你的 BottomNavigationBar
-
@EdwynZN 已解决,但背景仍然是白色
-
如果您将其颜色设置为透明,并将脚手架设置为白色,它会显示脚手架背景颜色,或者您期望的颜色是什么?