Skip to content

Commit

Permalink
Merge pull request #56 from woltapp/issue-55-barrier-dismiss-has-no-e…
Browse files Browse the repository at this point in the history
…ffect
  • Loading branch information
ulusoyca authored Sep 6, 2023
2 parents ff3dc09 + ffc269b commit 213d8bc
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 64 deletions.
16 changes: 12 additions & 4 deletions lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ class _WoltModalSheetState extends State<WoltModalSheet> {
themeData?.enableDrag ??
defaultThemeData.enableDrag);
final showDragHandle = widget.showDragHandle ??
(enableDrag &&
(themeData?.showDragHandle ??
defaultThemeData.showDragHandle));
(enableDrag && (themeData?.showDragHandle ?? defaultThemeData.showDragHandle));
final pageBackgroundColor = page.backgroundColor ??
themeData?.backgroundColor ??
defaultThemeData.backgroundColor;
Expand Down Expand Up @@ -273,7 +271,17 @@ class _WoltModalSheetState extends State<WoltModalSheet> {
id: barrierLayoutId,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onModalDismissedWithBarrierTap ?? Navigator.of(context).pop,
onTap: () {
if (widget.route.barrierDismissible) {
final onModalDismissedWithBarrierTap =
widget.onModalDismissedWithBarrierTap;
if (onModalDismissedWithBarrierTap != null) {
onModalDismissedWithBarrierTap();
} else {
Navigator.of(context).pop();
}
}
},
child: const SizedBox.expand(),
),
),
Expand Down
211 changes: 151 additions & 60 deletions test/wolt_modal_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,25 @@ void main() {
testWidgets('WoltModalSheet.show opens a sheet', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
child: const Text('Open sheet'),
);

}
),
)
),
},
child: const Text('Open sheet'),
);
}),
)),
),
);

Expand All @@ -43,25 +38,21 @@ void main() {
testWidgets('Empty pageListBuilder throws an error', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[];
},
);
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[];
},
child: const Text('Open sheet'),
);
}
),
)
),
},
child: const Text('Open sheet'),
);
}),
)),
),
);

Expand All @@ -72,6 +63,110 @@ void main() {
});
});

group('Modal sheet barrier dismissible', () {
testWidgets('WoltModalSheet does not dismiss on barrier tap if barrierDismissible is false',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
barrierDismissible: false,
onModalDismissedWithDrag: () => Navigator.of(context).pop(),
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
},
child: const Text('Open sheet'),
);
}),
)),
),
);

await tester.tap(find.text('Open sheet'));
await tester.pumpAndSettle();

expect(find.text('Wolt modal sheet page'), findsOneWidget);

await tester.tapAt(const Offset(0, 0));
await tester.pumpAndSettle();
expect(find.text('Wolt modal sheet page'), findsOneWidget);
});

testWidgets('WoltModalSheet dismisses on barrier tap if barrierDismissible is true',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
barrierDismissible: true,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
},
child: const Text('Open sheet'),
);
}),
)),
),
);

await tester.tap(find.text('Open sheet'));
await tester.pumpAndSettle();

expect(find.text('Wolt modal sheet page'), findsOneWidget);

await tester.tapAt(const Offset(0, 0));
await tester.pumpAndSettle();
expect(find.text('Wolt modal sheet page'), findsNothing);
});
});

testWidgets('Empty pageListBuilder throws an error', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[];
},
);
},
child: const Text('Open sheet'),
);
}),
)),
),
);

await tester.tap(find.text('Open sheet'));
await tester.pumpAndSettle();

expect(tester.takeException(), isNotNull);
});

testWidgets('WoltModalSheet.modalTypeBuilder defaults', (tester) async {
const Size wideSize = Size(800.0, 600.0);
const Size narrowSize = Size(300.0, 600.0);
Expand All @@ -82,29 +177,25 @@ void main() {

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
child: const Text('Open sheet'),
);
}
),
)
),
},
child: const Text('Open sheet'),
);
}),
)),
),
);

Expand Down

0 comments on commit 213d8bc

Please sign in to comment.