Skip to content

Commit

Permalink
feat: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekAbdelouahed committed Oct 8, 2023
1 parent 5068684 commit 985ec14
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 49 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,6 @@ Next, import 'flutter_reaction_button.dart' into your dart code.
import 'package:flutter_reaction_button/flutter_reaction_button.dart';
```

## Parameters
| parameter | description | default |
| -------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OnReactionChanged | triggered when reaction button value change ||
| reactions | reactions appear in reactions box when long pressed on ReactionnButtonToggle or click on ReactionButton ||
| initialReaction | Default reaction button widget | first item in reactions list |
| boxPosition | Vertical position of reactions box relative to the button | VerticalPosition.TOP |
| boxHorizontalPosition | Horizontal position of reactions box relative to the button | HorizontalPosition.START |
| boxOffset | Offset to reposition the box from the computed place | Offset.zero |
| boxColor | Reactions box color | Colors.white |
| boxElevation | Reactions box elevation | 5 |
| boxRadius | Reactions box radius | 50 |
| boxPadding | Reactions box padding | const EdgeInsets.all(0) |
| boxDuration | Reactions box show/hide duration | 200 milliseconds |
| shouldChangeReaction | Should change initial reaction after selected one or not | true |
| itemScale | Scale ratio when item hovered | 0.3 |
| itemScaleDuration | Scale duration while dragging | const Duration(milliseconds: 100) |


## LICENSE

```legal
Expand Down
23 changes: 9 additions & 14 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# flutter_reaction_button_example

ReactionButtonToggle:
ReactionButton:

```dart
ReactionButtonToggle<String>(
onReactionChanged: (String? value, bool isChecked) {
debugPrint('Selected value: $value, isChecked: $isChecked');
ReactionButton<String>(
onReactionChanged: (Reaction<String>? reaction) {
debugPrint('Selected value: ${reaction?.value}');
},
reactions: <Reaction<String>>[
Reaction<String>(
value: 'like',
previewIcon: widget,
icon: widget,
),
Reaction<String>(
value: 'love',
previewIcon: widget,
icon: widget,
),
...
Expand All @@ -35,28 +33,25 @@ ReactionButtonToggle<String>(
ReactionButton:

```dart
ReactionButton<String(
onReactionChanged: (String? value) {
debugPrint('Selected value: $value');
ReactionButton<String>(
toggle: false,
onReactionChanged: (Reaction<String>? reaction) {
debugPrint('Selected language: ${reaction?.value}');
},
reactions: <Reaction<String>>[
Reaction<String>(
value: 'en',
previewIcon: widget,
icon: widget,
),
Reaction<String>(
value: 'ar',
previewIcon: widget,
icon: widget,
),
...
],
initialReaction: Reaction<String>(
value: null,
icon: Icon(
Icons.language,
),
icon: Icon(Icons.language),
),
)
```
4 changes: 2 additions & 2 deletions example/lib/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ImageWidget extends StatefulWidget {
}

class _ImageWidgetState extends State<ImageWidget> {
String? _selectedReaction;
Reaction<String>? _selectedReaction;

@override
Widget build(BuildContext context) {
Expand All @@ -39,7 +39,7 @@ class _ImageWidgetState extends State<ImageWidget> {
),
),
child: ReactionButton<String>(
onReactionChanged: (String? value) {
onReactionChanged: (Reaction<String>? value) {
setState(() {
_selectedReaction = value;
});
Expand Down
5 changes: 3 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class MyApp extends StatelessWidget {
dimension: 30,
child: ReactionButton<String>(
toggle: false,
onReactionChanged: (String? value) {
onReactionChanged: (Reaction<String>? reaction) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Selected language: $value'),
content:
Text('Selected language: ${reaction?.value}'),
),
);
},
Expand Down
4 changes: 2 additions & 2 deletions example/lib/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class PostWidget extends StatelessWidget {
children: [
ReactionButton<String>(
itemSize: const Size.square(40),
onReactionChanged: (String? value) {
debugPrint('Selected value: $value');
onReactionChanged: (Reaction<String>? reaction) {
debugPrint('Selected value: ${reaction?.value}');
},
reactions: reactions,
placeholder: data.defaultInitialReaction,
Expand Down
23 changes: 13 additions & 10 deletions lib/src/widgets/reaction_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ class ReactionButton<T> extends StatefulWidget {
this.boxPadding = const EdgeInsets.all(4),
this.boxAnimationDuration = const Duration(milliseconds: 200),
this.itemAnimationDuration = const Duration(milliseconds: 100),
this.hoverDuration = const Duration(milliseconds: 400),
this.child,
}) : _type = child != null ? ReactionType.container : ReactionType.button;

/// This triggers when reaction button value changed.
final ValueChanged<T?> onReactionChanged;
final ValueChanged<Reaction<T>?> onReactionChanged;

/// Default widget when [isChecked == false]
final Reaction<T>? placeholder;
Expand Down Expand Up @@ -79,6 +80,8 @@ class ReactionButton<T> extends StatefulWidget {

final Widget? child;

final Duration hoverDuration;

final ReactionType _type;

@override
Expand All @@ -99,10 +102,18 @@ class _ReactionButtonState<T> extends State<ReactionButton<T>> {

bool get _isContainer => widget._type == ReactionType.container;

void _updateReaction(Reaction<T>? reaction) {
_isChecked = reaction != widget.placeholder;
widget.onReactionChanged.call(reaction);
setState(() {
_selectedReaction = reaction;
});
}

void _onHover(Offset offset) {
_hoverTimer?.cancel();
_hoverTimer = Timer(
const Duration(milliseconds: 400),
widget.hoverDuration,
() {
_onShowReactionsBox(offset);
},
Expand Down Expand Up @@ -151,14 +162,6 @@ class _ReactionButtonState<T> extends State<ReactionButton<T>> {
Overlay.of(context).insert(_overlayEntry!);
}

void _updateReaction(Reaction<T>? reaction) {
_isChecked = reaction != widget.placeholder;
widget.onReactionChanged.call(reaction?.value);
setState(() {
_selectedReaction = reaction;
});
}

void _disposeOverlayEntry() {
_overlayEntry
?..remove()
Expand Down

0 comments on commit 985ec14

Please sign in to comment.