fix(flutter): 优化分类弧线与自动滚动
This commit is contained in:
1 parent
3041849344
commit
5af70c345a
2 files changed
+177
-63
No files matched your search
@@ -12,6 +12,7 @@ import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_pull_to_refresh.dart';
|
||||
import 'package:fruitshorts/pages/discover/discover_view.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
@@ -274,23 +275,54 @@ void main() {
|
||||
|
||||
testWidgets('should_show_category_underline_for_selection', (tester) async {
|
||||
await _pumpTheater(tester, categoryRepository: _GridCategoryRepository());
|
||||
Color underline(String id) =>
|
||||
(tester
|
||||
.widget<Container>(
|
||||
find.byKey(Key('theater-category-underline-$id')),
|
||||
)
|
||||
.decoration!
|
||||
as BoxDecoration)
|
||||
.color!;
|
||||
CategoryUnderlinePainter underline(String id) =>
|
||||
tester
|
||||
.widget<CustomPaint>(
|
||||
find.byKey(Key('theater-category-underline-$id')),
|
||||
)
|
||||
.painter!
|
||||
as CategoryUnderlinePainter;
|
||||
|
||||
expect(underline('all'), AppColors.blue);
|
||||
expect(underline('7'), Colors.transparent);
|
||||
expect(
|
||||
tester
|
||||
.widget<CustomPaint>(
|
||||
find.byKey(const Key('theater-category-underline-all')),
|
||||
)
|
||||
.size,
|
||||
const Size(20, 3),
|
||||
);
|
||||
expect(underline('all').color, AppColors.blue);
|
||||
expect(underline('7').color, Colors.transparent);
|
||||
|
||||
await tester.tap(find.byKey(const Key('theater-category-7')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(underline('all'), Colors.transparent);
|
||||
expect(underline('7'), AppColors.blue);
|
||||
expect(underline('all').color, Colors.transparent);
|
||||
expect(underline('7').color, AppColors.blue);
|
||||
});
|
||||
|
||||
testWidgets('should_scroll_offscreen_category_into_view_when_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
final categories = [
|
||||
for (var index = 0; index < 12; index++)
|
||||
ContentCategory(id: '$index', name: 'Long category $index'),
|
||||
];
|
||||
await _pumpTheater(
|
||||
tester,
|
||||
categoryRepository: _GridCategoryRepository(categories: categories),
|
||||
);
|
||||
|
||||
final target = find.byKey(const Key('theater-category-11'));
|
||||
expect(tester.getRect(target).right, greaterThan(390));
|
||||
|
||||
tester.widget<GestureDetector>(target).onTap!();
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final rect = tester.getRect(target);
|
||||
expect(rect.left, greaterThanOrEqualTo(0));
|
||||
expect(rect.right, lessThanOrEqualTo(390));
|
||||
});
|
||||
|
||||
testWidgets('should_use_text_pull_to_refresh', (tester) async {
|
||||
@@ -344,15 +376,16 @@ Future<void> _pumpTheater(
|
||||
}
|
||||
|
||||
class _GridCategoryRepository implements CategoryRepository {
|
||||
_GridCategoryRepository({HomeFeed? discoverFeed})
|
||||
: discoverFeed = discoverFeed ?? _defaultDiscoverFeed;
|
||||
_GridCategoryRepository({
|
||||
HomeFeed? discoverFeed,
|
||||
this.categories = const [ContentCategory(id: '7', name: 'Romance')],
|
||||
}) : discoverFeed = discoverFeed ?? _defaultDiscoverFeed;
|
||||
|
||||
final HomeFeed discoverFeed;
|
||||
final List<ContentCategory> categories;
|
||||
|
||||
@override
|
||||
Future<List<ContentCategory>> fetchCategories() async => const [
|
||||
ContentCategory(id: '7', name: 'Romance'),
|
||||
];
|
||||
Future<List<ContentCategory>> fetchCategories() async => categories;
|
||||
|
||||
@override
|
||||
Future<HomeFeed> fetchDiscoverFeed() async => discoverFeed;
|
||||
|
||||
Reference in new issue
Block a user