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

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

View File

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