您需要将Body和BottomNavigationBar放在Stack下,以便可以将BottomNavigationBar放在主体内容的顶部。
您的完整代码将是:
import 'package:flutter/material.dart';class App extends StatelessWidget { @override Widget build(BuildContext context) { final List<Widget> _children = [ Center( child: Container( height: 850, // use 'MediaQuery.of(context).size.height' to fit the screen height, color: Colors.red, ), ) ]; return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Stack( children: <Widget>[ _children[0], Positioned( left: 0, right: 0, bottom: 0, child: bottomNavigationBar(), ), ], ), )); }}Widget bottomNavigationBar() { return Container( margin: EdgeInsets.only(left: 16, right: 16), decoration: BoxDecoration( color: Colors.amber, borderRadius: BorderRadius.only( topLeft: Radius.circular(200), topRight: Radius.circular(200)), ), child: BottomNavigationBar( backgroundColor: Colors.transparent, showUnselectedLabels: true, type: BottomNavigationBarType.fixed, elevation: 0, items: [ BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')), BottomNavigationBarItem( icon: Icon(Icons.local_activity), title: Text('Activity')), BottomNavigationBarItem(icon: Icon(Icons.inbox), title: Text('Inbox')), BottomNavigationBarItem( icon: Icon(Icons.person), title: Text('Profile')), ], ), );}来自的部分代码:如何在Flutter应用中将边框半径设置为底部应用栏?
将其放入堆栈中。不要将“底部导航栏”直接添加到支架中。
class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Some Text'), ), body: Stack( children: <Widget>[ bodyContent, Positioned( left: 0, right: 0, bottom: 0, child: bottomNavigationBar, ), ], ), ); } Widget get bodyContent { return Container(color: Colors.red); } Widget get bottomNavigationBar { return ClipRRect( borderRadius: BorderRadius.only( topRight: Radius.circular(40), topLeft: Radius.circular(40), ), child: BottomNavigationBar( items: [ BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('1')), BottomNavigationBarItem(icon: Icon(Icons.usb), title: Text('2')), BottomNavigationBarItem( icon: Icon(Icons.assignment_ind), title: Text('3')), BottomNavigationBarItem( icon: Icon(Icons.multiline_chart), title: Text('4')), ], unselectedItemColor: Colors.grey, selectedItemColor: Colors.black, showUnselectedLabels: true, ), ); }}


