我是flutter新手,谁能指导我如何在导航栏()中调用长度或索引
import 'package:flutter/material.dart';
class MENU extends StatefulWidget {
const MENU({Key? key}) : super(key: key);
@override
State<MENU> createState() => _MENUState();
}
class _MENUState extends State<MENU> {
var pages = [Favourites(items: CatalogModel.items.length), MainMenu(), Profile()];
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: pages[_selectedIndex],
// BOTTOM NAVIGATION BAR
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Color(0xFFF3E5F5),
elevation: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.favorite_outline_sharp), label: "Specialities"),
BottomNavigationBarItem(icon: Icon(Icons.list), label: "Menu"),
BottomNavigationBarItem(icon: Icon(Icons.person), label: "Profile"),
],
currentIndex: _selectedIndex,
// selectedItemColor: Colors.amber[800],
onTap: (setValue) {
setState(() {
_selectedIndex = setValue;
});
},
),
floatingActionButton: FloatingActionButton.small(
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => CART()));
},
child: Icon(
CupertinoIcons.cart_badge_plus,
size: 25,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
);
}
}
我试图为 CatalogModel.items.index 提供索引,但它显示错误