`
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class BottomNavBarWidget extends StatefulWidget {
@override
_BottomNavBarWidgetState createState() => _BottomNavBarWidgetState();
}
class _BottomNavBarWidgetState extends State<BottomNavBarWidget> {
@override
Widget build(BuildContext context) {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
// navigateToScreens(index);
});
}
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'Home',
style: TextStyle(color: Color(0xFF2c2b2b)),
),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Color(0xFFfd5352),
onTap: _onItemTapped,
);
}
}
I was assigned to run a mobile application with the Flutter framework. But I don’t understand how to use "title" in the navbar item, of course with style. Therefore, I want to ask, "How do I fix the error in the code?" and how to include a proper "title" parameter in Flutter?
3
Answers
instead of defining the
title
onBottomNavigationBarItem
because it doesn’t exist anymore, you should use thelabel
which accepts aString
, like this:In updated flutter version
title
is migrated withlabel
.Use it like :
title
parameter is deprecated by the flutter, either use a previous flutter version or change your title parameter tolabel
which accepts onlystring
as a parameter.For styling the text use customized theme in material app for example: