From 210b21579cc2ba70459fefa3601f481ef6d2843d Mon Sep 17 00:00:00 2001 From: Mrr Hak Date: Thu, 23 Oct 2025 11:16:48 +0700 Subject: [PATCH] chore(popup_content): allow custom content margin --- CHANGELOG.md | 10 ++++++-- example/lib/main.dart | 2 +- example/pubspec.lock | 44 ++++++++++++++++---------------- lib/src/popup.dart | 59 ++++++++++++++++++++++++++++--------------- lib/src/screen.dart | 2 +- pubspec.yaml | 4 +-- 6 files changed, 73 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad6f3c..64b5fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ -## 1.0.0 +## 3.3.10 + +- Allow custom content margin -* TODO: Describe initial release. ## 3.3.8 * TODO: Describe initial release. + +## 1.0.0 + +* TODO: Describe initial release. + diff --git a/example/lib/main.dart b/example/lib/main.dart index 828945c..a37a466 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -53,7 +53,7 @@ class _MyHomePageState extends State { children: [ // example1 text CustomPopup( - barrierColor: Colors.green.withOpacity(0.1), + barrierColor: Colors.green.withValues(alpha: 0.1), backgroundColor: Colors.white, content: Text('George says everything looks fine'), child: Icon(Icons.help, color: Colors.grey), diff --git a/example/pubspec.lock b/example/pubspec.lock index ebb9886..dcc56ec 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: async - sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" url: "https://pub.dev" source: hosted - version: "2.12.0" + version: "2.13.0" boolean_selector: dependency: transitive description: @@ -45,10 +45,10 @@ packages: dependency: transitive description: name: fake_async - sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.3.3" file: dependency: transitive description: @@ -73,7 +73,7 @@ packages: path: ".." relative: true source: path - version: "3.3.8" + version: "3.3.9" flutter_test: dependency: "direct dev" description: flutter @@ -93,26 +93,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" url: "https://pub.dev" source: hosted - version: "10.0.8" + version: "11.0.2" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573 + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" url: "https://pub.dev" source: hosted - version: "3.0.9" + version: "3.0.10" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" matcher: dependency: transitive description: @@ -157,10 +157,10 @@ packages: dependency: transitive description: name: process - sha256: "107d8be718f120bbba9dcd1e95e3bd325b1b4a4f07db64154635ba03f2567a0d" + sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744 url: "https://pub.dev" source: hosted - version: "5.0.3" + version: "5.0.5" sky_engine: dependency: transitive description: flutter @@ -218,34 +218,34 @@ packages: dependency: transitive description: name: test_api - sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.4" + version: "0.7.6" vector_math: dependency: transitive description: name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.2.0" vm_service: dependency: transitive description: name: vm_service - sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14" + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" url: "https://pub.dev" source: hosted - version: "14.3.1" + version: "15.0.2" webdriver: dependency: transitive description: name: webdriver - sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8" + sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade" url: "https://pub.dev" source: hosted - version: "3.0.4" + version: "3.1.0" sdks: - dart: ">=3.7.0-0 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/src/popup.dart b/lib/src/popup.dart index 63285dd..4eab879 100644 --- a/lib/src/popup.dart +++ b/lib/src/popup.dart @@ -1,4 +1,4 @@ -part of flutter_popup; +part of '../flutter_popup.dart'; enum _ArrowDirection { top, bottom } @@ -14,6 +14,7 @@ class CustomPopup extends StatefulWidget { final Color? barrierColor; final bool showArrow; final EdgeInsets contentPadding; + final EdgeInsets contentMargin; final double? contentRadius; final BoxDecoration? contentDecoration; final VoidCallback? onBeforePopup; @@ -34,6 +35,7 @@ class CustomPopup extends StatefulWidget { this.showArrow = true, this.barrierColor, this.contentPadding = const EdgeInsets.all(8), + this.contentMargin = const EdgeInsets.symmetric(vertical: 10), this.contentRadius, this.contentDecoration, this.onBeforePopup, @@ -66,6 +68,7 @@ class CustomPopupState extends State { showArrow: widget.showArrow, barriersColor: widget.barrierColor, contentPadding: widget.contentPadding, + contentMargin: widget.contentMargin, contentRadius: widget.contentRadius, contentDecoration: widget.contentDecoration, position: widget.position, @@ -98,11 +101,11 @@ class _PopupContent extends StatelessWidget { final Color? arrowColor; final bool showArrow; final EdgeInsets contentPadding; + final EdgeInsets contentMargin; final double? contentRadius; final BoxDecoration? contentDecoration; const _PopupContent({ - Key? key, required this.child, required this.childKey, required this.arrowKey, @@ -113,8 +116,9 @@ class _PopupContent extends StatelessWidget { this.arrowColor, this.contentRadius, required this.contentPadding, + required this.contentMargin, this.contentDecoration, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -123,7 +127,7 @@ class _PopupContent extends StatelessWidget { Container( key: childKey, padding: contentPadding, - margin: const EdgeInsets.symmetric(vertical: 10).copyWith( + margin: contentMargin.copyWith( top: arrowDirection == _ArrowDirection.bottom ? 0 : null, bottom: arrowDirection == _ArrowDirection.top ? 0 : null, ), @@ -134,7 +138,7 @@ class _PopupContent extends StatelessWidget { borderRadius: BorderRadius.circular(contentRadius ?? 10), boxShadow: [ BoxShadow( - color: Colors.black.withOpacity(0.1), + color: Colors.black.withValues(alpha: 0.1), blurRadius: 10, ), ], @@ -172,14 +176,32 @@ class _TrianglePainter extends CustomPainter { paint.color = color; path.lineTo(size.width * 0.66, size.height * 0.86); - path.cubicTo(size.width * 0.58, size.height * 1.05, size.width * 0.42, - size.height * 1.05, size.width * 0.34, size.height * 0.86); + path.cubicTo( + size.width * 0.58, + size.height * 1.05, + size.width * 0.42, + size.height * 1.05, + size.width * 0.34, + size.height * 0.86, + ); path.cubicTo(size.width * 0.34, size.height * 0.86, 0, 0, 0, 0); path.cubicTo(0, 0, size.width, 0, size.width, 0); - path.cubicTo(size.width, 0, size.width * 0.66, size.height * 0.86, - size.width * 0.66, size.height * 0.86); - path.cubicTo(size.width * 0.66, size.height * 0.86, size.width * 0.66, - size.height * 0.86, size.width * 0.66, size.height * 0.86); + path.cubicTo( + size.width, + 0, + size.width * 0.66, + size.height * 0.86, + size.width * 0.66, + size.height * 0.86, + ); + path.cubicTo( + size.width * 0.66, + size.height * 0.86, + size.width * 0.66, + size.height * 0.86, + size.width * 0.66, + size.height * 0.86, + ); canvas.drawPath(path, paint); } @@ -211,6 +233,7 @@ class _PopupRoute extends PopupRoute { final bool showArrow; final Color? barriersColor; final EdgeInsets contentPadding; + final EdgeInsets contentMargin; final double? contentRadius; final BoxDecoration? contentDecoration; @@ -225,9 +248,6 @@ class _PopupRoute extends PopupRoute { double? _right; _PopupRoute({ - RouteSettings? settings, - ImageFilter? filter, - TraversalEdgeBehavior? traversalEdgeBehavior, required this.child, required this.targetRect, this.backgroundColor, @@ -235,19 +255,17 @@ class _PopupRoute extends PopupRoute { required this.showArrow, this.barriersColor, required this.contentPadding, + required this.contentMargin, this.contentRadius, this.contentDecoration, this.position = PopupPosition.auto, required this.animationDuration, this.animationCurve = Curves.easeInOut, - }) : super( - settings: settings, - filter: filter, - traversalEdgeBehavior: traversalEdgeBehavior, - ); + }); @override - Color? get barrierColor => barriersColor ?? Colors.black.withOpacity(0.1); + Color? get barrierColor => + barriersColor ?? Colors.black.withValues(alpha: 0.1); @override bool get barrierDismissible => true; @@ -360,6 +378,7 @@ class _PopupRoute extends PopupRoute { arrowColor: arrowColor, showArrow: showArrow, contentPadding: contentPadding, + contentMargin: contentMargin, contentRadius: contentRadius, contentDecoration: contentDecoration, child: child, diff --git a/lib/src/screen.dart b/lib/src/screen.dart index 6b1d77c..f97bf1c 100644 --- a/lib/src/screen.dart +++ b/lib/src/screen.dart @@ -1,4 +1,4 @@ -part of flutter_popup; +part of '../flutter_popup.dart'; abstract class Screen { static MediaQueryData get mediaQuery => MediaQueryData.fromView( diff --git a/pubspec.yaml b/pubspec.yaml index 6084218..e728bd4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_popup description: The flutter_popup package is a versatile tool for creating customizable popups in Flutter apps. Its highlight feature effectively guides user attention to specific areas -version: 3.3.9 +version: 3.3.10 homepage: https://github.com/herowws/flutter_popup environment: @@ -13,7 +13,7 @@ dependencies: dev_dependencies: example: path: example - flutter_lints: ^1.0.0 + flutter_lints: ^6.0.0 flutter_test: sdk: flutter