大佬教程收集整理的这篇文章主要介绍了使用颤动的底部导航中的下拉列表,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以通过单击 BottomNavigationbarItem
按钮之一来显示水平列表?我想要的是,如果用户点击 Clothes
标签,衣服列表将如下图所示。
这是我现有的代码
final List<Widget> _Widgets = <Widget>[
ClothesPage(),colorsPage(),IDeasPage(),ProfilePage(),];
class _MyHomePageState extends State<MyHomePage> {
int _currenTindex = 0;
Widget build(BuildContext context) {
final colorscheR_438_11845@e = theme.of(context).colorscheR_438_11845@e;
final texttheme = theme.of(context).texttheme;
return Scaffold(
// This body is new.
body: _Widgets[_currenTindex],bottomNavigationbar: BottomNavigationbar(
type: BottomNavigationbarType.fixed,currenTindex: _currenTindex,BACkgroundcolor: colors.orangeAccent,SELEctedItemcolor: colors.white,unSELEctedItemcolor: colorscheR_438_11845@e.onSurface.withOpacity(.40),SELEctedLabelStyle: texttheme.caption,unSELEctedLabelStyle: texttheme.caption,onTap: (value) {
_currenTindex = value;
showDialog(
context: context,barrIErdismissible: true,builder: (BuildContext context) {
return column(
mainAxisAlignment: MainAxisAlignment.end,children: [
_Widgets[_currenTindex],SizedBox(
// Use @R_197_10112@ever height you desire.
height: 90,),],);
},);
},items: [
BottomNavigationbarItem(
title: Text('Clothes'),icon: Icon(Icons.design_services_rounded),BottomNavigationbarItem(
title: Text('colors'),icon: Icon(Icons.colorize_rounded),BottomNavigationbarItem(
title: Text('IDeas'),icon: Icon(Icons.lightbulb_outline_rounded),BottomNavigationbarItem(
title: Text('Profile'),icon: Icon(Icons.face_rounded),);
}
}
class ClothesPage extends StatelessWidget {
@overrIDe
Widget build(BuildContext context) {
return new Card(
elevation: 9.0,shape: new RoundedRectangleborder(
borderRadius: new borderRadius.circular(20.0)),child: new Container(
decoration: Boxdecoration(
image: decorationImage(
image: Assetimage(
'assets/shirt/white-shirt1.jpg'),// Use the path here.
fit: BoxFit.cover,);
}
}
class colorsPage extends StatelessWidget {
@overrIDe
Widget build(BuildContext context) {
return Card(
color: colors.white,child: padding(
padding: EdgeInsets.all(10),child: Text(
"color",);
}
}
class IDeasPage extends StatelessWidget {
@overrIDe
Widget build(BuildContext context) {
return Card(
color: colors.white,child: Text(
"IDea",);
}
}
class ProfilePage extends StatelessWidget {
@overrIDe
Widget build(BuildContext context) {
return Card(
color: colors.white,child: Text(
"Profile",);
}
}
当您将 showDialog
作为 _widgets[_currenTindex]
的主体时,Scaffold
是不必要的。你可以这样做:
showDialog
的 onTap
属性中的 BottomNavigationBar
并使用 setState()
:BottomNavigationBar(
// ... other lines
onTap: (value) {
// This notify the widget to rebuild,without it the screen will not react to your gesture
setState(() {
_currenTindex = value;
});
},)
ListView
中添加 ClothesPage
。完整的工作代码:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',theme: ThemeData(
priMarySwatch: Colors.indigo,),home: SomeScreen(),);
}
}
class SomeScreen extends StatefulWidget {
@override
_SomeScreenState createState() => _SomeScreenState();
}
class _SomeScreenState extends State<SomeScreen> {
var _currenTindex = 0;
final List<Widget> _widgets = <Widget>[
ClothesPage(),Container(),];
@override
Widget build(BuildContext context) {
return Scaffold(
// This body is new.
body: _widgets[_currenTindex],bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,currenTindex: _currenTindex,BACkgroundColor: Colors.orangeAccent,SELEctedItemColor: Colors.white,onTap: (value) {
// This notify the widget to rebuild,without it the screen will not react to your gesture
setState(() {
_currenTindex = value;
});
},items: [
BottomNavigationBarItem(
title: Text('Clothes'),icon: Icon(Icons.design_services_rounded),BottomNavigationBarItem(
title: Text('Colors'),icon: Icon(Icons.colorize_rounded),BottomNavigationBarItem(
title: Text('Ideas'),icon: Icon(Icons.lightbulb_outline_rounded),BottomNavigationBarItem(
title: Text('Profile'),icon: Icon(Icons.face_rounded),],);
}
}
class ClothesPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return column(
mainAxisAlignment: MainAxisAlignment.spacebetween,children: [
Expanded(
child: new Card(
elevation: 9.0,shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0)),child: new Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/shirt/white-shirt1.jpg'),// Use the path here.
fit: BoxFit.cover,Container(
height: 150,child: ListView.separated(
shrinkWrap: true,scrollDirection: Axis.horizontal,itemBuilder: (context,indeX) => Container(
color: Colors.blue,width: 150,//! Modify the width of each item
child:
Container(),//! Add your clothing product photos here
),separatorBuilder: (context,indeX) => Container(
color: Colors.grey,width: 2,itemCount: 5),// number of your clothing products
)
],);
}
}
以上是大佬教程为你收集整理的使用颤动的底部导航中的下拉列表全部内容,希望文章能够帮你解决使用颤动的底部导航中的下拉列表所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。