Reputation: 1
I am trying to add a BottomNavigationBarItem and give it a different icon and label. then I tried to change the pages when you click on them: but it gives me three message errors:
The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.
The operator '[]' isn't defined for the type 'int'.
Try defining the operator '[]'.
The argument type 'Object?' can't be assigned to the parameter type 'Widget?'.
When I searched for the solution I have known that it is an sdk-type issue but couldn't know how to solve it without changing the sdk I am kind of new in flutter
class _TaskscreenState extends State<Taskscreen> {
List<Map<String, Object>> get _pages => [
{
'page': provincesScreen(),
'title': 'org',
},
{
'page': FavouritScreen(),
'title': 'your favourits',
},
];
int _selectedpageIndex = 0;
void _selectedPage(int value) {
setState(() {
_selectedpageIndex = value;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:
AppBar(title: Text(_pages[_selectedpageIndex['title']])),
body:_pages[_selectedpageIndex]['page'],
bottomNavigationBar: BottomNavigationBar(
onTap: _selectedPage,
backgroundColor: Colors.blueGrey,
selectedItemColor: Colors.purple,
unselectedItemColor: Colors.white,
currentIndex: _selectedpageIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.category),
label: ('categories'),
),
BottomNavigationBarItem(
icon: Icon(Icons.star),
label: ('favourites'),
),
BottomNavigationBarItem(
icon: Icon(Icons.star),
label: ('Rating'),
),
],
),
);
}
}
Upvotes: 0
Views: 480
Reputation: 9196
you put this wrong
AppBar(title: Text(_pages[_selectedpageIndex['title']])),
correct it to:
AppBar(title: Text(_pages[_selectedpageIndex]['title'])),
Upvotes: 0