Skip to content

Commit

Permalink
[*] improve ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed May 24, 2024
1 parent 7816f7c commit 669a435
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/pages/lyric.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../widgets/searchbar.dart';
import '../widgets/nodata.dart';
import '../models/lyric_controller.dart';
import '../models/player_controller.dart';
import '../models/playlist_controller.dart';
import '../src/rust/api/lyric.dart';

class LyricPage extends StatefulWidget {
Expand All @@ -18,15 +19,22 @@ class LyricPage extends StatefulWidget {
}

class _LyricPageState extends State<LyricPage> {
final TextEditingController _controllerSearch = TextEditingController();
final FocusNode _focusNodeSearch = FocusNode();
final TextEditingController controllerSearch = TextEditingController();
final FocusNode focusNodeSearch = FocusNode();
final lyricController = Get.find<SongLyricController>();
final playerController = Get.find<PlayerController>();
final playlistController = Get.find<PlaylistController>();
final isSearching = false.obs;

final downloadPath = Get.arguments["downloadPath"] as String;
final currentSongIndex = Get.arguments["currentSongIndex"] as int;

@override
void initState() {
super.initState();
controllerSearch.text = playlistController.playingSong().songName;
}

Future<void> search(String text) async {
lyricController.lyricList.clear();

Expand All @@ -35,7 +43,7 @@ class _LyricPageState extends State<LyricPage> {
return;
}

_focusNodeSearch.unfocus();
focusNodeSearch.unfocus();

isSearching.value = true;
var items = await searchLyric(keyword: text.trim());
Expand Down Expand Up @@ -168,8 +176,8 @@ class _LyricPageState extends State<LyricPage> {
const BoxConstraints(maxHeight: CTheme.searchBarHeight),
child: CSearchBar(
height: CTheme.searchBarHeight,
controller: _controllerSearch,
focusNode: _focusNodeSearch,
controller: controllerSearch,
focusNode: focusNodeSearch,
autofocus: lyricController.lyricList.isEmpty,
hintText: "请输入关键字".tr,
onSubmitted: (value) => search(value),
Expand All @@ -178,7 +186,7 @@ class _LyricPageState extends State<LyricPage> {
),
const SizedBox(width: CTheme.margin * 4),
GestureDetector(
onTap: () => search(_controllerSearch.text),
onTap: () => search(controllerSearch.text),
child: Text("搜索".tr, style: Theme.of(context).textTheme.bodyLarge),
),
],
Expand Down

0 comments on commit 669a435

Please sign in to comment.