我想在我的应用程序中添加底部导航但是当我想添加这一行
_children[_selectedIndex],
但我如何添加这一行因为我在不同的文件中创建导航但在 home.dart 文件中我如何在正文中添加这一行?飞镖主页代码:
import 'package:flutter/material.dart';
import 'package:try_custom_list_view/widget/bottom_nav.dart';
import 'package:try_custom_list_view/widget/drawer.dart';
import 'package:try_custom_list_view/widget/list_view.dart';
class SampleApp extends StatefulWidget {
@override
_SampleAppState createState() => _SampleAppState();
}
class _SampleAppState extends State<SampleApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Gaming Shayari"),
),
body: ListViewFromApi(),
drawer: MyDrawer(),
bottomNavigationBar: MyNavBar(),
);
}
}
底部导航飞镖文件代码:
import 'package:flutter/material.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:line_icons/line_icons.dart';
import 'package:try_custom_list_view/trending.dart';
import 'package:try_custom_list_view/widget/list_view.dart';
class MyNavBar extends StatefulWidget {
@override
_MyNavBarState createState() => _MyNavBarState();
}
class _MyNavBarState extends State<MyNavBar> {
int _selectedIndex = 0;
final List<Widget> _children = <Widget>[
ListViewFromApi(),
MyTrending(),
];
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 20,
color: Colors.black.withOpacity(.1),
)
],
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 8),
child: GNav(
gap: 12,
activeColor: Colors.white,
iconSize: 24,
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
duration: Duration(milliseconds: 600),
tabBackgroundColor: Colors.grey[800],
tabs: [
GButton(
icon: LineIcons.home,
text: 'Home',
backgroundColor: Colors.purple,
),
GButton(
icon: LineIcons.plus_circle,
text: 'Add Your Poetry',
backgroundColor: Colors.green,
),
GButton(
icon: LineIcons.fire,
text: 'Trending',
backgroundColor: Colors.red,
),
],
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
_selectedIndex = index;
});
},
),
)));
}
}
我在哪里放置此代码以在页面之间导航? _children[_selectedIndex],