feat(player): 首页进详情与播放页改为淡入转场
This commit is contained in:
1 parent
3a636ca894
commit
8c04099d97
4 files changed
+72
-3
No files matched your search
@@ -0,0 +1,17 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// 无位移的短促淡入转场。
|
||||
class FadePageRoute<T> extends PageRouteBuilder<T> {
|
||||
FadePageRoute({required WidgetBuilder builder, super.settings})
|
||||
: super(
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
reverseTransitionDuration: const Duration(milliseconds: 180),
|
||||
pageBuilder: (context, _, _) => builder(context),
|
||||
transitionsBuilder: (context, animation, _, child) => FadeTransition(
|
||||
opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/navigation/fade_page_route.dart';
|
||||
import 'player_view.dart';
|
||||
|
||||
/// 目录卡片统一入口:补齐详情后直接进入全屏播放页。
|
||||
@@ -29,7 +30,7 @@ Future<void> playDramaFromCatalog(
|
||||
? 0
|
||||
: playable.episodes.indexWhere((episode) => episode.id == episodeId);
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
FadePageRoute<void>(
|
||||
builder: (_) => PlayerPage(
|
||||
drama: playable,
|
||||
initialIndex: index < 0 ? 0 : index,
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../../core/data/services/playback_session.dart';
|
||||
import '../../core/data/services/video_player_port.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/localized_content.dart';
|
||||
import '../../core/navigation/fade_page_route.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../discover/discover_types.dart';
|
||||
import '../discover/discover_view.dart';
|
||||
@@ -625,7 +626,7 @@ class PlayerLogic extends ChangeNotifier {
|
||||
try {
|
||||
if (!context.mounted) return;
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
FadePageRoute<void>(
|
||||
builder: (_) =>
|
||||
DramaDetailPage(drama: queue.entryAt(session.currentIndex).drama),
|
||||
),
|
||||
@@ -646,7 +647,7 @@ class PlayerLogic extends ChangeNotifier {
|
||||
await saveCurrentProgress();
|
||||
if (!context.mounted) return;
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
FadePageRoute<void>(
|
||||
builder: (_) => PlayerPage(
|
||||
drama: drama,
|
||||
initialIndex: index,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/navigation/fade_page_route.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('should_fade_in_without_slide_and_use_short_transitions', (
|
||||
tester,
|
||||
) async {
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
var routePushed = false;
|
||||
final route = FadePageRoute<void>(
|
||||
builder: (_) =>
|
||||
const Scaffold(key: Key('fade-route-page'), body: SizedBox.expand()),
|
||||
);
|
||||
|
||||
expect(route.transitionDuration, const Duration(milliseconds: 220));
|
||||
expect(route.reverseTransitionDuration, const Duration(milliseconds: 180));
|
||||
expect(route.opaque, isTrue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
navigatorKey: navigatorKey,
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () {
|
||||
navigatorKey.currentState!.push(route);
|
||||
routePushed = true;
|
||||
},
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(routePushed, isTrue);
|
||||
expect(find.byKey(const Key('fade-route-page')), findsOneWidget);
|
||||
final fade = tester.widget<FadeTransition>(
|
||||
find.byType(FadeTransition).last,
|
||||
);
|
||||
expect(fade.opacity.value, inExclusiveRange(0, 1));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user