Skip to content

Commit

Permalink
PortalNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi Rousselet committed Feb 23, 2020
1 parent 01fc9d3 commit 464ff6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
30 changes: 22 additions & 8 deletions lib/src/portal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,45 @@ class PortalEntry<T extends Portal> extends SingleChildRenderObjectWidget {
portal = visible ? portal : null,
super(key: key, child: child);

final Widget portal;
final Alignment childAnchor;
final Alignment portalAnchor;
final Alignment childAnchor;
final Widget portal;

@override
RenderObject createRenderObject(BuildContext context) {
return RenderPortalEntry(
context
.dependOnInheritedWidgetOfExactType<_PortalLinkScope>()
.overlayLink,
_getOverlayLink(context),
);
}

_OverlayLink _getOverlayLink(BuildContext context) {
final scope =
context.dependOnInheritedWidgetOfExactType<_PortalLinkScope>();
if (scope == null) {
throw PortalNotFoundError._(this);
}
return scope.overlayLink;
}

@override
void updateRenderObject(
BuildContext context,
RenderPortalEntry renderObject,
) {
renderObject.overlayLink = context
.dependOnInheritedWidgetOfExactType<_PortalLinkScope>()
.overlayLink;
renderObject.overlayLink = _getOverlayLink(context);
}

@override
SingleChildRenderObjectElement createElement() => PortalEntryElement(this);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<Alignment>('portalAnchor', portalAnchor));
properties.add(DiagnosticsProperty<Alignment>('childAnchor', childAnchor));
properties.add(DiagnosticsProperty<Widget>('portal', portal));
properties.add(DiagnosticsProperty<Widget>('child', child));
}
}

class RenderPortalEntry extends RenderProxyBox {
Expand Down
19 changes: 3 additions & 16 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,7 @@ void main() {
expect(find.text('child'), findsNothing);
expect(find.text('portal'), findsNothing);
expect(find.text('newChild'), findsOneWidget);
}, skip: true);
testWidgets("doesn't throw if no Portal in ancestors but visible is false",
(tester) async {
await tester.pumpWidget(
PortalEntry(
visible: false,
portal: const Text('portal', textDirection: TextDirection.ltr),
child: const Text('child', textDirection: TextDirection.ltr),
),
);

expect(find.text('child'), findsOneWidget);
expect(find.text('portal'), findsNothing);
}, skip: true);
});
testWidgets('throws if no PortalEntry were found', (tester) async {
await tester.pumpWidget(
PortalEntry(
Expand All @@ -207,9 +194,9 @@ void main() {
final dynamic exception = tester.takeException();
expect(exception, isA<PortalNotFoundError>());
expect(exception.toString(), equals('''
Error: Could not find a Portal above this PortalEntry<Portal>(visible, portalAnchor: null, childAnchor: null, portal: Text, child: Text).
Error: Could not find a Portal above this PortalEntry<Portal>(portalAnchor: null, childAnchor: null, portal: Text, child: Text).
'''));
}, skip: true);
});
testWidgets('visible defaults to true', (tester) async {
await tester.pumpWidget(
Boilerplate(
Expand Down

0 comments on commit 464ff6d

Please sign in to comment.