0
final int selectedIndex = 0;
var heightOfDevice = MediaQuery.of(context).size.height;
return SafeArea(
  child: Scaffold(
    bottomNavigationBar: const GNav(
      backgroundColor: Color(0xFF242A38),
      color: Colors.white,
      activeColor: Color(0xFFF54B64),
      gap: 8,
      onTabChange: (index) {
        
        // Here the index is raising error as invalid constant value
      },
      tabs: [
        GButton(
          icon: Icons.home,
          text: 'Home',
        ), // Etc.
      ]
    )
  )
)

I don't know why I am getting that error, I have initialized everything correctly, I want to navigate to another page but here I am getting stopped, as the index is raising the error as invalid constant.

user16217248
  • 3,119
  • 19
  • 19
  • 37

1 Answers1

0

You can't GNav const with current structure because you are calling (executing) the function which will be on runtime rather than compile time.

bottomNavigationBar: GNav(
  onTabChange: (index) {}

But you can create function and pass it on onTabChange:functionName and it can be const.

void onTapChange(int index) {
  print(index);
}
....
bottomNavigationBar: const GNav(
  onTabChange: onTapChange,

You can check What is the difference between the "const" and "final" keywords in Dart?

halfer
  • 19,824
  • 17
  • 99
  • 186
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56