Skip to content

Commit

Permalink
Merge pull request #70 from guozhigq/feature-scroll_to_index
Browse files Browse the repository at this point in the history
Feature scroll to index
  • Loading branch information
guozhigq authored Mar 24, 2023
2 parents 922abc6 + 22dcecc commit 5315ac7
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 47 deletions.
17 changes: 12 additions & 5 deletions lib/components/message/notice_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:flutter_v2ex/utils/string.dart';
import 'package:flutter_v2ex/components/common/avatar.dart';
import 'package:flutter_v2ex/components/topic/html_render.dart';
import 'package:flutter_v2ex/models/web/item_member_notice.dart';
Expand Down Expand Up @@ -59,11 +60,17 @@ class _NoticeItemState extends State<NoticeItem> {
color: Theme.of(context).colorScheme.onInverseSurface,
child: InkWell(
onTap: () {
String replyCount = widget.noticeItem.topicHref.split('#reply')[1];
Get.toNamed('/t/${widget.noticeItem.topicId}', parameters: {
'source': 'notice',
'floorNumber': replyCount
});
String floorNumber =
widget.noticeItem.topicHref.split('#reply')[1];
NoticeType noticeType = widget.noticeItem.noticeType;
Map<String, String> parameters = {};
if (noticeType.name == NoticeType.reply.name ||
noticeType.name == NoticeType.thanksReply.name) {
// 回复 or 感谢回复
parameters = {'source': 'notice', 'floorNumber': floorNumber};
}
Get.toNamed('/t/${widget.noticeItem.topicId}',
parameters: parameters);
},
child: Ink(
padding: const EdgeInsets.fromLTRB(15, 15, 5, 15),
Expand Down
105 changes: 88 additions & 17 deletions lib/components/topic/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'dart:math' as math;

class ReplyListItem extends StatefulWidget {
ReplyListItem({
Expand All @@ -22,6 +23,7 @@ class ReplyListItem extends StatefulWidget {
this.totalPage,
this.source,
this.replyList,
this.floorNumber,
Key? key,
}) : super(key: key);

Expand All @@ -31,12 +33,16 @@ class ReplyListItem extends StatefulWidget {
int? totalPage;
String? source;
List? replyList;
int? floorNumber;



@override
State<ReplyListItem> createState() => _ReplyListItemState();
}

class _ReplyListItemState extends State<ReplyListItem> {
class _ReplyListItemState extends State<ReplyListItem>
with TickerProviderStateMixin {
// bool isChoose = false;
List<Map<dynamic, dynamic>> sheetMenu = [
{
Expand Down Expand Up @@ -80,6 +86,10 @@ class _ReplyListItemState extends State<ReplyListItem> {
String? loginUserName;
bool highLightOp = GStorage().getHighlightOp();

late AnimationController _controller;
int _animationCount = 0;
final int _maxAnimationCount = 3;

@override
void initState() {
// TODO: implement initState
Expand All @@ -97,6 +107,24 @@ class _ReplyListItemState extends State<ReplyListItem> {
setState(() {
reply = widget.reply;
});

_controller = AnimationController(
lowerBound: 0.95,
duration: const Duration(milliseconds: 600),
vsync: this,
)..addListener(() {
if (_controller.status == AnimationStatus.completed) {
_animationCount++;
if (_animationCount >= _maxAnimationCount) {
_controller.stop();
} else {
_controller.reverse();
}
} else if (_controller.status == AnimationStatus.dismissed) {
_controller.forward();
}
});
_controller.forward();
}

void menuAction(id) {
Expand Down Expand Up @@ -238,6 +266,13 @@ class _ReplyListItemState extends State<ReplyListItem> {
}
}

@override
void dispose() {
// TODO: implement dispose
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return AnimatedSize(
Expand Down Expand Up @@ -414,26 +449,62 @@ class _ReplyListItemState extends State<ReplyListItem> {
}

Widget replyItemTopic(context, child) {
return RepaintBoundary(
key: repaintKey,
child: Material(
color: reply.isOwner && highLightOp
? Theme.of(context).colorScheme.onInverseSurface
: null,
child: InkWell(
onTap: () async {
/// 增加200毫秒延迟 水波纹动画
await Future.delayed(const Duration(milliseconds: 200));
replyComment();
},
onLongPress: () {},
child: Ink(
padding: const EdgeInsets.fromLTRB(14, 12, 12, 0),
child: child,
return AnimatedBuilder(
animation: _controller,
child: RepaintBoundary(
key: repaintKey,
child: Material(
color: reply.isOwner
? Theme.of(context).colorScheme.onInverseSurface
: null,
child: InkWell(
onTap: () async {
/// 增加200毫秒延迟 水波纹动画
await Future.delayed(const Duration(milliseconds: 200));
replyComment();
},
onLongPress: () {},
child: Ink(
padding: const EdgeInsets.fromLTRB(14, 12, 12, 0),
child: child,
),
),
),
),
builder: (BuildContext context, Widget? child) {
return Transform.scale(
scale: widget.floorNumber! > 0 &&
reply.floorNumber == widget.floorNumber!
? _controller.value
: 1,
child: child,
);
},
);
// return
// RepaintBoundary(
// key: repaintKey,
// child: Material(
// color:
// widget.floorNumber! > 0 && reply.floorNumber == widget.floorNumber!
// ? Theme.of(context).colorScheme.errorContainer.withOpacity(0.5)
// : reply.isOwner
// ? Theme.of(context).colorScheme.onInverseSurface
// : null,
// child: InkWell(
// onTap: () async {
// /// 增加200毫秒延迟 水波纹动画
// await Future.delayed(const Duration(milliseconds: 200));
// replyComment();
// },
// onLongPress: () {},
// child: Ink(
// padding: const EdgeInsets.fromLTRB(14, 12, 12, 0),
// child: child,
// ),
// ),
// ),
// );
}

Widget replyItemSheet(context, child) {
Expand Down
Loading

0 comments on commit 5315ac7

Please sign in to comment.