fix(flutter): feed 长按加速与刷新转圈
This commit is contained in:
1 parent
564c0dbbef
commit
ea9ea6e606
5 files changed
+317
-103
No files matched your search
@@ -366,83 +366,82 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
|||||||
if (logic.pip || logic.pipPreparing)
|
if (logic.pip || logic.pipPreparing)
|
||||||
const SizedBox.expand()
|
const SizedBox.expand()
|
||||||
else if (widget.homeMode)
|
else if (widget.homeMode)
|
||||||
_chromeVisible
|
HomeFeedOverlay(
|
||||||
? HomeFeedOverlay(
|
l10n: l10n,
|
||||||
l10n: l10n,
|
drama: drama,
|
||||||
drama: drama,
|
episode: episode,
|
||||||
episode: episode,
|
controller: ready ? videoPort!.controller : null,
|
||||||
controller: ready ? videoPort!.controller : null,
|
visible: _chromeVisible,
|
||||||
liked: interactions.isLiked(drama.id),
|
boosting: _boosting,
|
||||||
likeCount:
|
onBoostStart: _startBoost,
|
||||||
interactions.likeCount(drama.id) ?? drama.likeCount,
|
onBoostEnd: _endBoost,
|
||||||
favoriteCount: drama.favoriteCount == null
|
onTogglePlay: () =>
|
||||||
? null
|
logic.session.setUserWantsPlay(!logic.session.userWantsPlay),
|
||||||
: drama.favoriteCount! + (_favoriteDelta[drama.id] ?? 0),
|
liked: interactions.isLiked(drama.id),
|
||||||
commentCount: drama.commentCount,
|
likeCount: interactions.likeCount(drama.id) ?? drama.likeCount,
|
||||||
saved: context.watch<FavoriteController>().isSaved(drama.id),
|
favoriteCount: drama.favoriteCount == null
|
||||||
onLike: () async {
|
? null
|
||||||
if (await ensureSignedIn(context)) {
|
: drama.favoriteCount! + (_favoriteDelta[drama.id] ?? 0),
|
||||||
if (!context.mounted) return;
|
commentCount: drama.commentCount,
|
||||||
unawaited(context.read<Haptics>().lightImpact());
|
saved: context.watch<FavoriteController>().isSaved(drama.id),
|
||||||
final result = await interactions.toggleDramaLike(
|
onLike: () async {
|
||||||
drama.id,
|
if (await ensureSignedIn(context)) {
|
||||||
);
|
if (!context.mounted) return;
|
||||||
if (!result.isSuccess && context.mounted) {
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
final result = await interactions.toggleDramaLike(drama.id);
|
||||||
SnackBar(
|
if (!result.isSuccess && context.mounted) {
|
||||||
content: Text(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
result.errorMessage ??
|
SnackBar(
|
||||||
AppLocalizations.of(context)!.likeFailed,
|
content: Text(
|
||||||
),
|
result.errorMessage ??
|
||||||
),
|
AppLocalizations.of(context)!.likeFailed,
|
||||||
);
|
),
|
||||||
}
|
),
|
||||||
}
|
);
|
||||||
},
|
}
|
||||||
onSave: () async {
|
}
|
||||||
final favorites = context.read<FavoriteController>();
|
},
|
||||||
if (await ensureSignedIn(context)) {
|
onSave: () async {
|
||||||
if (!context.mounted) return;
|
final favorites = context.read<FavoriteController>();
|
||||||
unawaited(context.read<Haptics>().lightImpact());
|
if (await ensureSignedIn(context)) {
|
||||||
final ok = await favorites.toggle(drama.id, card: drama);
|
if (!context.mounted) return;
|
||||||
if (ok || !context.mounted) return;
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
final ok = await favorites.toggle(drama.id, card: drama);
|
||||||
SnackBar(content: Text(l10n.favoriteToggleFailed)),
|
if (ok || !context.mounted) return;
|
||||||
);
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
}
|
SnackBar(content: Text(l10n.favoriteToggleFailed)),
|
||||||
},
|
);
|
||||||
onComments: () => logic.showComments(context, drama),
|
}
|
||||||
onShare: () => logic.shareDrama(context, drama),
|
},
|
||||||
onEpisodes: () => logic.showEpisodes(context),
|
onComments: () => logic.showComments(context, drama),
|
||||||
onDetail: () => unawaited(logic.openDetail(context)),
|
onShare: () => logic.shareDrama(context, drama),
|
||||||
onOpenFullPlayer: () async {
|
onEpisodes: () => logic.showEpisodes(context),
|
||||||
await widget.onOpenFullPlayer?.call(drama, episode);
|
onDetail: () => unawaited(logic.openDetail(context)),
|
||||||
if (!mounted || !widget.active) return;
|
onOpenFullPlayer: () async {
|
||||||
logic.session.setUserWantsPlay(true);
|
await widget.onOpenFullPlayer?.call(drama, episode);
|
||||||
},
|
if (!mounted || !widget.active) return;
|
||||||
onRefreshFeed: () async {
|
logic.session.setUserWantsPlay(true);
|
||||||
final ok = await widget.onRefreshFeed?.call() ?? true;
|
},
|
||||||
if (!context.mounted || ok) return;
|
onRefreshFeed: () async {
|
||||||
ScaffoldMessenger.of(
|
final ok = await widget.onRefreshFeed?.call() ?? true;
|
||||||
context,
|
if (context.mounted && !ok) {
|
||||||
).showSnackBar(SnackBar(content: Text(l10n.catalogError)));
|
ScaffoldMessenger.of(
|
||||||
},
|
context,
|
||||||
onDownload: () => requestEpisodeDownload(context, episode.id),
|
).showSnackBar(SnackBar(content: Text(l10n.catalogError)));
|
||||||
onClear: () => setState(() => _chromeVisible = false),
|
}
|
||||||
onSearch:
|
return ok;
|
||||||
widget.onSearch ?? () => logic.showDiscover(context),
|
},
|
||||||
onScrubStart: ready
|
onDownload: () => requestEpisodeDownload(context, episode.id),
|
||||||
? () => logic.beginScrub(videoPort!)
|
onClear: () => setState(() => _chromeVisible = false),
|
||||||
: null,
|
onSearch: widget.onSearch ?? () => logic.showDiscover(context),
|
||||||
onSeek: ready
|
onScrubStart: ready ? () => logic.beginScrub(videoPort!) : null,
|
||||||
? (position) =>
|
onSeek: ready
|
||||||
logic.seekTo(context, videoPort!, position)
|
? (position) => logic.seekTo(context, videoPort!, position)
|
||||||
: null,
|
: null,
|
||||||
onPip: logic.pictureInPicture.isPlatformSupported
|
onPip: logic.pictureInPicture.isPlatformSupported
|
||||||
? () => unawaited(logic.enterPip(context))
|
? () => unawaited(logic.enterPip(context))
|
||||||
: null,
|
: null,
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink()
|
|
||||||
else
|
else
|
||||||
PlayerPlaybackOverlay(
|
PlayerPlaybackOverlay(
|
||||||
data: PlayerOverlayData(
|
data: PlayerOverlayData(
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ const double _tagFontSize = 11;
|
|||||||
const double _fullBarHeight = 44;
|
const double _fullBarHeight = 44;
|
||||||
const double _progressHeight = 2;
|
const double _progressHeight = 2;
|
||||||
const double _progressHitHeight = 24;
|
const double _progressHitHeight = 24;
|
||||||
|
const List<Shadow> _boostTextShadows = [
|
||||||
|
Shadow(color: Colors.black54, blurRadius: 5, offset: Offset(0, 1)),
|
||||||
|
];
|
||||||
const int _maxTags = 4;
|
const int _maxTags = 4;
|
||||||
final RegExp _tagSplitter = RegExp(r'[,/、·]');
|
final RegExp _tagSplitter = RegExp(r'[,/、·]');
|
||||||
|
|
||||||
@@ -40,6 +43,8 @@ class HomeFeedOverlay extends StatefulWidget {
|
|||||||
required this.controller,
|
required this.controller,
|
||||||
required this.liked,
|
required this.liked,
|
||||||
required this.saved,
|
required this.saved,
|
||||||
|
required this.visible,
|
||||||
|
required this.boosting,
|
||||||
required this.onLike,
|
required this.onLike,
|
||||||
required this.onSave,
|
required this.onSave,
|
||||||
required this.onComments,
|
required this.onComments,
|
||||||
@@ -51,6 +56,9 @@ class HomeFeedOverlay extends StatefulWidget {
|
|||||||
required this.onDownload,
|
required this.onDownload,
|
||||||
required this.onClear,
|
required this.onClear,
|
||||||
required this.onSearch,
|
required this.onSearch,
|
||||||
|
required this.onTogglePlay,
|
||||||
|
required this.onBoostStart,
|
||||||
|
required this.onBoostEnd,
|
||||||
this.onScrubStart,
|
this.onScrubStart,
|
||||||
this.onSeek,
|
this.onSeek,
|
||||||
this.likeCount,
|
this.likeCount,
|
||||||
@@ -70,6 +78,8 @@ class HomeFeedOverlay extends StatefulWidget {
|
|||||||
final int? commentCount;
|
final int? commentCount;
|
||||||
final bool saved;
|
final bool saved;
|
||||||
final String authorNote;
|
final String authorNote;
|
||||||
|
final bool visible;
|
||||||
|
final bool boosting;
|
||||||
final VoidCallback onLike;
|
final VoidCallback onLike;
|
||||||
final VoidCallback onSave;
|
final VoidCallback onSave;
|
||||||
final VoidCallback onComments;
|
final VoidCallback onComments;
|
||||||
@@ -77,13 +87,16 @@ class HomeFeedOverlay extends StatefulWidget {
|
|||||||
final VoidCallback onEpisodes;
|
final VoidCallback onEpisodes;
|
||||||
final VoidCallback onDetail;
|
final VoidCallback onDetail;
|
||||||
final VoidCallback onOpenFullPlayer;
|
final VoidCallback onOpenFullPlayer;
|
||||||
final VoidCallback onRefreshFeed;
|
final Future<bool> Function() onRefreshFeed;
|
||||||
final VoidCallback onDownload;
|
final VoidCallback onDownload;
|
||||||
final VoidCallback onClear;
|
final VoidCallback onClear;
|
||||||
final VoidCallback onSearch;
|
final VoidCallback onSearch;
|
||||||
|
final VoidCallback onTogglePlay;
|
||||||
final VoidCallback? onPip;
|
final VoidCallback? onPip;
|
||||||
final VoidCallback? onScrubStart;
|
final VoidCallback? onScrubStart;
|
||||||
final ValueChanged<Duration>? onSeek;
|
final ValueChanged<Duration>? onSeek;
|
||||||
|
final VoidCallback onBoostStart;
|
||||||
|
final VoidCallback onBoostEnd;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<HomeFeedOverlay> createState() => _HomeFeedOverlayState();
|
State<HomeFeedOverlay> createState() => _HomeFeedOverlayState();
|
||||||
@@ -91,30 +104,100 @@ class HomeFeedOverlay extends StatefulWidget {
|
|||||||
|
|
||||||
class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
||||||
_FeedTab _tab = _FeedTab.recommend;
|
_FeedTab _tab = _FeedTab.recommend;
|
||||||
|
bool _refreshing = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
bottom: false,
|
bottom: false,
|
||||||
child: Column(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
_header(context),
|
Positioned.fill(
|
||||||
Expanded(
|
child: LayoutBuilder(
|
||||||
child: Align(
|
builder: (context, constraints) => Listener(
|
||||||
alignment: const Alignment(1.0, 0.68),
|
onPointerUp: (_) => widget.onBoostEnd(),
|
||||||
child: Padding(
|
onPointerCancel: (_) => widget.onBoostEnd(),
|
||||||
padding: const EdgeInsets.fromLTRB(0, 0, 10, 16),
|
child: GestureDetector(
|
||||||
child: _rail(),
|
key: const Key('home-feed-gesture'),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: widget.onTogglePlay,
|
||||||
|
onLongPressStart: (details) =>
|
||||||
|
_handleLongPressStart(details, constraints.maxWidth),
|
||||||
|
onLongPressEnd: (_) => widget.onBoostEnd(),
|
||||||
|
onLongPressCancel: widget.onBoostEnd,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_bottomInfo(),
|
if (widget.boosting)
|
||||||
_fullSeriesBar(),
|
Column(children: [const Spacer(), _boostHint(), _fullSeriesBar()])
|
||||||
|
else if (widget.visible)
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
_header(context),
|
||||||
|
Expanded(
|
||||||
|
child: Align(
|
||||||
|
alignment: const Alignment(1.0, 0.80),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(0, 0, 10, 16),
|
||||||
|
child: _rail(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_bottomInfo(),
|
||||||
|
_fullSeriesBar(),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleLongPressStart(LongPressStartDetails details, double width) {
|
||||||
|
final third = width / 3;
|
||||||
|
final dx = details.localPosition.dx;
|
||||||
|
if (dx < third || dx > width - third) {
|
||||||
|
widget.onBoostStart();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_openMore(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _boostHint() {
|
||||||
|
return Padding(
|
||||||
|
key: const Key('home-feed-speed-boost-hint'),
|
||||||
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.play_arrow_rounded,
|
||||||
|
color: AppColors.blue,
|
||||||
|
size: 16,
|
||||||
|
shadows: _boostTextShadows,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
widget.l10n.speedBoosting('2.0'),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: AppColors.blue,
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
shadows: _boostTextShadows,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _refresh() async {
|
||||||
|
if (_refreshing) return;
|
||||||
|
setState(() => _refreshing = true);
|
||||||
|
await widget.onRefreshFeed();
|
||||||
|
if (mounted) setState(() => _refreshing = false);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _header(BuildContext context) {
|
Widget _header(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 4),
|
padding: const EdgeInsets.fromLTRB(8, 6, 8, 4),
|
||||||
@@ -124,7 +207,8 @@ class _HomeFeedOverlayState extends State<HomeFeedOverlay> {
|
|||||||
tooltip: widget.l10n.retry,
|
tooltip: widget.l10n.retry,
|
||||||
dimension: _topIconSize,
|
dimension: _topIconSize,
|
||||||
glyphSize: _topIconGlyph,
|
glyphSize: _topIconGlyph,
|
||||||
onTap: widget.onRefreshFeed,
|
refreshing: _refreshing,
|
||||||
|
onTap: _refresh,
|
||||||
onLongPress: () => _openMore(context),
|
onLongPress: () => _openMore(context),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
part of 'home_feed_overlay.dart';
|
part of 'home_feed_overlay.dart';
|
||||||
|
|
||||||
const double _thumbSize = 6;
|
const double _thumbSize = 6;
|
||||||
const double _thumbActiveSize = 10;
|
const double _thumbActiveSize = 14;
|
||||||
const double _trackActiveHeight = 4;
|
const double _trackActiveHeight = 6;
|
||||||
const double _lineCenterFromBottom = 6;
|
const double _lineCenterFromBottom = 8;
|
||||||
|
|
||||||
/// 顶部频道 tab:漫剧点击提示即将上线。
|
/// 顶部频道 tab:漫剧点击提示即将上线。
|
||||||
enum _FeedTab {
|
enum _FeedTab {
|
||||||
@@ -69,6 +69,7 @@ class _RefreshButton extends StatelessWidget {
|
|||||||
required this.tooltip,
|
required this.tooltip,
|
||||||
required this.dimension,
|
required this.dimension,
|
||||||
required this.glyphSize,
|
required this.glyphSize,
|
||||||
|
required this.refreshing,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
required this.onLongPress,
|
required this.onLongPress,
|
||||||
});
|
});
|
||||||
@@ -76,6 +77,7 @@ class _RefreshButton extends StatelessWidget {
|
|||||||
final String tooltip;
|
final String tooltip;
|
||||||
final double dimension;
|
final double dimension;
|
||||||
final double glyphSize;
|
final double glyphSize;
|
||||||
|
final bool refreshing;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
final VoidCallback onLongPress;
|
final VoidCallback onLongPress;
|
||||||
|
|
||||||
@@ -90,12 +92,23 @@ class _RefreshButton extends StatelessWidget {
|
|||||||
onLongPress: onLongPress,
|
onLongPress: onLongPress,
|
||||||
child: SizedBox.square(
|
child: SizedBox.square(
|
||||||
dimension: dimension,
|
dimension: dimension,
|
||||||
child: Icon(
|
child: refreshing
|
||||||
Icons.refresh_rounded,
|
? const Center(
|
||||||
size: glyphSize,
|
child: SizedBox.square(
|
||||||
color: Colors.white,
|
dimension: 18,
|
||||||
shadows: const [Shadow(blurRadius: 6, color: Colors.black)],
|
child: CircularProgressIndicator(
|
||||||
),
|
key: Key('home-feed-refreshing'),
|
||||||
|
strokeWidth: 2,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
Icons.refresh_rounded,
|
||||||
|
size: glyphSize,
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: const [Shadow(blurRadius: 6, color: Colors.black)],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||||
@@ -104,6 +106,11 @@ void main() {
|
|||||||
controller: null,
|
controller: null,
|
||||||
liked: true,
|
liked: true,
|
||||||
saved: false,
|
saved: false,
|
||||||
|
visible: true,
|
||||||
|
boosting: false,
|
||||||
|
onTogglePlay: () {},
|
||||||
|
onBoostStart: () {},
|
||||||
|
onBoostEnd: () {},
|
||||||
likeCount: 1006,
|
likeCount: 1006,
|
||||||
favoriteCount: 32000,
|
favoriteCount: 32000,
|
||||||
commentCount: 12,
|
commentCount: 12,
|
||||||
@@ -114,7 +121,7 @@ void main() {
|
|||||||
onEpisodes: () {},
|
onEpisodes: () {},
|
||||||
onDetail: () {},
|
onDetail: () {},
|
||||||
onOpenFullPlayer: () {},
|
onOpenFullPlayer: () {},
|
||||||
onRefreshFeed: () {},
|
onRefreshFeed: () async => true,
|
||||||
onDownload: () {},
|
onDownload: () {},
|
||||||
onClear: () {},
|
onClear: () {},
|
||||||
onSearch: () {},
|
onSearch: () {},
|
||||||
@@ -189,6 +196,11 @@ void main() {
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
liked: false,
|
liked: false,
|
||||||
saved: false,
|
saved: false,
|
||||||
|
visible: true,
|
||||||
|
boosting: false,
|
||||||
|
onTogglePlay: () {},
|
||||||
|
onBoostStart: () {},
|
||||||
|
onBoostEnd: () {},
|
||||||
onLike: () {},
|
onLike: () {},
|
||||||
onSave: () {},
|
onSave: () {},
|
||||||
onComments: () {},
|
onComments: () {},
|
||||||
@@ -196,7 +208,10 @@ void main() {
|
|||||||
onEpisodes: () {},
|
onEpisodes: () {},
|
||||||
onDetail: () {},
|
onDetail: () {},
|
||||||
onOpenFullPlayer: () => opened++,
|
onOpenFullPlayer: () => opened++,
|
||||||
onRefreshFeed: () => refreshed++,
|
onRefreshFeed: () async {
|
||||||
|
refreshed++;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
onDownload: () {},
|
onDownload: () {},
|
||||||
onClear: () {},
|
onClear: () {},
|
||||||
onSearch: () {},
|
onSearch: () {},
|
||||||
@@ -254,11 +269,11 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(
|
expect(
|
||||||
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
|
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
|
||||||
const Size(10, 10),
|
const Size(14, 14),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
tester.getSize(find.byKey(const Key('home-feed-progress-track'))).height,
|
tester.getSize(find.byKey(const Key('home-feed-progress-track'))).height,
|
||||||
4,
|
6,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
tester
|
tester
|
||||||
@@ -290,4 +305,75 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(opened, 1);
|
expect(opened, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('should_show_refresh_spinner_until_refresh_finishes', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final completer = Completer<bool>();
|
||||||
|
var calls = 0;
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: AppTheme.light(),
|
||||||
|
locale: const Locale('en'),
|
||||||
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
|
home: Builder(
|
||||||
|
builder: (context) => Scaffold(
|
||||||
|
body: HomeFeedOverlay(
|
||||||
|
l10n: AppLocalizations.of(context)!,
|
||||||
|
drama: const Drama(
|
||||||
|
id: 'refresh-drama',
|
||||||
|
title: 'Refresh Drama',
|
||||||
|
synopsis: 'synopsis',
|
||||||
|
posterUrl: '',
|
||||||
|
totalEpisodes: 8,
|
||||||
|
),
|
||||||
|
episode: const Episode(
|
||||||
|
id: 'refresh-episode',
|
||||||
|
number: 1,
|
||||||
|
title: 'Episode 1',
|
||||||
|
isFree: true,
|
||||||
|
),
|
||||||
|
controller: null,
|
||||||
|
liked: false,
|
||||||
|
saved: false,
|
||||||
|
visible: true,
|
||||||
|
boosting: false,
|
||||||
|
onTogglePlay: () {},
|
||||||
|
onBoostStart: () {},
|
||||||
|
onBoostEnd: () {},
|
||||||
|
onLike: () {},
|
||||||
|
onSave: () {},
|
||||||
|
onComments: () {},
|
||||||
|
onShare: () {},
|
||||||
|
onEpisodes: () {},
|
||||||
|
onDetail: () {},
|
||||||
|
onOpenFullPlayer: () {},
|
||||||
|
onRefreshFeed: () {
|
||||||
|
calls++;
|
||||||
|
return completer.future;
|
||||||
|
},
|
||||||
|
onDownload: () {},
|
||||||
|
onClear: () {},
|
||||||
|
onSearch: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.byKey(const Key('home-feed-refresh')));
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.byKey(const Key('home-feed-refreshing')), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byKey(const Key('home-feed-refresh')));
|
||||||
|
await tester.pump();
|
||||||
|
expect(calls, 1);
|
||||||
|
|
||||||
|
completer.complete(true);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byKey(const Key('home-feed-refreshing')), findsNothing);
|
||||||
|
expect(find.byIcon(Icons.refresh_rounded), findsOneWidget);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -118,10 +118,42 @@ void main() {
|
|||||||
.getRect(find.byKey(const Key('home-feed-series-meta')))
|
.getRect(find.byKey(const Key('home-feed-series-meta')))
|
||||||
.top;
|
.top;
|
||||||
|
|
||||||
expect(railTop, greaterThan(844 * 0.35));
|
expect(railTop, greaterThan(844 * 0.45));
|
||||||
expect(railBottom, lessThanOrEqualTo(infoTop));
|
expect(railBottom, lessThanOrEqualTo(infoTop));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('should_boost_feed_on_side_long_press', (tester) async {
|
||||||
|
await _pumpApp(tester);
|
||||||
|
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
||||||
|
|
||||||
|
final gesture = await tester.startGesture(const Offset(60, 300));
|
||||||
|
await tester.pump(const Duration(milliseconds: 700));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(find.byKey(const Key('home-feed-speed-boost-hint')), findsOneWidget);
|
||||||
|
expect(find.byKey(const Key('home-feed-full-series')), findsOneWidget);
|
||||||
|
expect(find.byKey(const Key('home-feed-title')), findsNothing);
|
||||||
|
expect(find.byKey(const Key('rail-save')), findsNothing);
|
||||||
|
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byKey(const Key('home-feed-speed-boost-hint')), findsNothing);
|
||||||
|
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
||||||
|
expect(find.byKey(const Key('rail-save')), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_open_more_sheet_on_center_long_press', (tester) async {
|
||||||
|
await _pumpApp(tester);
|
||||||
|
|
||||||
|
final gesture = await tester.startGesture(const Offset(195, 300));
|
||||||
|
await tester.pump(const Duration(milliseconds: 700));
|
||||||
|
await tester.pump();
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byKey(const Key('home-feed-clear')), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('should_restore_light_theme_after_leaving_feed_tab', (
|
testWidgets('should_restore_light_theme_after_leaving_feed_tab', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
|
|||||||
Reference in new issue
Block a user