diff --git a/.gitignore b/.gitignore index 75e9658..d691bdd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .pub/ packages pubspec.lock +/.vs +/.dart_tool diff --git a/lib/src/fab_dialer.dart b/lib/src/fab_dialer.dart index f0070ee..03f50cc 100644 --- a/lib/src/fab_dialer.dart +++ b/lib/src/fab_dialer.dart @@ -2,7 +2,7 @@ part of fab_dialer; class FabDialer extends StatefulWidget { const FabDialer(this._fabMiniMenuItemList, this._fabColor, this._fabIcon, - [this._closeFabIcon, this._animationDuration, this.closeOnTap]); + [this._closeFabIcon = const Icon(Icons.close), this._animationDuration = 180, this.closeOnTap = false]); final List _fabMiniMenuItemList; final Color _fabColor; @@ -14,34 +14,26 @@ class FabDialer extends StatefulWidget { @override FabDialerState createState() => - FabDialerState( - _fabMiniMenuItemList, _fabColor, _fabIcon, _closeFabIcon, - _animationDuration, closeOnTap); + FabDialerState( + _fabMiniMenuItemList, + _animationDuration, closeOnTap); } class FabDialerState extends State with TickerProviderStateMixin { - FabDialerState(this._fabMiniMenuItemList, this._fabColor, this._fabIcon, - this._closeFabIcon, this._animationDuration, this.closeOnTap); + FabDialerState(this._fabMiniMenuItemList, this._animationDuration, this.closeOnTap); bool _isRotated = false; final List _fabMiniMenuItemList; - final Color _fabColor; - final Icon _fabIcon; - final Icon _closeFabIcon; final int _animationDuration; final bool closeOnTap; - List _fabMenuItems; - - AnimationController _controller; + late List _fabMenuItems; + late AnimationController _controller; @override void initState() { - final int animationDuration = _animationDuration == null - ? 180 - : _animationDuration; _controller = AnimationController( vsync: this, - duration: Duration(milliseconds: animationDuration), + duration: Duration(milliseconds: _animationDuration), ); _controller.reverse(); @@ -51,21 +43,21 @@ class FabDialerState extends State with TickerProviderStateMixin { } void setFabMenu(List fabMenuList) { - List fabMenuItems = List(); + var fabMenuItems = []; for (int i = 0; i < _fabMiniMenuItemList.length; i++) { fabMenuItems.add(FabMenuMiniItemWidget( - tooltip: _fabMiniMenuItemList[i].tooltip, - text: _fabMiniMenuItemList[i].text, - elevation: _fabMiniMenuItemList[i].elevation, - icon: _fabMiniMenuItemList[i].icon, - index: i, - onPressed: _fabMiniMenuItemList[i].onPressed, - textColor: _fabMiniMenuItemList[i].textColor, - fabColor: _fabMiniMenuItemList[i].fabColor, - chipColor: _fabMiniMenuItemList[i].chipColor, - controller: _controller, - closeOnPress: closeOnTap, - close: _rotate + tooltip: _fabMiniMenuItemList[i].tooltip, + text: _fabMiniMenuItemList[i].text, + elevation: _fabMiniMenuItemList[i].elevation, + icon: widget._fabMiniMenuItemList[i].icon, + index: i, + onPressed: _fabMiniMenuItemList[i].onPressed, + textColor: _fabMiniMenuItemList[i].textColor, + fabColor: widget._fabMiniMenuItemList[i].fabColor, + chipColor: _fabMiniMenuItemList[i].chipColor, + controller: _controller, + closeOnPress: closeOnTap, + close: _rotate )); } @@ -84,39 +76,39 @@ class FabDialerState extends State with TickerProviderStateMixin { @override Widget build(BuildContext context) { - final Icon closeIcon = _closeFabIcon == null - ? Icon(Icons.close) - : _closeFabIcon; + setFabMenu(this._fabMiniMenuItemList); + return Container( - child: Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.end, - children: _fabMenuItems, - ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - AnimatedBuilder( - animation: _controller, - builder: (BuildContext _, Widget child) { - return FloatingActionButton( - child: Transform( - transform: Matrix4.rotationZ( - (2 * Math.pi) * _controller.value), - alignment: Alignment.center, - child: _controller.value >= 0.5 - ? closeIcon - : _fabIcon, - ), - backgroundColor: _fabColor, - onPressed: _rotate); - }, - ) - ], - ), - ], - )); + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: _fabMenuItems, + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + AnimatedBuilder( + animation: _controller, + builder: (BuildContext _, Widget? child) { + return FloatingActionButton( + child: Transform( + transform: Matrix4.rotationZ( + (2 * Math.pi) * _controller.value), + alignment: Alignment.center, + child: _controller.value >= 0.5 + ? widget._closeFabIcon + : widget._fabIcon, + ), + backgroundColor: widget._fabColor, + onPressed: _rotate); + }, + ) + ], + ), + ], + )); } -} +} \ No newline at end of file diff --git a/lib/src/fab_menu_item.dart b/lib/src/fab_menu_item.dart index 576c823..00a8bad 100644 --- a/lib/src/fab_menu_item.dart +++ b/lib/src/fab_menu_item.dart @@ -4,14 +4,15 @@ typedef void OnFabMiniMenuItemPressed(); class FabMiniMenuItem { double elevation; - String text; Icon icon; Color fabColor; - Color chipColor; String tooltip; - Color textColor; OnFabMiniMenuItemPressed onPressed; - + String? text; + Icon? dynamicIcon; + Color? chipColor; + Color? textColor; + FabMiniMenuItem.withText(this.icon, this.fabColor, this.elevation, @@ -22,90 +23,97 @@ class FabMiniMenuItem { this.textColor); FabMiniMenuItem.noText(this.icon, this.fabColor, this.elevation, - this.tooltip, this.onPressed){ + this.tooltip, this.onPressed) { this.text = null; this.chipColor = null; this.textColor = null; } } -class FabMenuMiniItemWidget extends StatelessWidget { - const FabMenuMiniItemWidget({Key key, +class FabMenuMiniItemWidget extends StatefulWidget { + FabMenuMiniItemWidget({Key? key, this.elevation, - this.text, + required this.text, this.icon, this.fabColor, this.chipColor, this.textColor, this.tooltip, - this.index, - this.controller, - this.onPressed, - this.closeOnPress, - this.close}) + required this.index, + required this.controller, + required this.onPressed, + required this.closeOnPress, + required this.close + }) : super(key: key); - final double elevation; - final String text; - final Icon icon; - final Color fabColor; - final Color chipColor; - final String tooltip; - final Color textColor; + + final double? elevation; + final String? text; + final Icon? icon; + final Color? fabColor; + final Color? chipColor; + final String? tooltip; + final Color? textColor; final int index; final OnFabMiniMenuItemPressed onPressed; final AnimationController controller; final bool closeOnPress; final Function close; + @override + _FabMenuMiniItemWidgetState createState() => _FabMenuMiniItemWidgetState(); +} + +class _FabMenuMiniItemWidgetState extends State { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.symmetric(vertical: 5.0, horizontal: 8.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Container( - margin: EdgeInsets.symmetric(horizontal: 8.0), - child: ScaleTransition( + margin: EdgeInsets.symmetric(vertical: 5.0, horizontal: 0.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + margin: EdgeInsets.symmetric(horizontal: 0.0), + child: ScaleTransition( + scale: CurvedAnimation( + parent: widget.controller, + curve: Interval(((widget.index + 1) / 100), 1.0, + curve: Curves.linear), + ), + child: widget.chipColor != null && widget.text != null + ? Chip( + label: Text( + widget.text ?? '', + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: widget.textColor, + fontWeight: FontWeight.bold), + ), + backgroundColor: widget.chipColor, ) + : null)), + ScaleTransition( scale: CurvedAnimation( - parent: controller, - curve: Interval(((index + 1) / 10), 1.0, - curve: Curves.linear), + parent: widget.controller, + curve: + Interval( + ((widget.index + 1) / 100), 1.0, curve: Curves.linear), ), - child: chipColor != null - ? Chip( - label: Text( - text, - textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: textColor, - fontWeight: FontWeight.bold), - ), - backgroundColor: chipColor, - ) : null)), - ScaleTransition( - scale: CurvedAnimation( - parent: controller, - curve: - Interval( - ((index + 1) / 10), 1.0, curve: Curves.linear), - ), - child: FloatingActionButton( - elevation: elevation, - mini: true, - backgroundColor: fabColor, - tooltip: tooltip, - child: icon, - heroTag: "$index", - onPressed: () { - onPressed(); - if (closeOnPress) { - close(); - } - }), - ) - ], - )); + child: FloatingActionButton( + elevation: widget.elevation, + mini: true, + backgroundColor: widget.fabColor, + tooltip: widget.tooltip, + child: widget.icon, + heroTag: "${widget.index}", + onPressed: () { + widget.onPressed(); + if (widget.closeOnPress) { + widget.close(); + } + }), + ) + ], + )); } } diff --git a/pubspec.lock b/pubspec.lock index ea890ff..49a0ce6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,28 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -45,35 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -85,55 +92,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.4" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" sdks: - dart: ">=2.1.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index e23a842..e994dca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,4 +14,4 @@ dev_dependencies: sdk: flutter environment: - sdk: ">=2.0.0-dev.28.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0'