@@ -17,6 +17,7 @@ import '../models/page_args_model.dart';
1717import '../models/page_media_view_model.dart' ;
1818import '../models/routes_view_model.dart' ;
1919import '../protocol/keyboard_event.dart' ;
20+ import '../protocol/update_control_props_payload.dart' ;
2021import '../routing/route_parser.dart' ;
2122import '../routing/route_state.dart' ;
2223import '../routing/router_delegate.dart' ;
@@ -34,6 +35,7 @@ import '../widgets/page_media.dart';
3435import '../widgets/window_media.dart' ;
3536import 'app_bar.dart' ;
3637import 'create_control.dart' ;
38+ import 'navigation_drawer.dart' ;
3739import 'scroll_notification_control.dart' ;
3840import 'scrollable_control.dart' ;
3941
@@ -90,6 +92,8 @@ class _PageControlState extends State<PageControl> {
9092 late final RouteParser _routeParser;
9193 String ? _prevViewRoutes;
9294 bool _keyboardHandlerSubscribed = false ;
95+ bool ? _drawerOpened;
96+ bool ? _endDrawerOpened;
9397
9498 @override
9599 void initState () {
@@ -598,6 +602,8 @@ class _PageControlState extends State<PageControl> {
598602 Control ? appBar;
599603 Control ? fab;
600604 Control ? navBar;
605+ Control ? drawer;
606+ Control ? endDrawer;
601607 List <Widget > controls = [];
602608 bool firstControl = true ;
603609
@@ -611,6 +617,13 @@ class _PageControlState extends State<PageControl> {
611617 } else if (ctrl.type == "navigationbar" ) {
612618 navBar = ctrl;
613619 continue ;
620+ } else if (ctrl.type == "navigationdrawer" &&
621+ ctrl.name == "start" ) {
622+ drawer = ctrl;
623+ continue ;
624+ } else if (ctrl.type == "navigationdrawer" && ctrl.name == "end" ) {
625+ endDrawer = ctrl;
626+ continue ;
614627 }
615628 // spacer between displayed controls
616629 else if (spacing > 0 &&
@@ -626,10 +639,8 @@ class _PageControlState extends State<PageControl> {
626639 controls.add (createControl (control, ctrl.id, control.isDisabled));
627640 }
628641
629- List <String > childIds = [];
630- if (appBar != null ) {
631- childIds.add (appBar.id);
632- }
642+ List <String > childIds =
643+ [appBar? .id, drawer? .id, endDrawer? .id].whereNotNull ().toList ();
633644
634645 final textDirection = parent.attrBool ("rtl" , false )!
635646 ? TextDirection .rtl
@@ -651,10 +662,12 @@ class _PageControlState extends State<PageControl> {
651662 builder: (context, childrenViews) {
652663 debugPrint ("Route view StoreConnector build: $viewId " );
653664
654- var appBarView =
655- appBar != null && childrenViews.controlViews.isNotEmpty
656- ? childrenViews.controlViews.last
657- : null ;
665+ var appBarView = childrenViews.controlViews.firstWhereOrNull (
666+ (v) => v.control.id == (appBar? .id ?? "" ));
667+ var drawerView = childrenViews.controlViews.firstWhereOrNull (
668+ (v) => v.control.id == (drawer? .id ?? "" ));
669+ var endDrawerView = childrenViews.controlViews.firstWhereOrNull (
670+ (v) => v.control.id == (endDrawer? .id ?? "" ));
658671
659672 var column = Column (
660673 mainAxisAlignment: mainAlignment,
@@ -673,7 +686,55 @@ class _PageControlState extends State<PageControl> {
673686 ScrollNotificationControl (control: control, child: child);
674687 }
675688
689+ GlobalKey <ScaffoldState >? scaffoldKey =
690+ FletAppServices .of (context).globalKeys["_scaffold" ]
691+ as GlobalKey <ScaffoldState >? ;
692+ if (scaffoldKey == null ) {
693+ scaffoldKey = GlobalKey <ScaffoldState >();
694+ FletAppServices .of (context).globalKeys["_scaffold" ] =
695+ scaffoldKey;
696+ }
697+
698+ WidgetsBinding .instance.addPostFrameCallback ((_) {
699+ if (drawerView != null ) {
700+ if (drawerView.control.attrBool ("open" , false )! &&
701+ _drawerOpened != true ) {
702+ if (scaffoldKey? .currentState? .isEndDrawerOpen == true ) {
703+ scaffoldKey? .currentState? .closeEndDrawer ();
704+ }
705+ Future .delayed (const Duration (milliseconds: 1 ))
706+ .then ((value) {
707+ scaffoldKey? .currentState? .openDrawer ();
708+ _drawerOpened = true ;
709+ });
710+ } else if (! drawerView.control.attrBool ("open" , false )! &&
711+ _drawerOpened == true ) {
712+ scaffoldKey? .currentState? .closeDrawer ();
713+ _drawerOpened = false ;
714+ }
715+ }
716+ if (endDrawerView != null ) {
717+ if (endDrawerView.control.attrBool ("open" , false )! &&
718+ _endDrawerOpened != true ) {
719+ if (scaffoldKey? .currentState? .isDrawerOpen == true ) {
720+ scaffoldKey? .currentState? .closeDrawer ();
721+ }
722+ Future .delayed (const Duration (milliseconds: 1 ))
723+ .then ((value) {
724+ scaffoldKey? .currentState? .openEndDrawer ();
725+ _endDrawerOpened = true ;
726+ });
727+ } else if (! endDrawerView.control
728+ .attrBool ("open" , false )! &&
729+ _endDrawerOpened == true ) {
730+ scaffoldKey? .currentState? .closeEndDrawer ();
731+ _endDrawerOpened = false ;
732+ }
733+ }
734+ });
735+
676736 var scaffold = Scaffold (
737+ key: scaffoldKey,
677738 backgroundColor: HexColor .fromString (
678739 Theme .of (context), control.attrString ("bgcolor" , "" )! ),
679740 appBar: appBarView != null
@@ -685,6 +746,56 @@ class _PageControlState extends State<PageControl> {
685746 height: appBarView.control
686747 .attrDouble ("toolbarHeight" , kToolbarHeight)! )
687748 : null ,
749+ drawer: drawerView != null
750+ ? NavigationDrawerControl (
751+ control: drawerView.control,
752+ children: drawerView.children,
753+ parentDisabled: control.isDisabled,
754+ dispatch: widget.dispatch,
755+ )
756+ : null ,
757+ onDrawerChanged: (opened) {
758+ if (drawerView != null && ! opened) {
759+ _drawerOpened = false ;
760+ List <Map <String , String >> props = [
761+ {"i" : drawerView.control.id, "open" : "false" }
762+ ];
763+ widget.dispatch (UpdateControlPropsAction (
764+ UpdateControlPropsPayload (props: props)));
765+ FletAppServices .of (context)
766+ .server
767+ .updateControlProps (props: props);
768+ FletAppServices .of (context).server.sendPageEvent (
769+ eventTarget: drawerView.control.id,
770+ eventName: "dismiss" ,
771+ eventData: "" );
772+ }
773+ },
774+ endDrawer: endDrawerView != null
775+ ? NavigationDrawerControl (
776+ control: endDrawerView.control,
777+ children: endDrawerView.children,
778+ parentDisabled: control.isDisabled,
779+ dispatch: widget.dispatch,
780+ )
781+ : null ,
782+ onEndDrawerChanged: (opened) {
783+ if (endDrawerView != null && ! opened) {
784+ _endDrawerOpened = false ;
785+ List <Map <String , String >> props = [
786+ {"i" : endDrawerView.control.id, "open" : "false" }
787+ ];
788+ widget.dispatch (UpdateControlPropsAction (
789+ UpdateControlPropsPayload (props: props)));
790+ FletAppServices .of (context)
791+ .server
792+ .updateControlProps (props: props);
793+ FletAppServices .of (context).server.sendPageEvent (
794+ eventTarget: endDrawerView.control.id,
795+ eventName: "dismiss" ,
796+ eventData: "" );
797+ }
798+ },
688799 body: Stack (children: [
689800 SizedBox .expand (
690801 child: Container (
0 commit comments