Reputation: 2966
This is my flutter code
import 'package:flutter/material.dart';
class Navbar extends StatefulWidget {
int tabIndex;
Navbar(this.tabIndex);
_NavbarState createState() => _NavbarState();
}
class _NavbarState extends State<Navbar> with SingleTickerProviderStateMixin {
// I need to get tabIndex here
}
I need to get tabIndex in second class, thank you so much for your answers
Upvotes: 4
Views: 2663
Reputation: 12559
You can create a tabIndex variable in your State
class and initialize it in your initState
with widget.tabIndex
.
class _NavbarState extends State<Navbar> with SingleTickerProviderStateMixin {
// I need to get tabIndex here
int tabIndex;
@override
void initState() {
tabIndex= widget.tabIndex;
super.initState();
}
}
Or you can just call it inside build
method with widget.tabIndex
.
Upvotes: 11