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

Added Null safe #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
.pub/
packages
pubspec.lock
/.vs
/.dart_tool
118 changes: 55 additions & 63 deletions lib/src/fab_dialer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<FabMiniMenuItem> _fabMiniMenuItemList;
final Color _fabColor;
Expand All @@ -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<FabDialer> 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<FabMiniMenuItem> _fabMiniMenuItemList;
final Color _fabColor;
final Icon _fabIcon;
final Icon _closeFabIcon;
final int _animationDuration;
final bool closeOnTap;
List<FabMenuMiniItemWidget> _fabMenuItems;

AnimationController _controller;
late List<FabMenuMiniItemWidget> _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();
Expand All @@ -51,21 +43,21 @@ class FabDialerState extends State<FabDialer> with TickerProviderStateMixin {
}

void setFabMenu(List<FabMiniMenuItem> fabMenuList) {
List<FabMenuMiniItemWidget> fabMenuItems = List();
var fabMenuItems = <FabMenuMiniItemWidget>[];
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
));
}

Expand All @@ -84,39 +76,39 @@ class FabDialerState extends State<FabDialer> 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: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: _fabMenuItems,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
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: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: _fabMenuItems,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
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);
},
)
],
),
],
));
}
}
}
138 changes: 73 additions & 65 deletions lib/src/fab_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<FabMenuMiniItemWidget> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 5.0, horizontal: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 8.0),
child: ScaleTransition(
margin: EdgeInsets.symmetric(vertical: 5.0, horizontal: 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
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();
}
}),
)
],
));
}
}
Loading