mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Update search
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import '../globals.dart';
|
||||
@@ -65,16 +64,35 @@ class HomeDrawer extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends HookWidget with IsTopWidget {
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
static const String routeName = '/';
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomePage();
|
||||
}
|
||||
|
||||
class _HomePage extends State<HomePage> with ThemeModeWidget, IsTopWidget2 {
|
||||
void _onStateChanged(dynamic _) {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
listener.on("meilisearch_enabled", _onStateChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
listener.removeEventListener("meilisearch_enabled", _onStateChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
tryInitApi(context);
|
||||
var mode = useState(MainApp.of(context).themeMode);
|
||||
mode.value = MainApp.of(context).themeMode;
|
||||
if (isTop(context)) {
|
||||
setCurrentTitle("", Theme.of(context).primaryColor.value,
|
||||
usePrefix: true);
|
||||
@@ -84,17 +102,7 @@ class HomePage extends HookWidget with IsTopWidget {
|
||||
title: Text(AppLocalizations.of(context)!.titleBar),
|
||||
actions: [
|
||||
buildSearchButton(context),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
final n = themeModeNext(mode.value);
|
||||
MainApp.of(context).changeThemeMode(n);
|
||||
mode.value = n;
|
||||
},
|
||||
icon: Icon(mode.value == ThemeMode.system
|
||||
? Icons.brightness_auto
|
||||
: mode.value == ThemeMode.dark
|
||||
? Icons.dark_mode
|
||||
: Icons.light_mode)),
|
||||
buildThemeModeIcon(context),
|
||||
buildMoreVertSettingsButon(context),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -94,6 +94,12 @@ class _SettingsPage extends State<SettingsPage>
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.search),
|
||||
title: Text(i18n.search),
|
||||
onTap: () {
|
||||
context.push("/settings/search");
|
||||
}),
|
||||
],
|
||||
));
|
||||
},
|
||||
|
||||
83
lib/pages/settings/search.dart
Normal file
83
lib/pages/settings/search.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import '../../components/alert_number_form_dialog.dart';
|
||||
import '../../globals.dart';
|
||||
|
||||
final _log = Logger("SearchSettingsPage");
|
||||
|
||||
class SearchSettingsPage extends StatefulWidget {
|
||||
const SearchSettingsPage({super.key});
|
||||
|
||||
static const String routeName = '/settings/search';
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _SearchSettingsPage();
|
||||
}
|
||||
|
||||
class _SearchSettingsPage extends State<SearchSettingsPage>
|
||||
with ThemeModeWidget, IsTopWidget2 {
|
||||
void _onStateChanged(dynamic _) {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
listener.on("settings_updated", _onStateChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
listener.removeEventListener("settings_updated", _onStateChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _buildMain(BuildContext context) {
|
||||
final i18n = AppLocalizations.of(context)!;
|
||||
return SingleChildScrollView(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
ListTile(
|
||||
title: Text(i18n.maxSearchSuggestions),
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertNumberFormDialog("maxSearchSuggestions",
|
||||
initial: 100,
|
||||
min: 1,
|
||||
max: 1000,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: i18n.maxSearchSuggestions,
|
||||
))),
|
||||
subtitle:
|
||||
Text((prefs.getInt("maxSearchSuggestions") ?? 100).toString()),
|
||||
)
|
||||
]));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final i18n = AppLocalizations.of(context)!;
|
||||
if (isTop(context)) {
|
||||
setCurrentTitle("${i18n.settings} - ${i18n.search}",
|
||||
Theme.of(context).primaryColor.value);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
context.canPop() ? context.pop() : context.go("/settings");
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
),
|
||||
title: Text(i18n.search),
|
||||
actions: [
|
||||
buildThemeModeIcon(context),
|
||||
buildMoreVertSettingsButon(context),
|
||||
],
|
||||
),
|
||||
body: _buildMain(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user