我正在尝试构建一个 Flutter 应用程序,我想在其中使用底部导航栏。但是在项目长度更长的底部导航项目上,文本不会换行。我想将文本换行到下一行。
以下是正在发生的事情的图像:
以下是代码:
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState(imageurl, name, email);
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
bottomNavigationBar: Theme(
data: Theme.of(context).copyWith(
// sets the background color of the `BottomNavigationBar`
canvasColor: Colors.white,
// sets the active color of the `BottomNavigationBar` if `Brightness` is light
primaryColor: Colors.red,
textTheme: Theme.of(context)
.textTheme
.copyWith(caption: new TextStyle(color: Colors.yellow))),
child: SizedBox(
height: 90,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BottomNavigationBar(
selectedItemColor: Colors.orange,
type: BottomNavigationBarType.fixed,
unselectedFontSize: 12,
elevation: 2,
currentIndex: 2, // this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: new Icon(
Icons.home_outlined,
color: Colors.black,
),
title: Flexible(
child: new Text(
'Home',
style: TextStyle(
color: Colors.black,
),
),
),
),
BottomNavigationBarItem(
icon: new Icon(
Icons.star_border,
color: Colors.black,
),
title: Flexible(
child: new Text(
‘Decideit who,
style: TextStyle(
color: Colors.black,
),
),
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.location_city,
//color: Colors.black,
),
title: Flexible(
child: Text(
'Post Question',
style: TextStyle(
color: Colors.black,
),
),
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.people_outline,
color: Colors.black,
),
title: Flexible(
child: Text(
'Communities',
style: TextStyle(
color: Colors.black,
),
),
)),
BottomNavigationBarItem(
icon: Icon(
Icons.person_outline,
color: Colors.black,
),
title: Flexible(
child: Text(
'Profile',
style: TextStyle(
color: Colors.black,
),
),
))
],
),
],
),
),
),
);
}
}
有人可以帮助我如何在下一行中显示 ... 文本吗?
我想你可以将你的文本小部件包装在一个像SizedBox
or的元素中,Expaned
然后做类似的事情:
BottomNavigationBarItem(
icon: Icon(
Icons.people_outline,
color: Colors.black,
),
title: Expanded(
child: Text(
'Communities',
maxLines: 4 // however many lines you would want as a maximum
style: TextStyle(
color: Colors.black,
),
),
),
),
或
BottomNavigationBarItem(
icon: Icon(
Icons.people_outline,
color: Colors.black,
),
title: SizedBox(
height: 80
child: Text(
'Communities',
maxLines: 4 // however many lines you would want as a maximum
style: TextStyle(
color: Colors.black,
),
),
),
),
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句