diff --git a/CHANGELOG.md b/CHANGELOG.md index 1710ef7..2aed6e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - Yellow underline (because of missing `Material` widget) +## Docs + +- Added documentation on the Snacky custom widget implementation + # 0.2.4 ## CI diff --git a/README.md b/README.md index c0ace1d..7294f10 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,20 @@ final snacky = Snacky( SnackyController.instance.showMessage((context) => snacky); ``` +## Show a snacky with a custom widget + +```dart +final snacky = Snacky.widget( + builder: (context, cancelableSnacky) => YourCustomSnackyWidget(), + showDuration: Duration(seconds: 3), // How long the snacky should be shown + transitionDuration: Duration(milliseconds: 300), // How long the transition should take + transitionCurve: Curves.easeInOut, // The curve of the transition + location: SnackyLocation + .top, // Where the snacky should be shown (SnackyLocation.top or SnackyLocation.bottom) +); +SnackyController.instance.showMessage((context) => snacky); +``` + ## Cancel the active snacky ```dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 58416aa..8abbde7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,4 @@ -import 'package:flutter/material.dart'; -import 'package:snacky/snacky.dart'; +import 'package:impaktfull_ui/impaktfull_ui.dart'; const colorAccent = Color(0xFF7D64F2); const colorPrimary = Color(0xFF1A1A1A); @@ -45,8 +44,8 @@ class HomeScreen extends StatelessWidget { height: 50, ), const SizedBox(height: 16), - ExampleButton( - title: 'show success at the top of the screen', + ImpaktfullButton.accent( + label: 'show success at the top of the screen', onTap: () { const snacky = Snacky( title: 'Top', @@ -55,8 +54,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show error at the top of the screen', + ImpaktfullButton.accent( + label: 'show error at the top of the screen', onTap: () { const snacky = Snacky( title: 'Top', @@ -65,8 +64,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show warning at the top of the screen', + ImpaktfullButton.accent( + label: 'show warning at the top of the screen', onTap: () { const snacky = Snacky( title: 'Top', @@ -75,8 +74,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show info at the top of the screen', + ImpaktfullButton.accent( + label: 'show info at the top of the screen', onTap: () { const snacky = Snacky( title: 'Top', @@ -86,8 +85,8 @@ class HomeScreen extends StatelessWidget { }, ), const SizedBox(height: 32), - ExampleButton( - title: 'show success at the bottom of the screen', + ImpaktfullButton.accent( + label: 'show success at the bottom of the screen', onTap: () { const snacky = Snacky( title: 'Bottom', @@ -97,8 +96,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show success that can be canceled', + ImpaktfullButton.accent( + label: 'show success that can be canceled', onTap: () { const snacky = Snacky( title: 'Top (cancelable)', @@ -108,8 +107,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show success that can be canceled by tap', + ImpaktfullButton.accent( + label: 'show success that can be canceled by tap', onTap: () { final snacky = Snacky( title: 'Top (tap to cancel)', @@ -119,8 +118,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show successs that will stay open untill closed', + ImpaktfullButton.accent( + label: 'show successs that will stay open untill closed', onTap: () { const snacky = Snacky( title: 'Top (open untill closed/cancelled)', @@ -131,8 +130,8 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton( - title: 'show custom widget', + ImpaktfullButton.accent( + label: 'show custom widget', onTap: () { final snacky = Snacky.widget( builder: (context, cancelabelSnacky) => Container( @@ -145,12 +144,12 @@ class HomeScreen extends StatelessWidget { SnackyController.instance.showMessage((context) => snacky); }, ), - ExampleButton.primary( - title: 'cancel all snackies', + ImpaktfullButton.primary( + label: 'cancel all snackies', onTap: () => SnackyController.instance.cancelAll(), ), - ExampleButton.primary( - title: 'cancel active snacky', + ImpaktfullButton.primary( + label: 'cancel active snacky', onTap: () => SnackyController.instance.cancelActiveSnacky(), ), ], @@ -158,60 +157,3 @@ class HomeScreen extends StatelessWidget { ); } } - -class ExampleButton extends StatelessWidget { - final String title; - final VoidCallback onTap; - final Color color; - - const ExampleButton({ - required this.title, - required this.onTap, - super.key, - }) : color = colorAccent; - - const ExampleButton.primary({ - required this.title, - required this.onTap, - super.key, - }) : color = colorPrimary; - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: ClipRRect( - borderRadius: BorderRadius.circular(4), - child: Stack( - children: [ - Container( - width: double.infinity, - color: color, - padding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 12, - ), - child: Text( - title, - style: const TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - ), - textAlign: TextAlign.center, - ), - ), - Positioned.fill( - child: Material( - color: Colors.transparent, - child: InkWell( - onTap: onTap, - child: const ColoredBox(color: Colors.transparent), - ), - ), - ), - ], - ), - ), - ); - } -} diff --git a/example/pubspec.lock b/example/pubspec.lock index a5da30d..18ff3c5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,6 +1,22 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d + url: "https://pub.dev" + source: hosted + version: "3.6.1" + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" async: dependency: transitive description: @@ -41,14 +57,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" - cupertino_icons: - dependency: "direct main" + crypto: + dependency: transitive description: - name: cupertino_icons - sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + name: crypto + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "1.0.6" + version: "3.0.5" fake_async: dependency: transitive description: @@ -70,11 +86,51 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_svg: + dependency: transitive + description: + name: flutter_svg + sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2" + url: "https://pub.dev" + source: hosted + version: "2.0.10+1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + url: "https://pub.dev" + source: hosted + version: "1.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + impaktfull_ui: + dependency: "direct main" + description: + name: impaktfull_ui + sha256: dd8cb54616aea021b7565def2d6337a78cdb77d473b9042ab36660cef993c4e1 + url: "https://pub.dev" + source: hosted + version: "0.10.0" + intl: + dependency: transitive + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" leak_tracker: dependency: transitive description: @@ -107,6 +163,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + lottie: + dependency: transitive + description: + name: lottie + sha256: "6a24ade5d3d918c306bb1c21a6b9a04aab0489d51a2582522eea820b4093b62b" + url: "https://pub.dev" + source: hosted + version: "3.1.2" matcher: dependency: transitive description: @@ -139,6 +203,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.0" + path_parsing: + dependency: transitive + description: + name: path_parsing + sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf + url: "https://pub.dev" + source: hosted + version: "1.0.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" sky_engine: dependency: transitive description: flutter @@ -150,7 +230,7 @@ packages: path: ".." relative: true source: path - version: "0.2.1" + version: "0.2.4" source_span: dependency: transitive description: @@ -199,6 +279,46 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + universal_io: + dependency: transitive + description: + name: universal_io + sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad" + url: "https://pub.dev" + source: hosted + version: "2.2.2" + vector_graphics: + dependency: transitive + description: + name: vector_graphics + sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3" + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" + vector_graphics_codec: + dependency: transitive + description: + name: vector_graphics_codec + sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" + vector_graphics_compiler: + dependency: transitive + description: + name: vector_graphics_compiler + sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81" + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" vector_math: dependency: transitive description: @@ -215,6 +335,22 @@ packages: url: "https://pub.dev" source: hosted version: "14.2.5" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb + url: "https://pub.dev" + source: hosted + version: "1.1.0" + xml: + dependency: transitive + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.4.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f932abc..2eb2794 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,24 +1,28 @@ name: snacky_example description: "A new Flutter project." -publish_to: 'none' +publish_to: "none" version: 1.0.0+1 environment: - sdk: '>=3.2.0 <4.0.0' + sdk: ">=3.2.0 <4.0.0" dependencies: flutter: sdk: flutter - cupertino_icons: ^1.0.2 - snacky: + snacky: path: ../ + impaktfull_ui: ^0.10.0 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.0 +dependency_overrides: + snacky: + path: ../ + flutter: uses-material-design: true assets: - - ../assets/logo.png \ No newline at end of file + - ../assets/logo.png diff --git a/lib/src/builder/simple_snacky_builder.dart b/lib/src/builder/simple_snacky_builder.dart index dae23a2..2f883ff 100644 --- a/lib/src/builder/simple_snacky_builder.dart +++ b/lib/src/builder/simple_snacky_builder.dart @@ -102,7 +102,8 @@ class SimpleSnackyBuilder extends SnackyBuilder { ), ], if (snacky.bottomWidgetBuilder != null) ...[ - snacky.bottomWidgetBuilder!(context, cancelableSnacky), + snacky.bottomWidgetBuilder!( + context, cancelableSnacky), ], ], ), @@ -122,7 +123,8 @@ class SimpleSnackyBuilder extends SnackyBuilder { padding: const EdgeInsets.all(8), child: Icon( Icons.close, - color: _getTextStyle(snacky, SimpleSnackyTextType.title).color, + color: _getTextStyle(snacky, SimpleSnackyTextType.title) + .color, ), ), ), @@ -131,7 +133,8 @@ class SimpleSnackyBuilder extends SnackyBuilder { const SizedBox(width: 8), Icon( Icons.keyboard_arrow_right, - color: _getTextStyle(snacky, SimpleSnackyTextType.title).color, + color: + _getTextStyle(snacky, SimpleSnackyTextType.title).color, ), const SizedBox(width: 16), ] else ...[ @@ -183,7 +186,8 @@ class SimpleSnackyBuilder extends SnackyBuilder { } switch (textType) { case SimpleSnackyTextType.title: - return const TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold); + return const TextStyle( + color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold); case SimpleSnackyTextType.subtitle: return const TextStyle(color: Colors.black, fontSize: 12); } diff --git a/lib/src/transition/snacky_slide_transition.dart b/lib/src/transition/snacky_slide_transition.dart index 1c5ac1b..de03368 100644 --- a/lib/src/transition/snacky_slide_transition.dart +++ b/lib/src/transition/snacky_slide_transition.dart @@ -49,9 +49,11 @@ class _SnackySlideTransitionState extends State }); // Animation - final beginX = snacky.location == SnackyLocation.topStart || snacky.location == SnackyLocation.bottomStart + final beginX = snacky.location == SnackyLocation.topStart || + snacky.location == SnackyLocation.bottomStart ? -1 - : snacky.location == SnackyLocation.topEnd || snacky.location == SnackyLocation.bottomEnd + : snacky.location == SnackyLocation.topEnd || + snacky.location == SnackyLocation.bottomEnd ? 1 : 0; final beginY = snacky.location == SnackyLocation.top diff --git a/lib/src/widget/snacky_configurator_widget.dart b/lib/src/widget/snacky_configurator_widget.dart index 4b9c282..d9b21c4 100644 --- a/lib/src/widget/snacky_configurator_widget.dart +++ b/lib/src/widget/snacky_configurator_widget.dart @@ -20,11 +20,14 @@ class SnackyConfiguratorWidget extends StatefulWidget { }); @override - State createState() => _SnackyConfiguratorWidgetState(); + State createState() => + _SnackyConfiguratorWidgetState(); } -class _SnackyConfiguratorWidgetState extends State implements SnackyListener { - SnackyController get snackyController => widget.snackyController ?? SnackyController.instance; +class _SnackyConfiguratorWidgetState extends State + implements SnackyListener { + SnackyController get snackyController => + widget.snackyController ?? SnackyController.instance; @override void initState() { @@ -72,7 +75,8 @@ class _SnackyConfiguratorWidgetState extends State imp context.visitChildElements(visitor); - assert(navigator != null, '''It looks like you are not using Navigator in your app. + assert(navigator != null, + '''It looks like you are not using Navigator in your app. Do you wrapped you app widget like this? SnackyConfiguratorWidget( app: MaterialApp( diff --git a/lib/src/widget/snacky_swipe_detector.dart b/lib/src/widget/snacky_swipe_detector.dart index 3a2eb03..1e06b51 100644 --- a/lib/src/widget/snacky_swipe_detector.dart +++ b/lib/src/widget/snacky_swipe_detector.dart @@ -41,7 +41,8 @@ class _SnackySwipeDetectorState extends State { // Bottom notification widget.onSwipe(); } - if (widget.alignment == AlignmentDirectional.topCenter && details.globalPosition.dy < _dragPositionY) { + if (widget.alignment == AlignmentDirectional.topCenter && + details.globalPosition.dy < _dragPositionY) { widget.onSwipe(); } else if (widget.alignment == AlignmentDirectional.bottomCenter && details.globalPosition.dy > _dragPositionY) { @@ -58,7 +59,8 @@ class _SnackySwipeDetectorState extends State { widget.onSwipe(); } else if (start == 0) { // Center notification (do nothing) - } else if (start > 0 && details.globalPosition.dx > _dragPositionStart) { + } else if (start > 0 && + details.globalPosition.dx > _dragPositionStart) { // End notification widget.onSwipe(); }