mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
novel
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:pixes/appdata.dart';
|
||||
import 'package:pixes/components/loading.dart';
|
||||
import 'package:pixes/components/message.dart';
|
||||
import 'package:pixes/components/novel.dart';
|
||||
import 'package:pixes/components/page_route.dart';
|
||||
import 'package:pixes/components/user_preview.dart';
|
||||
import 'package:pixes/foundation/app.dart';
|
||||
@@ -39,11 +40,11 @@ class _SearchPageState extends State<SearchPage> {
|
||||
];
|
||||
|
||||
void search() {
|
||||
switch(searchType) {
|
||||
switch (searchType) {
|
||||
case 0:
|
||||
context.to(() => SearchResultPage(text));
|
||||
case 1:
|
||||
showToast(context, message: "Not implemented");
|
||||
context.to(() => SearchNovelResultPage(text));
|
||||
case 2:
|
||||
context.to(() => SearchUserResultPage(text));
|
||||
case 3:
|
||||
@@ -62,7 +63,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
content: Column(
|
||||
children: [
|
||||
buildSearchBar(),
|
||||
const SizedBox(height: 8,),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
const Expanded(
|
||||
child: _TrendingTagsView(),
|
||||
)
|
||||
@@ -130,7 +133,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4,),
|
||||
const SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
Button(
|
||||
child: const SizedBox(
|
||||
height: 42,
|
||||
@@ -139,7 +144,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(SideBarRoute(const SearchSettings()));
|
||||
Navigator.of(context).push(SideBarRoute(SearchSettings(
|
||||
isNovel: searchType == 1,
|
||||
)));
|
||||
},
|
||||
)
|
||||
],
|
||||
@@ -169,12 +176,13 @@ class _TrendingTagsView extends StatefulWidget {
|
||||
State<_TrendingTagsView> createState() => _TrendingTagsViewState();
|
||||
}
|
||||
|
||||
class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<TrendingTag>> {
|
||||
class _TrendingTagsViewState
|
||||
extends LoadingState<_TrendingTagsView, List<TrendingTag>> {
|
||||
@override
|
||||
Widget buildContent(BuildContext context, List<TrendingTag> data) {
|
||||
return MasonryGridView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0)
|
||||
+ EdgeInsets.only(bottom: context.padding.bottom),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0) +
|
||||
EdgeInsets.only(bottom: context.padding.bottom),
|
||||
gridDelegate: const SliverSimpleGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 240,
|
||||
),
|
||||
@@ -189,7 +197,7 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
|
||||
final illust = tag.illust;
|
||||
|
||||
var text = tag.tag.name;
|
||||
if(tag.tag.translatedName != null) {
|
||||
if (tag.tag.translatedName != null) {
|
||||
text += "/${tag.tag.translatedName}";
|
||||
}
|
||||
|
||||
@@ -206,18 +214,19 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: (){
|
||||
onTap: () {
|
||||
context.to(() => SearchResultPage(tag.tag.name));
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: ClipRRect(
|
||||
Positioned.fill(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4.0),
|
||||
child: AnimatedImage(
|
||||
image: CachedImageProvider(illust.images.first.medium),
|
||||
fit: BoxFit.cover,
|
||||
width: width-16.0,
|
||||
height: height-16.0,
|
||||
width: width - 16.0,
|
||||
height: height - 16.0,
|
||||
),
|
||||
)),
|
||||
Positioned(
|
||||
@@ -226,10 +235,14 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: FluentTheme.of(context).micaBackgroundColor.withOpacity(0.84),
|
||||
borderRadius: BorderRadius.circular(4)
|
||||
),
|
||||
child: Text(text).paddingHorizontal(4).paddingVertical(6).paddingBottom(2),
|
||||
color: FluentTheme.of(context)
|
||||
.micaBackgroundColor
|
||||
.withOpacity(0.84),
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
child: Text(text)
|
||||
.paddingHorizontal(4)
|
||||
.paddingVertical(6)
|
||||
.paddingBottom(2),
|
||||
),
|
||||
)
|
||||
],
|
||||
@@ -248,10 +261,12 @@ class _TrendingTagsViewState extends LoadingState<_TrendingTagsView, List<Trendi
|
||||
}
|
||||
|
||||
class SearchSettings extends StatefulWidget {
|
||||
const SearchSettings({this.onChanged, super.key});
|
||||
const SearchSettings({this.onChanged, this.isNovel = false, super.key});
|
||||
|
||||
final void Function()? onChanged;
|
||||
|
||||
final bool isNovel;
|
||||
|
||||
@override
|
||||
State<SearchSettings> createState() => _SearchSettingsState();
|
||||
}
|
||||
@@ -264,113 +279,139 @@ class _SearchSettingsState extends State<SearchSettings> {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||
child: Text("Search Settings".tl, style: const TextStyle(fontSize: 18),),
|
||||
child: Text(
|
||||
"Search Settings".tl,
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
).toAlign(Alignment.centerLeft),
|
||||
buildItem(title: "Match".tl, child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.matchType.toString().tl),
|
||||
items: KeywordMatchType.values.map((e) =>
|
||||
MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if(appdata.searchOptions.matchType != e) {
|
||||
setState(() => appdata.searchOptions.matchType = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}
|
||||
)
|
||||
).toList(),
|
||||
)),
|
||||
buildItem(title: "Favorite number".tl, child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.favoriteNumber.toString().tl),
|
||||
items: FavoriteNumber.values.map((e) =>
|
||||
MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if(appdata.searchOptions.favoriteNumber != e) {
|
||||
setState(() => appdata.searchOptions.favoriteNumber = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}
|
||||
)
|
||||
).toList(),
|
||||
)),
|
||||
buildItem(title: "Sort".tl, child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.sort.toString().tl),
|
||||
items: SearchSort.values.map((e) =>
|
||||
MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if(appdata.searchOptions.sort != e) {
|
||||
setState(() => appdata.searchOptions.sort = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}
|
||||
)
|
||||
).toList(),
|
||||
)),
|
||||
Card(
|
||||
padding: EdgeInsets.zero,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Start Time".tl, style: const TextStyle(fontSize: 16),)
|
||||
.paddingVertical(8)
|
||||
.toAlign(Alignment.centerLeft)
|
||||
.paddingLeft(16),
|
||||
DatePicker(
|
||||
selected: appdata.searchOptions.startTime,
|
||||
onChanged: (t) {
|
||||
if(appdata.searchOptions.startTime != t) {
|
||||
setState(() => appdata.searchOptions.startTime = t);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8,)
|
||||
],
|
||||
),
|
||||
)),
|
||||
Card(
|
||||
padding: EdgeInsets.zero,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Text("End Time".tl, style: const TextStyle(fontSize: 16),)
|
||||
.paddingVertical(8)
|
||||
.toAlign(Alignment.centerLeft)
|
||||
.paddingLeft(16),
|
||||
DatePicker(
|
||||
selected: appdata.searchOptions.endTime,
|
||||
onChanged: (t) {
|
||||
if(appdata.searchOptions.endTime != t) {
|
||||
setState(() => appdata.searchOptions.endTime = t);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8,)
|
||||
],
|
||||
),
|
||||
buildItem(
|
||||
title: "Match".tl,
|
||||
child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.matchType.toString().tl),
|
||||
items: KeywordMatchType.values
|
||||
.map((e) => MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if (appdata.searchOptions.matchType != e) {
|
||||
setState(() => appdata.searchOptions.matchType = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}))
|
||||
.toList(),
|
||||
)),
|
||||
buildItem(title: "Age limit".tl, child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.ageLimit.toString().tl),
|
||||
items: AgeLimit.values.map((e) =>
|
||||
MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if(appdata.searchOptions.ageLimit != e) {
|
||||
setState(() => appdata.searchOptions.ageLimit = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}
|
||||
)
|
||||
).toList(),
|
||||
)),
|
||||
SizedBox(height: context.padding.bottom,)
|
||||
if (!widget.isNovel)
|
||||
buildItem(
|
||||
title: "Favorite number".tl,
|
||||
child: DropDownButton(
|
||||
title:
|
||||
Text(appdata.searchOptions.favoriteNumber.toString().tl),
|
||||
items: FavoriteNumber.values
|
||||
.map((e) => MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if (appdata.searchOptions.favoriteNumber != e) {
|
||||
setState(() =>
|
||||
appdata.searchOptions.favoriteNumber = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}))
|
||||
.toList(),
|
||||
)),
|
||||
buildItem(
|
||||
title: "Sort".tl,
|
||||
child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.sort.toString().tl),
|
||||
items: SearchSort.values
|
||||
.map((e) => MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if (appdata.searchOptions.sort != e) {
|
||||
setState(() => appdata.searchOptions.sort = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}))
|
||||
.toList(),
|
||||
)),
|
||||
if (!widget.isNovel)
|
||||
Card(
|
||||
padding: EdgeInsets.zero,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"Start Time".tl,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
)
|
||||
.paddingVertical(8)
|
||||
.toAlign(Alignment.centerLeft)
|
||||
.paddingLeft(16),
|
||||
DatePicker(
|
||||
selected: appdata.searchOptions.startTime,
|
||||
onChanged: (t) {
|
||||
if (appdata.searchOptions.startTime != t) {
|
||||
setState(() => appdata.searchOptions.startTime = t);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
if (!widget.isNovel)
|
||||
Card(
|
||||
padding: EdgeInsets.zero,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"End Time".tl,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
)
|
||||
.paddingVertical(8)
|
||||
.toAlign(Alignment.centerLeft)
|
||||
.paddingLeft(16),
|
||||
DatePicker(
|
||||
selected: appdata.searchOptions.endTime,
|
||||
onChanged: (t) {
|
||||
if (appdata.searchOptions.endTime != t) {
|
||||
setState(() => appdata.searchOptions.endTime = t);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
if (!widget.isNovel)
|
||||
buildItem(
|
||||
title: "Age limit".tl,
|
||||
child: DropDownButton(
|
||||
title: Text(appdata.searchOptions.ageLimit.toString().tl),
|
||||
items: AgeLimit.values
|
||||
.map((e) => MenuFlyoutItem(
|
||||
text: Text(e.toString().tl),
|
||||
onPressed: () {
|
||||
if (appdata.searchOptions.ageLimit != e) {
|
||||
setState(
|
||||
() => appdata.searchOptions.ageLimit = e);
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}))
|
||||
.toList(),
|
||||
)),
|
||||
SizedBox(
|
||||
height: context.padding.bottom,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -388,7 +429,6 @@ class _SearchSettingsState extends State<SearchSettings> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SearchResultPage extends StatefulWidget {
|
||||
const SearchResultPage(this.keyword, {super.key});
|
||||
|
||||
@@ -398,7 +438,8 @@ class SearchResultPage extends StatefulWidget {
|
||||
State<SearchResultPage> createState() => _SearchResultPageState();
|
||||
}
|
||||
|
||||
class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Illust> {
|
||||
class _SearchResultPageState
|
||||
extends MultiPageLoadingState<SearchResultPage, Illust> {
|
||||
late String keyword = widget.keyword;
|
||||
|
||||
late String oldKeyword = widget.keyword;
|
||||
@@ -406,7 +447,7 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
||||
late final controller = TextEditingController(text: widget.keyword);
|
||||
|
||||
void search() {
|
||||
if(keyword != oldKeyword) {
|
||||
if (keyword != oldKeyword) {
|
||||
oldKeyword = keyword;
|
||||
reset();
|
||||
}
|
||||
@@ -423,21 +464,23 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if(index == data.length - 1){
|
||||
if (index == data.length - 1) {
|
||||
nextPage();
|
||||
}
|
||||
return IllustWidget(data[index], onTap: () {
|
||||
context.to(() => IllustGalleryPage(
|
||||
illusts: data,
|
||||
initialPage: index,
|
||||
nextUrl: nextUrl
|
||||
));
|
||||
},);
|
||||
return IllustWidget(
|
||||
data[index],
|
||||
onTap: () {
|
||||
context.to(() => IllustGalleryPage(
|
||||
illusts: data, initialPage: index, nextUrl: nextUrl));
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: data.length,
|
||||
),
|
||||
).sliverPaddingHorizontal(8),
|
||||
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom),)
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(bottom: context.padding.bottom),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -481,7 +524,9 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4,),
|
||||
const SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
Button(
|
||||
child: const SizedBox(
|
||||
height: 42,
|
||||
@@ -489,12 +534,13 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
||||
child: Icon(FluentIcons.settings),
|
||||
),
|
||||
),
|
||||
onPressed: () async{
|
||||
onPressed: () async {
|
||||
bool isChanged = false;
|
||||
await Navigator.of(context).push(
|
||||
SideBarRoute(SearchSettings(
|
||||
onChanged: () => isChanged = true,)));
|
||||
if(isChanged) {
|
||||
await Navigator.of(context)
|
||||
.push(SideBarRoute(SearchSettings(
|
||||
onChanged: () => isChanged = true,
|
||||
)));
|
||||
if (isChanged) {
|
||||
reset();
|
||||
}
|
||||
},
|
||||
@@ -513,14 +559,14 @@ class _SearchResultPageState extends MultiPageLoadingState<SearchResultPage, Ill
|
||||
String? nextUrl;
|
||||
|
||||
@override
|
||||
Future<Res<List<Illust>>> loadData(page) async{
|
||||
if(nextUrl == "end") {
|
||||
Future<Res<List<Illust>>> loadData(page) async {
|
||||
if (nextUrl == "end") {
|
||||
return Res.error("No more data");
|
||||
}
|
||||
var res = nextUrl == null
|
||||
? await Network().search(keyword, appdata.searchOptions)
|
||||
: await Network().getIllustsWithNextUrl(nextUrl!);
|
||||
if(!res.error) {
|
||||
if (!res.error) {
|
||||
nextUrl = res.subData;
|
||||
nextUrl ??= "end";
|
||||
}
|
||||
@@ -537,30 +583,31 @@ class SearchUserResultPage extends StatefulWidget {
|
||||
State<SearchUserResultPage> createState() => _SearchUserResultPageState();
|
||||
}
|
||||
|
||||
class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultPage, UserPreview> {
|
||||
class _SearchUserResultPageState
|
||||
extends MultiPageLoadingState<SearchUserResultPage, UserPreview> {
|
||||
@override
|
||||
Widget buildContent(BuildContext context, final List<UserPreview> data) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Text("${"Search".tl}: ${widget.keyword}",
|
||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),)
|
||||
.paddingVertical(12).paddingHorizontal(16),
|
||||
child: Text(
|
||||
"${"Search".tl}: ${widget.keyword}",
|
||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
|
||||
).paddingVertical(12).paddingHorizontal(16),
|
||||
),
|
||||
SliverGridViewWithFixedItemHeight(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if(index == data.length - 1){
|
||||
nextPage();
|
||||
}
|
||||
return UserPreviewWidget(data[index]);
|
||||
},
|
||||
childCount: data.length
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index == data.length - 1) {
|
||||
nextPage();
|
||||
}
|
||||
return UserPreviewWidget(data[index]);
|
||||
}, childCount: data.length),
|
||||
minCrossAxisExtent: 440,
|
||||
itemHeight: 136,
|
||||
).sliverPaddingHorizontal(8),
|
||||
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom),)
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(bottom: context.padding.bottom),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -568,12 +615,12 @@ class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultP
|
||||
String? nextUrl;
|
||||
|
||||
@override
|
||||
Future<Res<List<UserPreview>>> loadData(page) async{
|
||||
if(nextUrl == "end") {
|
||||
Future<Res<List<UserPreview>>> loadData(page) async {
|
||||
if (nextUrl == "end") {
|
||||
return Res.error("No more data");
|
||||
}
|
||||
var res = await Network().searchUsers(widget.keyword, nextUrl);
|
||||
if(!res.error) {
|
||||
if (!res.error) {
|
||||
nextUrl = res.subData;
|
||||
nextUrl ??= "end";
|
||||
}
|
||||
@@ -581,3 +628,141 @@ class _SearchUserResultPageState extends MultiPageLoadingState<SearchUserResultP
|
||||
}
|
||||
}
|
||||
|
||||
class SearchNovelResultPage extends StatefulWidget {
|
||||
const SearchNovelResultPage(this.keyword, {super.key});
|
||||
|
||||
final String keyword;
|
||||
|
||||
@override
|
||||
State<SearchNovelResultPage> createState() => _SearchNovelResultPageState();
|
||||
}
|
||||
|
||||
class _SearchNovelResultPageState
|
||||
extends MultiPageLoadingState<SearchNovelResultPage, Novel> {
|
||||
late String keyword = widget.keyword;
|
||||
|
||||
late String oldKeyword = widget.keyword;
|
||||
|
||||
late final controller = TextEditingController(text: widget.keyword);
|
||||
|
||||
void search() {
|
||||
if (keyword != oldKeyword) {
|
||||
oldKeyword = keyword;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildContent(BuildContext context, final List<Novel> data) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
buildSearchBar(),
|
||||
SliverGridViewWithFixedItemHeight(
|
||||
itemHeight: 164,
|
||||
minCrossAxisExtent: 400,
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == data.length - 1) {
|
||||
nextPage();
|
||||
}
|
||||
return NovelWidget(data[index]);
|
||||
},
|
||||
childCount: data.length,
|
||||
),
|
||||
).sliverPaddingHorizontal(8),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(bottom: context.padding.bottom),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildSearchBar() {
|
||||
return SliverToBoxAdapter(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
child: SizedBox(
|
||||
height: 42,
|
||||
width: double.infinity,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constrains) {
|
||||
return SizedBox(
|
||||
height: 42,
|
||||
width: constrains.maxWidth,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextBox(
|
||||
controller: controller,
|
||||
placeholder: "Search artworks".tl,
|
||||
onChanged: (s) => keyword = s,
|
||||
onSubmitted: (s) => search(),
|
||||
foregroundDecoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: ColorScheme.of(context)
|
||||
.outlineVariant
|
||||
.withOpacity(0.6)),
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
suffix: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: search,
|
||||
child: const Icon(
|
||||
FluentIcons.search,
|
||||
size: 16,
|
||||
).paddingHorizontal(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
Button(
|
||||
child: const SizedBox(
|
||||
height: 42,
|
||||
child: Center(
|
||||
child: Icon(FluentIcons.settings),
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
bool isChanged = false;
|
||||
await Navigator.of(context)
|
||||
.push(SideBarRoute(SearchSettings(
|
||||
onChanged: () => isChanged = true,
|
||||
isNovel: true,
|
||||
)));
|
||||
if (isChanged) {
|
||||
reset();
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
).paddingHorizontal(16),
|
||||
),
|
||||
),
|
||||
).sliverPadding(const EdgeInsets.only(top: 12));
|
||||
}
|
||||
|
||||
String? nextUrl;
|
||||
|
||||
@override
|
||||
Future<Res<List<Novel>>> loadData(page) async {
|
||||
if (nextUrl == "end") {
|
||||
return Res.error("No more data");
|
||||
}
|
||||
var res = nextUrl == null
|
||||
? await Network().searchNovels(keyword, appdata.searchOptions)
|
||||
: await Network().getNovelsWithNextUrl(nextUrl!);
|
||||
if (!res.error) {
|
||||
nextUrl = res.subData;
|
||||
nextUrl ??= "end";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user