Skip to content

Commit

Permalink
Merge pull request #2 from gokhancvs/master
Browse files Browse the repository at this point in the history
Adding `contentMaxWidth` parameter
  • Loading branch information
SalihCanBinboga committed Nov 3, 2022
2 parents 59e663a + 4e37fca commit 905c092
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0

- feature: Added `contentMaxWidth` prop to `InfoPopupWidget`

## 2.1.3

- doc: Update README.md
Expand Down
9 changes: 8 additions & 1 deletion lib/src/controllers/info_popup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class InfoPopupController {
this.onLayoutMounted,
this.contentOffset = Offset.zero,
this.indicatorOffset = Offset.zero,
this.contentMaxWidth,
}) : _targetRenderBox = targetRenderBox;

/// The [layerLink] is the layer link of the popup.
Expand Down Expand Up @@ -74,6 +75,11 @@ class InfoPopupController {
/// The [infoPopupContainerSize] is the size of the popup.
Size? infoPopupContainerSize;

/// [contentMaxWidth] is the max width of the content that is shown.
/// If the [contentMaxWidth] is null, the max width will be eighty percent
/// of the screen.
final double? contentMaxWidth;

/// The [show] method is used to show the popup.
void show() {
_infoPopupOverlayEntry = OverlayEntry(
Expand All @@ -88,6 +94,8 @@ class InfoPopupController {
contentTheme: contentTheme,
contentOffset: contentOffset,
indicatorOffset: indicatorOffset,
dismissTriggerBehavior: dismissTriggerBehavior,
contentMaxWidth: contentMaxWidth,
onLayoutMounted: (Size size) {
Future<void>.delayed(
const Duration(milliseconds: 30),
Expand All @@ -109,7 +117,6 @@ class InfoPopupController {

dismissInfoPopup();
},
dismissTriggerBehavior: dismissTriggerBehavior,
);
},
);
Expand Down
7 changes: 7 additions & 0 deletions lib/src/info_popup_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class InfoPopupWidget extends StatefulWidget {
this.dismissTriggerBehavior = PopupDismissTriggerBehavior.onTapArea,
this.contentOffset,
this.indicatorOffset,
this.contentMaxWidth,
super.key,
}) : assert(customContent == null || contentTitle == null,
'You can not use both customContent and contentTitle at the same time.');
Expand Down Expand Up @@ -62,6 +63,11 @@ class InfoPopupWidget extends StatefulWidget {
/// The [indicatorOffset] is the offset of the indicator.
final Offset? indicatorOffset;

/// [contentMaxWidth] is the max width of the content that is shown.
/// If the [contentMaxWidth] is null, the max width will be eighty percent
/// of the screen.
final double? contentMaxWidth;

@override
State<InfoPopupWidget> createState() => _InfoPopupWidgetState();
}
Expand Down Expand Up @@ -129,6 +135,7 @@ class _InfoPopupWidgetState extends State<InfoPopupWidget> {
infoPopupDismissed: widget.infoPopupDismissed,
contentOffset: widget.contentOffset ?? const Offset(0, 0),
indicatorOffset: widget.indicatorOffset ?? const Offset(0, 0),
contentMaxWidth: widget.contentMaxWidth,
);

if (!_isControllerInitialized && widget.onControllerCreated != null) {
Expand Down
16 changes: 15 additions & 1 deletion lib/src/overlays/overlay_entry_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OverlayInfoPopup extends StatefulWidget {
required this.indicatorOffset,
required this.contentOffset,
required this.dismissTriggerBehavior,
required this.contentMaxWidth,
super.key,
});

Expand Down Expand Up @@ -55,6 +56,11 @@ class OverlayInfoPopup extends StatefulWidget {
/// [dismissTriggerBehavior] is the behavior of the popup when the popup is pressed.
final PopupDismissTriggerBehavior dismissTriggerBehavior;

/// [contentMaxWidth] is the max width of the content that is shown.
/// If the [contentMaxWidth] is null, the max width will be eighty percent
/// of the screen.
final double? contentMaxWidth;

@override
State<OverlayInfoPopup> createState() => _OverlayInfoPopupState();
}
Expand Down Expand Up @@ -183,6 +189,14 @@ class _OverlayInfoPopupState extends State<OverlayInfoPopup> {
);
}

double get _contentMaxWidth {
if (widget.contentMaxWidth == null) {
return context.screenWidth * .8;
} else {
return widget.contentMaxWidth!;
}
}

double get _contentMaxHeight {
const int padding = 16;
final double screenHeight = context.screenHeight;
Expand Down Expand Up @@ -263,7 +277,7 @@ class _OverlayInfoPopupState extends State<OverlayInfoPopup> {
scale: _isLayoutDone ? 1.0 : 0.0,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: context.screenWidth * .8,
maxWidth: _contentMaxWidth,
maxHeight: _contentMaxHeight,
),
child: Container(
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: info_popup
description: The simple way to show the user some information on your selected widget.
version: 2.1.3
version: 2.2.0
repository: https://github.com/salihcanbinboga/info_popup

environment:
sdk: '>=2.17.3 <3.0.0'
flutter: ">=1.17.0"
flutter: '>=1.17.0'

dependencies:
flutter:
Expand All @@ -16,4 +16,4 @@ dev_dependencies:
path: example
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
sdk: flutter

0 comments on commit 905c092

Please sign in to comment.