Shuffle post

This commit is contained in:
2025-08-22 01:41:25 +08:00
parent b4f2bb803a
commit bab602d98b
7 changed files with 70 additions and 7 deletions

View File

@@ -864,5 +864,6 @@
"mimeType": "MIME Type", "mimeType": "MIME Type",
"fileSize": "File Size", "fileSize": "File Size",
"fileHash": "File Hash", "fileHash": "File Hash",
"exifData": "EXIF Data" "exifData": "EXIF Data",
"postShuffle": "Shuffle Posts"
} }

View File

@@ -53,6 +53,7 @@ import 'package:island/screens/account/event_calendar.dart';
import 'package:island/screens/discovery/realms.dart'; import 'package:island/screens/discovery/realms.dart';
import 'package:island/screens/reports/report_detail.dart'; import 'package:island/screens/reports/report_detail.dart';
import 'package:island/screens/reports/report_list.dart'; import 'package:island/screens/reports/report_list.dart';
import 'package:island/widgets/post/post_shuffle.dart';
// Shell route keys for nested navigation // Shell route keys for nested navigation
final rootNavigatorKey = GlobalKey<NavigatorState>(); final rootNavigatorKey = GlobalKey<NavigatorState>();
@@ -376,6 +377,11 @@ final routerProvider = Provider<GoRouter>((ref) {
path: '/posts/search', path: '/posts/search',
builder: (context, state) => const PostSearchScreen(), builder: (context, state) => const PostSearchScreen(),
), ),
GoRoute(
name: 'postShuffle',
path: '/posts/shuffle',
builder: (context, state) => const PostShuffleScreen(),
),
GoRoute( GoRoute(
name: 'postCategories', name: 'postCategories',
path: '/posts/categories', path: '/posts/categories',

View File

@@ -200,6 +200,18 @@ class ExploreScreen extends HookConsumerWidget {
context.pushNamed('postTags'); context.pushNamed('postTags');
}, },
), ),
PopupMenuItem(
child: Row(
children: [
const Icon(Symbols.shuffle),
const Gap(12),
Text('postShuffle').tr(),
],
),
onTap: () {
context.pushNamed('postShuffle');
},
),
PopupMenuItem( PopupMenuItem(
child: Row( child: Row(
children: [ children: [

View File

@@ -145,7 +145,7 @@ class PostCategoriesListScreen extends ConsumerWidget {
final categoriesState = ref.watch(postCategoriesNotifierProvider); final categoriesState = ref.watch(postCategoriesNotifierProvider);
return AppScaffold( return AppScaffold(
appBar: AppBar(title: const Text('Categories')), appBar: AppBar(title: const Text('categories').tr()),
body: categoriesState.when( body: categoriesState.when(
data: (data) { data: (data) {
if (data.items.isEmpty) { if (data.items.isEmpty) {
@@ -197,7 +197,7 @@ class PostTagsListScreen extends ConsumerWidget {
final tagsState = ref.watch(postTagsNotifierProvider); final tagsState = ref.watch(postTagsNotifierProvider);
return AppScaffold( return AppScaffold(
appBar: AppBar(title: const Text('Tags')), appBar: AppBar(title: const Text('tags').tr()),
body: tagsState.when( body: tagsState.when(
data: (data) { data: (data) {
if (data.items.isEmpty) { if (data.items.isEmpty) {

View File

@@ -21,6 +21,7 @@ class PostListNotifier extends _$PostListNotifier
int? type, int? type,
List<String>? categories, List<String>? categories,
List<String>? tags, List<String>? tags,
bool shuffle = false,
}) { }) {
return fetch(cursor: null); return fetch(cursor: null);
} }
@@ -38,6 +39,7 @@ class PostListNotifier extends _$PostListNotifier
if (type != null) 'type': type, if (type != null) 'type': type,
if (tags != null) 'tags': tags, if (tags != null) 'tags': tags,
if (categories != null) 'categories': categories, if (categories != null) 'categories': categories,
if (shuffle) 'shuffle': true,
}; };
final response = await client.get( final response = await client.get(
@@ -74,6 +76,7 @@ class SliverPostList extends HookConsumerWidget {
final int? type; final int? type;
final List<String>? categories; final List<String>? categories;
final List<String>? tags; final List<String>? tags;
final bool shuffle;
final PostItemType itemType; final PostItemType itemType;
final Color? backgroundColor; final Color? backgroundColor;
final EdgeInsets? padding; final EdgeInsets? padding;
@@ -88,6 +91,7 @@ class SliverPostList extends HookConsumerWidget {
this.type, this.type,
this.categories, this.categories,
this.tags, this.tags,
this.shuffle = false,
this.itemType = PostItemType.regular, this.itemType = PostItemType.regular,
this.backgroundColor, this.backgroundColor,
this.padding, this.padding,
@@ -105,6 +109,7 @@ class SliverPostList extends HookConsumerWidget {
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
), ),
futureRefreshable: futureRefreshable:
postListNotifierProvider( postListNotifierProvider(
@@ -113,6 +118,7 @@ class SliverPostList extends HookConsumerWidget {
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
).future, ).future,
notifierRefreshable: notifierRefreshable:
postListNotifierProvider( postListNotifierProvider(
@@ -121,6 +127,7 @@ class SliverPostList extends HookConsumerWidget {
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
).notifier, ).notifier,
contentBuilder: contentBuilder:
(data, widgetCount, endItemView) => SliverList.builder( (data, widgetCount, endItemView) => SliverList.builder(

View File

@@ -6,7 +6,7 @@ part of 'post_list.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$postListNotifierHash() => r'9784b282b3ee14b7109e263c5841a082cf0be78e'; String _$postListNotifierHash() => r'27dc73b92a057b396e8ac026d4392508aedea4f5';
/// Copied from Dart SDK /// Copied from Dart SDK
class _SystemHash { class _SystemHash {
@@ -36,6 +36,7 @@ abstract class _$PostListNotifier
late final int? type; late final int? type;
late final List<String>? categories; late final List<String>? categories;
late final List<String>? tags; late final List<String>? tags;
late final bool shuffle;
FutureOr<CursorPagingData<SnPost>> build({ FutureOr<CursorPagingData<SnPost>> build({
String? pubName, String? pubName,
@@ -43,6 +44,7 @@ abstract class _$PostListNotifier
int? type, int? type,
List<String>? categories, List<String>? categories,
List<String>? tags, List<String>? tags,
bool shuffle = false,
}); });
} }
@@ -63,6 +65,7 @@ class PostListNotifierFamily
int? type, int? type,
List<String>? categories, List<String>? categories,
List<String>? tags, List<String>? tags,
bool shuffle = false,
}) { }) {
return PostListNotifierProvider( return PostListNotifierProvider(
pubName: pubName, pubName: pubName,
@@ -70,6 +73,7 @@ class PostListNotifierFamily
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
); );
} }
@@ -83,6 +87,7 @@ class PostListNotifierFamily
type: provider.type, type: provider.type,
categories: provider.categories, categories: provider.categories,
tags: provider.tags, tags: provider.tags,
shuffle: provider.shuffle,
); );
} }
@@ -115,6 +120,7 @@ class PostListNotifierProvider
int? type, int? type,
List<String>? categories, List<String>? categories,
List<String>? tags, List<String>? tags,
bool shuffle = false,
}) : this._internal( }) : this._internal(
() => () =>
PostListNotifier() PostListNotifier()
@@ -122,7 +128,8 @@ class PostListNotifierProvider
..realm = realm ..realm = realm
..type = type ..type = type
..categories = categories ..categories = categories
..tags = tags, ..tags = tags
..shuffle = shuffle,
from: postListNotifierProvider, from: postListNotifierProvider,
name: r'postListNotifierProvider', name: r'postListNotifierProvider',
debugGetCreateSourceHash: debugGetCreateSourceHash:
@@ -137,6 +144,7 @@ class PostListNotifierProvider
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
); );
PostListNotifierProvider._internal( PostListNotifierProvider._internal(
@@ -151,6 +159,7 @@ class PostListNotifierProvider
required this.type, required this.type,
required this.categories, required this.categories,
required this.tags, required this.tags,
required this.shuffle,
}) : super.internal(); }) : super.internal();
final String? pubName; final String? pubName;
@@ -158,6 +167,7 @@ class PostListNotifierProvider
final int? type; final int? type;
final List<String>? categories; final List<String>? categories;
final List<String>? tags; final List<String>? tags;
final bool shuffle;
@override @override
FutureOr<CursorPagingData<SnPost>> runNotifierBuild( FutureOr<CursorPagingData<SnPost>> runNotifierBuild(
@@ -169,6 +179,7 @@ class PostListNotifierProvider
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
); );
} }
@@ -183,7 +194,8 @@ class PostListNotifierProvider
..realm = realm ..realm = realm
..type = type ..type = type
..categories = categories ..categories = categories
..tags = tags, ..tags = tags
..shuffle = shuffle,
from: from, from: from,
name: null, name: null,
dependencies: null, dependencies: null,
@@ -194,6 +206,7 @@ class PostListNotifierProvider
type: type, type: type,
categories: categories, categories: categories,
tags: tags, tags: tags,
shuffle: shuffle,
), ),
); );
} }
@@ -214,7 +227,8 @@ class PostListNotifierProvider
other.realm == realm && other.realm == realm &&
other.type == type && other.type == type &&
other.categories == categories && other.categories == categories &&
other.tags == tags; other.tags == tags &&
other.shuffle == shuffle;
} }
@override @override
@@ -225,6 +239,7 @@ class PostListNotifierProvider
hash = _SystemHash.combine(hash, type.hashCode); hash = _SystemHash.combine(hash, type.hashCode);
hash = _SystemHash.combine(hash, categories.hashCode); hash = _SystemHash.combine(hash, categories.hashCode);
hash = _SystemHash.combine(hash, tags.hashCode); hash = _SystemHash.combine(hash, tags.hashCode);
hash = _SystemHash.combine(hash, shuffle.hashCode);
return _SystemHash.finish(hash); return _SystemHash.finish(hash);
} }
@@ -248,6 +263,9 @@ mixin PostListNotifierRef
/// The parameter `tags` of this provider. /// The parameter `tags` of this provider.
List<String>? get tags; List<String>? get tags;
/// The parameter `shuffle` of this provider.
bool get shuffle;
} }
class _PostListNotifierProviderElement class _PostListNotifierProviderElement
@@ -270,6 +288,8 @@ class _PostListNotifierProviderElement
(origin as PostListNotifierProvider).categories; (origin as PostListNotifierProvider).categories;
@override @override
List<String>? get tags => (origin as PostListNotifierProvider).tags; List<String>? get tags => (origin as PostListNotifierProvider).tags;
@override
bool get shuffle => (origin as PostListNotifierProvider).shuffle;
} }
// ignore_for_file: type=lint // ignore_for_file: type=lint

View File

@@ -0,0 +1,17 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/widgets/app_scaffold.dart';
import 'package:island/widgets/post/post_list.dart';
class PostShuffleScreen extends HookConsumerWidget {
const PostShuffleScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return AppScaffold(
appBar: AppBar(title: const Text('postShuffle').tr()),
body: CustomScrollView(slivers: [SliverPostList(shuffle: true)]),
);
}
}