2

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

anticafe
  • 6,816
  • 9
  • 43
  • 74
Rohan
  • 55
  • 5
  • Has been some time - but this looks like a duplicate of this earlier question, that has an accepted answer written by Remi R, the creator of Riverpod. https://stackoverflow.com/questions/64435989/flutter-navigationbar-with-riverpod – Alexandre Jean May 17 '21 at 02:15

1 Answers1

-1

Solved, if you use state Provider then rebuild state. state

James Risner
  • 5,451
  • 11
  • 25
  • 47
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33037117) – Nikhileshwar Nov 01 '22 at 10:55