Skip to content

Commit

Permalink
fix for dumb way to handle state
Browse files Browse the repository at this point in the history
state should be passed straight through so that a change in parameters is reflected in a new render
previous implementation made that impossible because the state was set only once upon the constructor of state
  • Loading branch information
shoxter committed Jun 12, 2021
1 parent 2e12927 commit b960fa8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 83 deletions.
23 changes: 14 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
## [0.1.0] - 09/21/2018
## [0.1.5] - 06/12/2021

* Initial fork from flutter_fab_dialer
* Fixed default "tooltip" from always saying "Increment"
* Added optional animation duration for the animation
* Changed the hard-coded rotation to a transform animation so that it works with any icons
* Fixed the bad way state was being handled
* State is now accessed via `widget.` as opposed to being initialized only once upon creation of the `State` object

## [0.1.1] - 09/21/2018
## [0.1.4] - 05/10/2019

* Fixed README from warning about nonexistent breaking changes
* Fixed overflow on smaller screens

## [0.1.3] - 11/08/2018

* Skipped version 0.1.2 to match actual package version
* Added ability to close on tap
* Modified dependencies

## [0.1.4] - 05/10/2019
## [0.1.1] - 09/21/2018

* Fixed README from warning about nonexistent breaking changes

## [0.1.0] - 09/21/2018

* Fixed overflow on smaller screens
* Initial fork from flutter_fab_dialer
* Fixed default "tooltip" from always saying "Increment"
* Added optional animation duration for the animation
* Changed the hard-coded rotation to a transform animation so that it works with any icons
70 changes: 27 additions & 43 deletions lib/src/fab_dialer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,30 @@ class FabDialer extends StatefulWidget {

@override
FabDialerState createState() =>
FabDialerState(
_fabMiniMenuItemList, _fabColor, _fabIcon, _closeFabIcon,
_animationDuration, closeOnTap);
FabDialerState();
}

class FabDialerState extends State<FabDialer> with TickerProviderStateMixin {
FabDialerState(this._fabMiniMenuItemList, this._fabColor, this._fabIcon,
this._closeFabIcon, this._animationDuration, this.closeOnTap);
FabDialerState();

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;

@override
void initState() {
final int animationDuration = _animationDuration == null
final int animationDuration = widget._animationDuration == null
? 180
: _animationDuration;
: widget._animationDuration;
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: animationDuration),
);

_controller.reverse();

setFabMenu(this._fabMiniMenuItemList);
super.initState();
}

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

this._fabMenuItems = fabMenuItems;
}

void _rotate() {
if (_isRotated) {
_isRotated = false;
Expand All @@ -84,16 +50,34 @@ class FabDialerState extends State<FabDialer> with TickerProviderStateMixin {

@override
Widget build(BuildContext context) {
final Icon closeIcon = _closeFabIcon == null
List<FabMenuMiniItemWidget> fabMenuItems = [];
for (int i = 0; i < widget._fabMiniMenuItemList.length; i++) {
fabMenuItems.add(FabMenuMiniItemWidget(
tooltip: widget._fabMiniMenuItemList[i].tooltip,
text: widget._fabMiniMenuItemList[i].text,
elevation: widget._fabMiniMenuItemList[i].elevation,
icon: widget._fabMiniMenuItemList[i].icon,
index: i,
onPressed: widget._fabMiniMenuItemList[i].onPressed,
textColor: widget._fabMiniMenuItemList[i].textColor,
fabColor: widget._fabMiniMenuItemList[i].fabColor,
chipColor: widget._fabMiniMenuItemList[i].chipColor,
controller: _controller,
closeOnPress: widget.closeOnTap,
close: _rotate
));
}

final Icon closeIcon = widget._closeFabIcon == null
? Icon(Icons.close)
: _closeFabIcon;
: widget._closeFabIcon;
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: _fabMenuItems,
children: fabMenuItems,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand All @@ -108,9 +92,9 @@ class FabDialerState extends State<FabDialer> with TickerProviderStateMixin {
alignment: Alignment.center,
child: _controller.value >= 0.5
? closeIcon
: _fabIcon,
: widget._fabIcon,
),
backgroundColor: _fabColor,
backgroundColor: widget._fabColor,
onPressed: _rotate);
},
)
Expand Down
69 changes: 38 additions & 31 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
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
Expand All @@ -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
Expand All @@ -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-0.0 <3.0.0"

0 comments on commit b960fa8

Please sign in to comment.