【发布时间】:2021-11-27 14:47:24
【问题描述】:
如何从底部导航栏项单击打开底部工作表。这是我当前的页面代码,这是我迄今为止尝试过的,但它似乎不起作用。我已经成功创建了底部导航栏,并且使用了 Page1()、Page2()、Page3() 功能,我可以成功迁移到其他页面,现在我需要第四个项目来打开一个底部工作表,我可以在其中做更多项目.函数 showBottomSheet() 应该能够打开一个底页
class _MyNavigationBarState extends State<MyNavigationBar > {
int _currentTabIndex = 0;
@override
Widget build(BuildContext context) {
final _kTabPages = <Widget>[
Page1(),
Page2(),
Page3(),
showBottomSheet()
];
final _kBottmonNavBarItems = <BottomNavigationBarItem>[
const BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
const BottomNavigationBarItem(icon: Icon(Icons.network_cell), label: 'Prices'),
const BottomNavigationBarItem(icon: Icon(Icons.add_circle), label: 'Trade'),
const BottomNavigationBarItem(icon: Icon(Icons.account_balance_wallet), label: 'Wallet'),
];
assert(_kTabPages.length == _kBottmonNavBarItems.length);
final bottomNavBar = BottomNavigationBar(
items: _kBottmonNavBarItems,
currentIndex: _currentTabIndex,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
_currentTabIndex = index;
});
},
);
return Scaffold(
body: _kTabPages[_currentTabIndex],
bottomNavigationBar: bottomNavBar,
),
);
}
}
showBottomSheet(){
Container _buildBottomSheet(BuildContext context) {
return Container(
height: 300,
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.circular(8.0),
),
child: ListView(
children: <Widget>[
const ListTile(title: Text('Bottom sheet')),
const TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
border: OutlineInputBorder(),
icon: Icon(Icons.attach_money),
labelText: 'Enter an integer',
),
),
Container(
alignment: Alignment.center,
child: ElevatedButton.icon(
icon: const Icon(Icons.save),
label: const Text('Save and close'),
onPressed: () => Navigator.pop(context),
),
)
],
),
);
}
}
【问题讨论】:
标签: flutter flutter-ios flutter-android