I am using Getx package for state management in my project. I have written appbar as a separate dart file and have called it in the screens where necessary. I have a bottom navigation bar in the main page. When I navigate to a page other than the main home page (Body.dart) say I press a submit button and go to next page, I click the icon(Paths.switchInstance - in the code) but the end drawer does not open. When I navigate back to the main home page, the end drawer is already opened. Why does the end drawer not open in pages other than the main home page? Is it because the other page has a different context? Can someone suggest a solution?
appbar.dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import '../controllers/app_bar_controller.dart';
import '../constants/paths.dart';
import '../controllers/animated_container_controller.dart';
import '../controllers/tender_stage_search_controller.dart';
import '../custom_widgets/translucent_circle_avatar.dart';
import 'gradient_container.dart';
class AppBarDomainSpecific extends StatelessWidget {
AppBarDomainSpecific({Key? key}) : super(key: key);
final AnimatedContainerController bodyController =
Get.find<AnimatedContainerController>();
final TenderStageSearchController tenderStageSearchController =
Get.find<TenderStageSearchController>();
final AppBarController appBarController = Get.find<AppBarController>();
var width = Get.width;
@override
Widget build(BuildContext context) {
return
// PreferredSize(
// preferredSize: Size.fromHeight(Get.height * 0.05),
// child:
AppBar(
actions: [Container()],
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: bodyController.isDrawerOpen.value == true
? const Radius.circular(10.0)
: Radius.zero,
bottomRight: const Radius.circular(18.0),
bottomLeft: const Radius.circular(18.0))),
flexibleSpace: AppGradientContainer(
containerHeight: width * 0.17,
containerBorderRadius: BorderRadius.only(
topLeft: bodyController.isDrawerOpen.value == true
? Radius.circular(10) //width * 0.07)
: Radius.zero,
bottomRight: const Radius.circular(18),
bottomLeft: const Radius.circular(18)),
//containerHeight: Get.height * 0.2,
containerChild: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// bodyController.isDrawerOpen.value == true
// ? IconButton(
// onPressed: () {
// bodyController.drawerClosed();
// bottomNavBarController.doAnimation();
// },
// icon: const Icon(
// Icons.close,
// color: Colors.white,
// ))
// :
bodyController.isDrawerOpen.value == true
? SvgPicture.asset(Paths.hamburgerMenu)
: tenderStageSearchController.isSubmitPressed.value
? InkWell(
onTap: () {
tenderStageSearchController.submitPressed();
Get.back();
},
child:
// TranslucentCircleAvatar(
// radius: 15,
// child:
SvgPicture.asset(
Paths.backButton,
width: width * 0.07,
height: width * 0.07,
)
// )
)
: InkWell(
child: SvgPicture.asset(Paths.hamburgerMenu),
onTap: () {
bodyController.drawerOpened();
//bottomNavBarController.doAnimation();
},
),
SizedBox(
width: 5,
),
Padding(
padding: EdgeInsets.only(
top: 5, bottom: 5, right: 10, left: 10),
child: SvgPicture.asset(Paths.tamilNaduLogo)),
Text(
'Tenders Tamil Nadu',
style: TextStyle(
fontSize: Get.width * 0.044,
color: Colors.white,
fontWeight: FontWeight.w900),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
appBarController.openAppEndDrawer();
//Scaffold.of(context).openEndDrawer();
},
// () => Get.to(
// () => SwitchInstance(),
// ),
child: TranslucentCircleAvatar(
radius: 15,
child: SvgPicture.asset(Paths.switchInstance),
),
),
const SizedBox(
width: 15,
),
InkWell(
onTap: () {
print('Button pressed');
},
child: TranslucentCircleAvatar(
radius: 15,
child: SvgPicture.asset(Paths.search),
),
),
],
),
],
)),
)
//)
;
}
}
This is my appbar controller:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class AppBarController extends GetxController {
var scaffoldKey = GlobalKey<ScaffoldState>();
void openAppEndDrawer() {
scaffoldKey.currentState!.openEndDrawer();
}
}