Skip to content

Commit

Permalink
添加搜索类别的按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhoucheng133 committed Aug 26, 2024
1 parent f60ec3d commit d800d06
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/pages/components/search_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SearchBox extends SliverPersistentHeaderDelegate {

@override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
return false;
return true;
}

}
Expand All @@ -30,7 +30,8 @@ class SearchInput extends StatefulWidget {
final TextEditingController textController;
final FocusNode focus;
final VoidCallback search;
const SearchInput({super.key, required this.textController, required this.focus, required this.search});
final String mode;
const SearchInput({super.key, required this.textController, required this.focus, required this.search, required this.mode});

@override
State<SearchInput> createState() => _SearchInputState();
Expand Down Expand Up @@ -65,7 +66,7 @@ class _SearchInputState extends State<SearchInput> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'搜索歌曲,专辑或艺人',
'搜索${widget.mode=="song" ? "歌曲": widget.mode=="album" ? "专辑": "艺人"}',
style: GoogleFonts.notoSansSc(
color: Colors.grey,
),
Expand Down
91 changes: 91 additions & 0 deletions lib/pages/components/title_aria.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,95 @@ class _TitleAriaState extends State<TitleAria> {
),
);
}
}

class SearchTitleArea extends StatefulWidget {

final ValueChanged changeMode;
final String mode;

const SearchTitleArea({super.key, required this.mode, required this.changeMode});

@override
State<SearchTitleArea> createState() => _SearchTitleAreaState();
}

class _SearchTitleAreaState extends State<SearchTitleArea> {
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey[100]
),
child: Padding(
padding: const EdgeInsets.only(left: 30, bottom: 0, right: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'搜索',
style: GoogleFonts.notoSansSc(
fontWeight: FontWeight.w300,
color: Colors.black,
fontSize: 35
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(width: 10,),
IconButton(
onPressed: (){
if(widget.mode=='song'){
return;
}
widget.changeMode('song');
},
icon: Icon(
Icons.music_note_rounded,
color: widget.mode=='song' ? Colors.black : Colors.grey[300],
size: 30,
)
),
IconButton(
onPressed: (){
if(widget.mode=='album'){
return;
}
widget.changeMode('album');
},
icon: Icon(
Icons.album_rounded,
color: widget.mode=='album' ? Colors.black : Colors.grey[300],
size: 30,
)
),
IconButton(
onPressed: (){
if(widget.mode=='artist'){
return;
}
widget.changeMode('artist');
},
icon: Icon(
Icons.mic_rounded,
color: widget.mode=='artist' ? Colors.black : Colors.grey[300],
size: 30,
)
)
],
),
),
const SizedBox(height: 20,),
],
),
),
);
}
}
12 changes: 9 additions & 3 deletions lib/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class _SearchState extends State<Search> {
ScrollController controller=ScrollController();
bool showAppbarTitle=false;
List ls=[];
String mode='song';
void changeMode(val){
setState(() {
mode=val;
});
}

@override
void initState() {
Expand Down Expand Up @@ -53,14 +59,14 @@ class _SearchState extends State<Search> {
body: CustomScrollView(
controller: controller,
slivers: [
const SliverToBoxAdapter(
child: TitleAria(title: '搜索', subtitle: "")
SliverToBoxAdapter(
child: SearchTitleArea(mode: mode, changeMode: (val)=>changeMode(val))
),
SliverPersistentHeader(
pinned: true,
delegate: SearchBox(
(context)=>SearchInput(
textController: textController, focus: focus, search: (){},
textController: textController, focus: focus, search: (){}, mode: mode,
),
),
),
Expand Down

0 comments on commit d800d06

Please sign in to comment.