Notice: You're viewing an old version of the Nylo documentation.
Consider upgrading your project to Nylo 5.20.0.
Widgets

NySwitch



Introduction

In this section, we will learn about the NySwitch widget.

This widget can perform a 'switch' statement on the widgets that are passed to it. It makes it easy to switch between different widgets based on the index.

Let's take a look at some code.


Usage

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),
        ),
    );
}


Parameters

The NySwitch widget requires two parameters:

  • widgets - This is the list of widgets that will be displayed.
  • indexSelected - This is the index of the widget that should be displayed.

If you would like to know all the parameters available, visit this link here.