From 9f9e7a5d512ce0c294a1e913283a2b3f8c69b392 Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Tue, 31 Mar 2020 22:13:13 -0300 Subject: [PATCH] Add documentation --- lib/ripple_effect.dart | 35 +++++++++++++++++++++++++++++++++ lib/src/ripple_effect.dart | 40 ++++++++++++++++++++++++++++++++++++++ lib/src/transition.dart | 10 ++++++++++ 3 files changed, 85 insertions(+) diff --git a/lib/ripple_effect.dart b/lib/ripple_effect.dart index cfce67f..00a204a 100644 --- a/lib/ripple_effect.dart +++ b/lib/ripple_effect.dart @@ -1,3 +1,38 @@ +/// This library allows apply a ripple effect to the app screen. +/// +/// It requires to wrap the page or the area where the ripple effect +/// will happen with the [RipplePage] widget, then wrap the start point of +/// the effect with the [RippleEffect] widget, finally, to start the animation, +/// use [RippleEffect.start]. +/// +/// ```dart +/// class Stateless extends StatelessWidget { +/// final pageKey = RipplePage.createGlobalKey(); +/// final effectKey = RippleEffect.createGlobalKey(); +/// +/// @override +/// Widget build(BuildContext context) { +/// return RipplePage( +/// child: Scaffold( +/// body: Center(), +/// floatingActionButton: RippleEffect( +/// pageKey: pageKey, +/// effectKey: effectKey, +/// color: Colors.blue, +/// child: FloatingActionButton( +/// backgroundColor: Colors.blue, +/// onPressed: () => +/// RippleEffect.start(effectKey, () => toNextPage(context)), +/// child: Icon(Icons.arrow_back), +/// ), +/// ) +/// ), +/// ); +/// } +/// } +/// +/// ``` + library ripple_effect; export 'src/ripple_effect.dart' show RipplePage, RippleEffect; diff --git a/lib/src/ripple_effect.dart b/lib/src/ripple_effect.dart index 9f606fd..dc9fb9c 100644 --- a/lib/src/ripple_effect.dart +++ b/lib/src/ripple_effect.dart @@ -3,6 +3,28 @@ import 'package:rect_getter/rect_getter.dart'; import 'ripple_data.dart'; +/// Wrap your screen with this widget. +/// +/// The ripple effect will growth until reaches this widget. +/// It requires a [GlobalKey] that can be generated +/// via [RipplePage.createGlobalKey()]. +/// +/// This should be used with the [RippleEffect] widget to work. +/// +/// ```dart +/// class Stateless extends StatelessWidget { +/// +/// final pageKey = RipplePage.createGlobalKey(); +/// +/// @override +/// Widget build(BuildContext context) { +/// return RipplePage( +/// child: Scaffold(body: MyPage()), +/// pageKey: pageKey, +/// ); +/// } +/// } +/// ``` class RipplePage extends StatefulWidget { RipplePage({ @required GlobalKey<_RipplePageState> pageKey, @@ -50,6 +72,23 @@ class _RipplePageState extends State { } } +/// Responsible to wrap the origin point of the ripple effect. +/// +/// Often this should wrap a button widget or the animation +/// start widget. +/// It requires to call [RippleEffect.start] to start the animation. +/// +/// ```dart +/// RippleEffect( +/// pageKey: pageKey, +/// effectKey: effectKey, +/// color: Colors.blue, +/// child: FloatingActionButton( +/// child: Icon(Icons.arrow_back), +/// onPressed: () => RippleEffect.start(effectKey, toNextPage), +/// ), +/// ) +/// ``` class RippleEffect extends StatefulWidget { RippleEffect({ @required this.pageKey, @@ -77,6 +116,7 @@ class RippleEffect extends StatefulWidget { static GlobalKey<_RippleEffectState> createGlobalKey() => new GlobalKey<_RippleEffectState>(); + /// Start the animation and call [callback] after the animation. static Future start( GlobalKey<_RippleEffectState> rippleEffectKey, VoidCallback callback, diff --git a/lib/src/transition.dart b/lib/src/transition.dart index 7b67770..18e56ee 100644 --- a/lib/src/transition.dart +++ b/lib/src/transition.dart @@ -1,5 +1,15 @@ import 'package:flutter/widgets.dart'; +/// A common used fade transition to use with [RippleEffect] on navigation. +/// +/// ```dart +/// Future toNextPage(BuildContext context) => +/// Navigator.of(context).push( +/// FadeRouteBuilder( +/// page: MyNextPage(), +/// ), +/// ); +/// ``` class FadeRouteBuilder extends PageRouteBuilder { final Widget page;