我带着更多的问题来到这里。今天,我遇到了一些关于Animator的问题。我正在尝试为我的帖子喜欢的代码制作一个小小的心形符号动画,但我一直收到以下错误。
Compiler message:
../../../developer/flutter/.pub-cache/hosted/pub.dartlang.org/animator-0.1.4/lib/animator.dart:457:7: Error: No named parameter with the name 'blocs'.
blocs: [_animatorBloc],
^^^^^
../../../developer/flutter/.pub-cache/hosted/pub.dartlang.org/states_rebuilder-1.15.0/lib/src/state_with_mixin_builder.dart:142:3: Context: Found this candidate, but the arguments don't match.
StateWithMixinBuilder({
^^^^^^^^^^^^^^^^^^^^^
../../../developer/flutter/.pub-cache/hosted/pub.dartlang.org/animator-0.1.4/lib/animator.dart:494:27: Error: Method not found: 'StatesRebuilder.addToListeners'.
StatesRebuilder.addToListeners(
^^^^^^^^^^^^^^
../../../developer/flutter/.pub-cache/hosted/pub.dartlang.org/animator-0.1.4/lib/animator.dart:559:27: Error: Method not found: 'StatesRebuilder.removeFromListeners'.
StatesRebuilder.removeFromListeners(b, widget.name, "$hashCode");
^^^^^^^^^^^^^^^^^^^我试图运行flutter干净,但没有效果,我无法在网上找到最好的答案。我试图更新我的pubspec.yaml,但那弄乱了我在项目中的大量代码。我想看看其他人会怎么想。
Post.dart --看buildPostImage
class Post extends StatefulWidget {
final String postId;
final String ownerId;
final String userName;
final String location;
final String description;
final String mediaUrl;
final dynamic likes;
Post({
this.postId,
this.ownerId,
this.userName,
this.location,
this.description,
this.mediaUrl,
this.likes,
});
factory Post.fromDocument(DocumentSnapshot doc){
return Post(
postId: doc['postId'],
ownerId: doc['ownerId'],
userName: doc['username'],
location: doc['location'],
description: doc['description'],
mediaUrl: doc['mediaUrl'],
likes: doc['likes'],
);
}
int getLikeCount(likes) {
// if no likes, return 0
if(likes == null){
return 0;
}
int count = 0;
//if like explicitly set to true, add a like
likes.values.forEach((val){
if(val == true){
count += 1;
}
});
return count;
}
@override
_PostState createState() => _PostState(
postId: this.postId,
ownerId: this.ownerId,
userName: this.userName,
location: this.location,
description: this.description,
mediaUrl: this.mediaUrl,
likeCount: getLikeCount(this.likes),
likes: this.likes
);
}
class _PostState extends State<Post> {
final String currentUserId = currentUser?.id;
final String postId;
final String ownerId;
final String userName;
final String location;
final String description;
final String mediaUrl;
int likeCount;
Map likes;
bool isLiked;
bool showHeart = false;
_PostState({
this.postId,
this.ownerId,
this.userName,
this.location,
this.description,
this.mediaUrl,
this.likes,
this.likeCount,
});
buildPostHeader(){
return FutureBuilder(
future: usersRef.document(ownerId).get(),
builder: (context, snapshot){
if(!snapshot.hasData){
return circularProgress(context);
}
User user = User.fromDocument(snapshot.data);
return ListTile(
leading: CircleAvatar(
backgroundImage: CachedNetworkImageProvider(user.photoUrl),
backgroundColor: Colors.grey,
),
title: GestureDetector(
child: Text(
user.username,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold
),
),
),
subtitle: Text(location),
trailing: IconButton(
onPressed: () => print("deleting post"),
icon: Icon(Icons.more_vert),
),
);
},
);
}
handleLikePosts() {
bool _isLiked = likes[currentUserId] == true;
if (_isLiked) {
postsRef.document(ownerId)
.collection('userPosts')
.document(postId)
.updateData({'likes.$currentUserId': false});
setState(() {
likeCount -= 1;
isLiked = false;
likes[currentUserId] = false;
});
} else if (!_isLiked) {
postsRef.document(ownerId)
.collection('userPosts')
.document(postId)
.updateData({'likes.$currentUserId': true});
setState(() {
likeCount += 1;
isLiked = true;
likes[currentUserId] = true;
showHeart = true;
});
Timer(Duration(milliseconds: 500),(){
setState(() {
showHeart = false;
});
});
}
}
buildPostImage() {
return GestureDetector(
onDoubleTap: handleLikePosts,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
cachedNetworkImage(mediaUrl),
showHeart
? Animator(
duration: Duration(milliseconds: 300),
tween: Tween(begin: 0.8, end: 1.4),
curve: Curves.elasticOut,
cycles: 0,
builder: (anim) => Transform.scale(
scale: anim.value,
child: Icon(
Icons.favorite,
size: 80.0,
color: Colors.red,
),
),
)
: Text(""),
],
),
);
}
buildPostFooter() {
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(padding: EdgeInsets.only(top: 40.0, left: 20.0)),
GestureDetector(
onTap: handleLikePosts,
child: Icon(
isLiked ? Icons.favorite : Icons.favorite_border,
size: 28.0,
color: Colors.pink,
),
),
Padding(padding: EdgeInsets.only(right: 20.0)),
GestureDetector(
onTap: () => print('Showing comments'),
child: Icon(
Icons.chat,
size: 28.0,
color: Colors.blue[900],
),
),
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0),
child: Text(
"$likeCount likes ",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0),
child: Text(
"$userName ",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: Text(description),
)
],
)
],
);
}
@override
Widget build(BuildContext context) {
isLiked = (likes[currentUserId] == true);
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
buildPostHeader(),
buildPostImage(),
buildPostFooter(),
],
);
}
}
Thank you all for the help.发布于 2020-08-31 20:43:45
看起来您使用的是0.1.4版本的Animator包。将其更新到2.0.1 ( visit here for Animator Package Updates )的最新版本。
Animator(
duration: Duration(milliseconds: 300),
tween: Tween(begin: 0.8, end: 1.5),
curve: Curves.elasticOut,
cycles: 0,
builder: (context, anim, child) => Transform.scale(
scale: anim.value,
child: Icon(Icons.favorite, color: Colors.pink, size: 100.0,),
),
)检查它是否正常工作!
https://stackoverflow.com/questions/63659269
复制相似问题