title: Simultaneous Navbar index page change
body: <p>sorry for my english I am a French baguette</p>
  <p>Here is my question, I was wondering how I could switch pages while moving my index in the NavBar I have already tried the solution above but my crash after a few seconds I wonder why?</p>
  <p><strong>Here is the code of my homepage</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/painting.dart';
  import 'package:flutter_application_1/views/screenmaps_view.dart';
  import 'package:flutter_application_1/views/screenussers_views.dart';
  
  class HomeScreen extends StatefulWidget {
    const HomeScreen({Key? key}) : super(key: key);
  
    @override
    State&lt;HomeScreen&gt; createState() =&gt; _HomeScreenState();
  }
  
  class _HomeScreenState extends State&lt;HomeScreen&gt; {
    int _selectedItemIndex = 0;
    int setPageIndex = 0;
  
    final pages = [
      HomeScreen(),
      PageMaps(),
      userpage(),
    ];
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: pages[setPageIndex], //the line that makes me crash my application
        //backgroundColor: Colors.amber,
        bottomNavigationBar: Row(
          children: [
            newNavBarItem(Icons.home_outlined, 0),
            newNavBarItem(Icons.map_outlined, 1),
            newNavBarItem(Icons.home, 2),
          ],
        ),
      );
    }
  
    Widget newNavBarItem(IconData icon, int index) {
      return GestureDetector(
        onTap: () {
          setState(() {
            _selectedItemIndex = index;
            setPageIndex = index;
          });
        },
        child: Container(
            height: 70,
            width: MediaQuery.of(context).size.width / 3,
            decoration: index == _selectedItemIndex
                ? BoxDecoration(
                    border: Border(
                      bottom: BorderSide(width: 4, color: Color(0xff238ADC)),
                    ),
                    gradient: LinearGradient(colors: [
                      Color(0xff7EC1F6).withOpacity(0.3),
                      Color(0xff7EC1F6).withOpacity(0.015)
                    ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
                  )
                : BoxDecoration(),
            child: Icon(icon,
                color:
                    index == _selectedItemIndex ? Colors.black : Colors.black)),
      );
    }
  }
  
  </code></pre>
  <p>I initialized a variable &quot;setPageIndex&quot; with the value of the index of the navbar to associate it with the body to display but without success the report of the crash is lower</p>
  <pre><code>@override
    Widget build(BuildContext context) {
      return Scaffold(
        body: pages[setPageIndex], //the line that makes me crash my application
        //backgroundColor: Colors.amber,
        bottomNavigationBar: Row(
          children: [
            newNavBarItem(Icons.home_outlined, 0),
            newNavBarItem(Icons.map_outlined, 1),
            newNavBarItem(Icons.home, 2),
          ],
        ),
      );
    }
  </code></pre>
  <p><strong>here is the error from errors_path.dart</strong></p>
  <pre><code>@pragma(&quot;vm:external-name&quot;, &quot;AssertionError_throwNew&quot;)
    external static _doThrowNew(
        int assertionStart, int assertionEnd, Object? message);
    @pragma(&quot;vm:external-name&quot;, &quot;AssertionError_throwNewSource&quot;)
    external static _doThrowNewSource(
        String failedAssertion, int line, int column, Object? message);
  </code></pre>
  <p><strong>and here is the err of my debug console</strong></p>
  <pre><code>
  #24     DiagnosticsNode.toString
  package:flutter/…/foundation/diagnostics.dart:1706
  #25     Diagnosticable.toString.&lt;anonymous closure&gt;
  package:flutter/…/foundation/diagnostics.dart:3168
  #26     Diagnosticable.toString
  package:flutter/…/foundation/diagnostics.dart:3170
  #27     _StringBase._interpolate (dart:core-patch/string_patch.dart:853:19)
  #28     ComponentElement.performRebuild
  package:flutter/…/widgets/framework.dart:4785
  #29     StatefulElement.performRebuild
  package:flutter/…/widgets/framework.dart:4928
  #30     Element.rebuild
  package:flutter/…/widgets/framework.dart:4477
  #31     ComponentElement._firstBuild
  package:flutter/…/widgets/framework.dart:4735
  #32     StatefulElement._firstBuild
  package:flutter/…/widgets/framework.dart:4919
  #33     ComponentElement.mount
  package:flutter/…/widgets/framework.dart:4729
  ...     Normal element mounting (7 frames)
  #40     Element.inflateWidget
  package:flutter/…/widgets/framework.dart:3790
  #41     Element.updateChild
  package:flutter/…/widgets/framework.dart:3540
  #42     ComponentElement.performRebuild
  package:flutter/…/widgets/framework.dart:4780
  #43     Element.rebuild
  package:flutter/…/widgets/framework.dart:4477
  2
  ...
  ...     Normal element mounting (21 frames)
  #4821   Element.inflateWidget
  package:flutter/…/widgets/framework.dart:3790
  #4822   Element.updateChild
  package:flutter/…/widgets/framework.dart:3540
  #4823   RenderObjectToWidgetElement._rebuild
  package:flutter/…/widgets/binding.dart:1198
  #4824   RenderObjectToWidgetElement.mount
  package:flutter/…/widgets/binding.dart:1167
  #4825   RenderObjectToWidgetAdapter.attachToRenderTree.&lt;anonymous closure&gt;
  package:flutter/…/widgets/binding.dart:1112
  #4826   BuildOwner.buildScope
  package:flutter/…/widgets/framework.dart:2600
  #4827   RenderObjectToWidgetAdapter.attachToRenderTree
  package:flutter/…/widgets/binding.dart:1111
  #4828   WidgetsBinding.attachRootWidget
  package:flutter/…/widgets/binding.dart:944
  #4829   WidgetsBinding.scheduleAttachRootWidget.&lt;anonymous closure&gt;
  package:flutter/…/widgets/binding.dart:924
  (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
  ════════════════════════════════════════════════════════════════════════════════
  </code></pre>
  <p>If things seem special to you in the code, I'm starting by the way, tell me if something is wrong :)</p>
  <p>and thank you for reading my threads</p>