lint changes reactions

This commit is contained in:
Deven Joshi
2021-05-05 16:32:32 +05:30
parent d1705c26a3
commit 645d21503a
2 changed files with 99 additions and 97 deletions
@@ -1,9 +1,14 @@
/// Reaction icon data
class ReactionIcon { class ReactionIcon {
final String type; /// Constructor for creating [ReactionIcon]
final String assetName;
ReactionIcon({ ReactionIcon({
required this.type, required this.type,
required this.assetName, required this.assetName,
}); });
/// Type of reaction
final String type;
/// Asset to display for reaction
final String assetName;
} }
@@ -3,23 +3,24 @@ import 'dart:math';
import 'package:ezanimation/ezanimation.dart'; import 'package:ezanimation/ezanimation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_svg_icon.dart'; import 'package:stream_chat_flutter/src/stream_svg_icon.dart';
import 'package:stream_chat_flutter/src/extension.dart';
import '../stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'extension.dart';
/// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/reaction_picker.png) /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/reaction_picker.png)
/// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/reaction_picker_paint.png) /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/reaction_picker_paint.png)
/// ///
/// It shows a reaction picker /// It shows a reaction picker
/// ///
/// Usually you don't use this widget as it's one of the default widgets used by [MessageWidget.onMessageActions]. /// Usually you don't use this widget as it's one of the default widgets used
/// by [MessageWidget.onMessageActions].
class ReactionPicker extends StatefulWidget { class ReactionPicker extends StatefulWidget {
/// Constructor for creating a [ReactionPicker] widget
const ReactionPicker({ const ReactionPicker({
Key? key, Key? key,
required this.message, required this.message,
}) : super(key: key); }) : super(key: key);
/// Message to attach the reaction to
final Message message; final Message message;
@override @override
@@ -39,7 +40,7 @@ class _ReactionPickerState extends State<ReactionPicker>
animations.add( animations.add(
EzAnimation.tween( EzAnimation.tween(
Tween(begin: 0.0, end: 1.0), Tween(begin: 0.0, end: 1.0),
Duration(milliseconds: 500), const Duration(milliseconds: 500),
curve: Curves.easeInOutBack, curve: Curves.easeInOutBack,
), ),
); );
@@ -51,108 +52,104 @@ class _ReactionPickerState extends State<ReactionPicker>
return TweenAnimationBuilder<double>( return TweenAnimationBuilder<double>(
tween: Tween(begin: 0, end: 1), tween: Tween(begin: 0, end: 1),
curve: Curves.easeInOutBack, curve: Curves.easeInOutBack,
duration: Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
builder: (context, val, wid) { builder: (context, val, wid) => Transform.scale(
return Transform.scale( scale: val,
scale: val, child: Material(
child: Material( borderRadius: BorderRadius.circular(24),
borderRadius: BorderRadius.circular(24), color: StreamChatTheme.of(context).colorTheme.white,
color: StreamChatTheme.of(context).colorTheme.white, clipBehavior: Clip.hardEdge,
clipBehavior: Clip.hardEdge, child: Padding(
child: Padding( padding: const EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric( horizontal: 16,
horizontal: 16, vertical: 8,
vertical: 8, ),
), child: Row(
child: Row( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: reactionIcons
children: reactionIcons .map<Widget>((reactionIcon) {
.map<Widget>((reactionIcon) { final ownReactionIndex = widget.message.ownReactions
final ownReactionIndex = widget.message.ownReactions ?.indexWhere((reaction) =>
?.indexWhere((reaction) => reaction.type == reactionIcon.type) ??
reaction.type == reactionIcon.type) ?? -1;
-1; final index = reactionIcons.indexOf(reactionIcon);
final index = reactionIcons.indexOf(reactionIcon);
return ConstrainedBox( return ConstrainedBox(
constraints: BoxConstraints.tightFor( constraints: const BoxConstraints.tightFor(
height: 24,
width: 24,
),
child: RawMaterialButton(
elevation: 0,
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
constraints: BoxConstraints.tightFor(
height: 24, height: 24,
width: 24, width: 24,
), ),
onPressed: () { child: RawMaterialButton(
if (ownReactionIndex != -1) { elevation: 0,
removeReaction( shape: ContinuousRectangleBorder(
context, borderRadius: BorderRadius.circular(16),
widget ),
.message.ownReactions![ownReactionIndex], constraints: const BoxConstraints.tightFor(
); height: 24,
} else { width: 24,
sendReaction( ),
context, onPressed: () {
reactionIcon.type, if (ownReactionIndex != -1) {
); removeReaction(
} context,
}, widget.message
child: AnimatedBuilder( .ownReactions![ownReactionIndex],
animation: animations[index],
builder: (context, val) {
return Transform.scale(
scale: animations[index].value,
child: StreamSvgIcon(
assetName: reactionIcon.assetName,
height: max(
0,
animations[index].value * 24.0,
),
width: max(
0,
animations[index].value * 24.0,
),
color: ownReactionIndex != -1
? StreamChatTheme.of(context)
.colorTheme
.accentBlue
: Theme.of(context)
.iconTheme
.color!
.withOpacity(.5),
),
); );
}), } else {
), sendReaction(
); context,
}) reactionIcon.type,
.insertBetween(SizedBox( );
width: 16, }
)) },
.toList(), child: AnimatedBuilder(
animation: animations[index],
builder: (context, val) => Transform.scale(
scale: animations[index].value,
child: StreamSvgIcon(
assetName: reactionIcon.assetName,
height: max(
0,
animations[index].value * 24.0,
),
width: max(
0,
animations[index].value * 24.0,
),
color: ownReactionIndex != -1
? StreamChatTheme.of(context)
.colorTheme
.accentBlue
: Theme.of(context)
.iconTheme
.color!
.withOpacity(.5),
),
)),
),
);
})
.insertBetween(const SizedBox(
width: 16,
))
.toList(),
),
), ),
), ),
), ));
);
});
} }
void triggerAnimations() async { void triggerAnimations() async {
for (var a in animations) { for (final a in animations) {
a.start(); a.start();
await Future.delayed(Duration(milliseconds: 100)); await Future.delayed(const Duration(milliseconds: 100));
} }
} }
void pop() async { void pop() async {
for (var a in animations) { for (final a in animations) {
a.stop(); a.stop();
} }
Navigator.of(context).pop(); Navigator.of(context).pop();
@@ -176,7 +173,7 @@ class _ReactionPickerState extends State<ReactionPicker>
@override @override
void dispose() { void dispose() {
for (var a in animations) { for (final a in animations) {
a.dispose(); a.dispose();
} }
super.dispose(); super.dispose();