I'm using flutter-riverpod
for state management in my app. Since for using Riverpod, I have to change my Stateful widget
into a consumer widget
, I couldn't access setState()
. Now, after writing state management code for bottom bar using Riverpod
, it does not work.
Here is my code-
int index = 0;
class HomePage extends ConsumerWidget {
final currentIndex = Provider<int>((ref) => index);
Widget build(BuildContext context, ScopedReader watch) {
int _currentIndex = watch(currentIndex);
return auth.when(//authstatchange provider
data: (e) {
if (e!=null&&e.uid != null) {
return Scaffold(
body: PageView(
physics: NeverScrollableScrollPhysics(),
controller: _pageController,
onPageChanged: (ind) {
index = ind;
},
children: [
SomePage(),
],
),
bottomNavigationBar: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
someCode(),
),
child: SomeCode(),)
tabBackgroundColor: Colors.grey[800],
tabs: [
tabs()
],
selectedIndex: _currentIndex,
onTabChange: (ind) {
index = ind;
_pageController.jumpToPage(index);
)//closing brackets (omitted)
//brackets