0

I am using Scaffold AppBar as a component for multiple time call and this is a separate class where I am using AppBar functionality but when I am using Navigator here context showing me the error because I am not using in BuildContext if anyone has the idea please share my code is here:

class AppBarComponent extends AppBar {
  AppBarComponent({Key key, int totalCartItems})
  : super(
  key: key,
  backgroundColor: Colors.greenAccent,
  centerTitle: true,
  title: Image.asset('images/logo.png',width: 120.0),
  actions: <Widget>[
    new IconButton(
      onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) =>ShoppingCart())),
      icon: Stack(
         children: <Widget>[
           Padding(
             padding: const EdgeInsets.only(right: 8.0,top: 4.0),
             child: Icon(Icons.shopping_cart,color: Colors.white,),
           ),
           Positioned(
             top: 0.0,
             right: 1.0,
             child: new Stack(
               children: <Widget>[
                 Icon(Icons.brightness_1, size: 16.0, color: Colors.red[800]),
                 Positioned(
                   top: 1.0,
                   right: 4.0,
                   child: new Text(totalCartItems.toString(),
                     style: new TextStyle(
                       color: Colors.white,
                       fontSize: 12.0,
                       fontWeight: FontWeight.w500
                      )
                    ),
                  )
                ],
              ),
            )
          ]
        )
     ),
   ],
 );
}

Flutter material_search is also not working here because of the same issue.

Rahul Mishra
  • 4,263
  • 7
  • 32
  • 53

0 Answers0