Flutter微框架Nylo(十九):NySwitch组件

78 阅读1分钟

在本节中,我们将了解 NySwitch 组件。该组件可以根据索引在不同的 widget 之间轻松切换。

用法

int _currentIndex = 1;

@override
Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text("Dashboard")
        ),
        bottomNavigationBar: BottomNavigationBar(items: [
            BottomNavigationBarItem(icon: Icon(Icons.account_circle_outlined), label: "Account"),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Settings"),
        ], onTap: (index) {
        setState(() {
            _currentIndex = index;
        });
        }, currentIndex: _currentIndex),
        body: SafeArea(
            child: NySwitch(widgets: [
            AccountTab(),
            SettingsTab(),
            ], indexSelected: _currentIndex),
        ),
    );
}

此组件可以对传递给它的小部件执行“switch”语句。它使根据索引在不同的小部件之间切换变得容易。

参数

NySwitch 组件需要两个参数:

  • widgets - 这是将显示的小部件列表。
  • indexSelected - 这是应显示的小组件的索引。

如果您想了解所有可用的参数,请访问此处的此链接