@@ -742,6 +742,160 @@ void main() {
742742 expect (nestedObserver.licensePageCount, 0 );
743743 });
744744
745+ group ('Barrier dismissible' , () {
746+ late AboutDialogObserver rootObserver;
747+
748+ setUpAll (() {
749+ rootObserver = AboutDialogObserver ();
750+ });
751+
752+ testWidgets ('Barrier is dismissible with default parameter' , (WidgetTester tester) async {
753+ await tester.pumpWidget (
754+ MaterialApp (
755+ navigatorObservers: < NavigatorObserver > [rootObserver],
756+ home: Material (
757+ child: Center (
758+ child: Builder (
759+ builder: (BuildContext context) {
760+ return ElevatedButton (
761+ child: const Text ('X' ),
762+ onPressed: () => showAboutDialog (
763+ context: context,
764+ ),
765+ );
766+ },
767+ ),
768+ ),
769+ ),
770+ ),
771+ );
772+
773+ // Open the dialog.
774+ await tester.tap (find.byType (ElevatedButton ));
775+ await tester.pumpAndSettle ();
776+ expect (rootObserver.dialogCount, 1 );
777+
778+ // Tap on the barrier.
779+ await tester.tapAt (const Offset (10.0 , 10.0 ));
780+ await tester.pumpAndSettle ();
781+ expect (rootObserver.dialogCount, 0 );
782+ });
783+
784+ testWidgets ('Barrier is not dismissible with barrierDismissible is false' , (WidgetTester tester) async {
785+ await tester.pumpWidget (
786+ MaterialApp (
787+ navigatorObservers: < NavigatorObserver > [rootObserver],
788+ home: Material (
789+ child: Center (
790+ child: Builder (
791+ builder: (BuildContext context) {
792+ return ElevatedButton (
793+ child: const Text ('X' ),
794+ onPressed: () => showAboutDialog (
795+ context: context,
796+ barrierDismissible: false
797+ ),
798+ );
799+ },
800+ ),
801+ ),
802+ ),
803+ ),
804+ );
805+
806+ // Open the dialog.
807+ await tester.tap (find.byType (ElevatedButton ));
808+ await tester.pumpAndSettle ();
809+ expect (rootObserver.dialogCount, 1 );
810+
811+ // Tap on the barrier, which shouldn't do anything this time.
812+ await tester.tapAt (const Offset (10.0 , 10.0 ));
813+ await tester.pumpAndSettle ();
814+ expect (rootObserver.dialogCount, 1 );
815+ });
816+ });
817+
818+ testWidgets ('Barrier color' , (WidgetTester tester) async {
819+ await tester.pumpWidget (
820+ MaterialApp (
821+ home: Material (
822+ child: Center (
823+ child: Builder (
824+ builder: (BuildContext context) {
825+ return ElevatedButton (
826+ child: const Text ('X' ),
827+ onPressed: () => showAboutDialog (
828+ context: context,
829+ ),
830+ );
831+ },
832+ ),
833+ ),
834+ ),
835+ ),
836+ );
837+
838+ // Open the dialog.
839+ await tester.tap (find.byType (ElevatedButton ));
840+ await tester.pumpAndSettle ();
841+ expect (tester.widget <ModalBarrier >(find.byType (ModalBarrier ).last).color, Colors .black54);
842+
843+ // Dismiss the dialog.
844+ await tester.tapAt (const Offset (10.0 , 10.0 ));
845+
846+ await tester.pumpWidget (
847+ MaterialApp (
848+ home: Material (
849+ child: Center (
850+ child: Builder (
851+ builder: (BuildContext context) {
852+ return ElevatedButton (
853+ child: const Text ('X' ),
854+ onPressed: () => showAboutDialog (
855+ context: context,
856+ barrierColor: Colors .pink,
857+ ),
858+ );
859+ },
860+ ),
861+ ),
862+ ),
863+ ),
864+ );
865+
866+ // Open the dialog.
867+ await tester.tap (find.byType (ElevatedButton ));
868+ await tester.pumpAndSettle ();
869+ expect (tester.widget <ModalBarrier >(find.byType (ModalBarrier ).last).color, Colors .pink);
870+ });
871+
872+ testWidgets ('Barrier Label' , (WidgetTester tester) async {
873+ await tester.pumpWidget (
874+ MaterialApp (
875+ home: Material (
876+ child: Center (
877+ child: Builder (
878+ builder: (BuildContext context) {
879+ return ElevatedButton (
880+ child: const Text ('X' ),
881+ onPressed: () => showAboutDialog (
882+ context: context,
883+ barrierLabel: 'Custom Label' ,
884+ ),
885+ );
886+ },
887+ ),
888+ ),
889+ ),
890+ ),
891+ );
892+
893+ // Open the dialog.
894+ await tester.tap (find.byType (ElevatedButton ));
895+ await tester.pumpAndSettle ();
896+ expect (tester.widget <ModalBarrier >(find.byType (ModalBarrier ).last).semanticsLabel, 'Custom Label' );
897+ });
898+
745899 testWidgetsWithLeakTracking ('showAboutDialog uses root navigator by default' , (WidgetTester tester) async {
746900 final AboutDialogObserver rootObserver = AboutDialogObserver ();
747901 final AboutDialogObserver nestedObserver = AboutDialogObserver ();
@@ -1741,4 +1895,12 @@ class AboutDialogObserver extends NavigatorObserver {
17411895 }
17421896 super .didPush (route, previousRoute);
17431897 }
1898+
1899+ @override
1900+ void didPop (Route <dynamic > route, Route <dynamic >? previousRoute) {
1901+ if (route is DialogRoute ) {
1902+ dialogCount-- ;
1903+ }
1904+ super .didPop (route, previousRoute);
1905+ }
17441906}
0 commit comments