Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding contentMaxWidth parameter #2

Merged
merged 4 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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