我想在应用程序中修复底部导航栏



我想在我的应用程序的漏洞上修复bottomNavigationBar

当我改变屏幕时,底部导航栏消失了。所以我想修复我的应用程序的一个漏洞。

这是我代码的一部分:

class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('fa', 'iran'),
],
);
}
}
class MyNavigationBar extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyNavigationBar();
}
}
class _MyNavigationBar extends State<MyNavigationBar> {
int _selectedIndex = 0;
int _currentIndex = 0;
final String a= 'assets/icons/a.svg';
final String b= 'assets/icons/b.svg';
final String c= 'assets/icons/c.svg';
final String d= 'assets/icons/d.svg';
final String e= 'assets/icons/e.svg';
List<Widget> _pages = [
aScreen(),
bScreen(),
cScreen(),
dScreen(),
];
Stack _buildScreens() {
List<Widget> children = [];
_pages.asMap().forEach((index, value) {
children.add(
Offstage(
offstage: _currentIndex != index,
child: TickerMode(
enabled: _currentIndex == index,
child: value,
),
),
);
});
return Stack(children: children);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _buildScreens(),
),
bottomNavigationBar: Container(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54,
blurRadius: 15.0,
offset: Offset(0.0, 0.75))
],
),
child: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
type: BottomNavigationBarType.fixed,
unselectedLabelStyle: TextStyle(fontSize: 10.0, color: Colors.grey),
selectedIconTheme: IconThemeData(, size: 10),
selectedLabelStyle: TextStyle(color: Colors.grey),
unselectedItemColor: Colors.grey[900],
iconSize: 24,
selectedFontSize: 10,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Container(
child: SvgPicture.asset(
a,
width: 24,
height: 24,
),
),
activeIcon: Container(
child: SvgPicture.asset(
b,
width: 24,
height: 24,

),
),
),
BottomNavigationBarItem(
icon: Container(
child: SvgPicture.asset(
c,
width: 24,
height: 24,
),
),
activeIcon: Container(
child: SvgPicture.asset(
c,
width: 24,
height: 24,

),
),
),
BottomNavigationBarItem(
icon: Container(
child: SvgPicture.asset(
d,
width: 24,
height: 24,
),
),
activeIcon: Container(
child: SvgPicture.asset(
d,
width: 24,
height: 24,

),
),
),
BottomNavigationBarItem(
icon: Container(
// alignment: Alignment.center,
child: SvgPicture.asset(
e,
width: 24,
height: 24,
),
),
activeIcon: Container(
child: SvgPicture.asset(
e,
width: 24,
height: 24,

),
),

),
],
),
));
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
}

你有没有试过这样做:

Widget _buildScreens(int index) {
switch (index) {
case 0:
return FirstPage();
case 1:
return SecondPage();
...
default:
return FirstPage();
}
}

相关内容

  • 没有找到相关文章

最新更新