底部导航样式实现
1、普通底部栏
1、中间凹起
3、中间悬浮
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'application_page.dart';
import 'article_page.dart';
import 'home_page.dart';
import 'mine_page.dart';
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int _currentIndex = 0;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
static final List<Widget> _pagesList = [
const HomePage(),
const ApplicationPage(),
const ArticlePage(),
const MinePage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: IndexedStack(
index: _currentIndex,
children: _pagesList,
),
bottomNavigationBar: BottomAppBar(
color: Colors.brown,
shape: const CircularNotchedRectangle(),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
_buildIconButton(0, Icon(Icons.home, size: 24.r)),
_buildIconButton(1, Icon(Icons.settings_applications, size: 24.r)),
SizedBox(
width: 50.w,
),
_buildIconButton(2, Icon(Icons.article, size: 24.r)),
_buildIconButton(3, Icon(Icons.person, size: 24.r)),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [Icon(Icons.add)])),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
Widget _buildIconButton(int index, Icon icon) {
return IconButton(
icon: icon,
color: _currentIndex == index ? Colors.blue : Colors.grey,
onPressed: () {
setState(() {
_currentIndex = index;
});
},
);
}
}