import 'package:flutter/material.dart'; import 'package:skywood/main/lib_file.dart'; import 'package:skywood/pages/search/page/result_page.dart'; import 'package:skywood/pages/search/widget/search_util.dart'; import 'package:skywood/pages/search/widget/search_view.dart'; import 'package:skywood/pages/widgets/pixel_widgets.dart'; import 'package:skywood/utils/tools/help_nav.dart'; import 'package:skywood/utils/tools/widgets/sky_app_bar.dart'; import 'package:skywood/utils/tools/widgets/sky_text_field.dart'; class SearchPage extends StatefulWidget { const SearchPage({super.key}); @override State createState() { return _MainRootState(); } } class _MainRootState extends State { List _searchHistory = []; final _searchController = TextEditingController(); final _searchFocus = FocusNode(); final List _titles = const [ "Mr. Gu's Sweet Weakness", 'Secret Wife with a Scar', 'A Second Chance at Love', 'Shadows of the Heart', 'Boarding Pass To Love', 'The Love Blueprint', 'Who Dared Touch My Bride', 'Famous Families Fled', ]; Future _loadSearchHistory() async { final list = await SearchUtil.getSearchList(); if (!mounted) return; setState(() { _searchHistory = list; }); } Future _onGoSearch(String keyword, {bool isTapKey = false}) async { if (isTapKey == true) { } else { await SearchUtil.addSearch(keyword); await _loadSearchHistory(); } HelpNav.to(ResultPage( keyword: keyword, )); // 发起 搜索 } @override void initState() { super.initState(); _loadSearchHistory(); } @override Widget build(BuildContext context) { return Scaffold( appBar: SkyAppBar( showBackButton: false, titleWidget: SkyTextField( controller: _searchController, focusNode: _searchFocus, border: Border.all(width: 0.6, color: CommonColor.black), borderRadius: BorderRadius.circular(20), width: 300, height: 36, placeholder: 'Search', prefix: HelpImg.asset(ConstImg.search, width: 14.w, height: 14.w), textInputAction: TextInputAction.search, onEditingComplete: () { print('object'); _searchFocus.unfocus(); if (_searchController.text.trim().isEmpty) return; _onGoSearch(_searchController.text); }, ), ), body: CustomScrollView( slivers: [ SliverToBoxAdapter(child: _buildHistory()), SliverToBoxAdapter(child: SizedBox(height: 30.h)), SliverToBoxAdapter(child: _buildTitle('Trending Now')), SliverToBoxAdapter(child: SizedBox(height: 10.h)), SliverToBoxAdapter(child: _buildTrendingList()), SliverToBoxAdapter(child: SizedBox(height: 20.h)), ], ), ); } Widget _buildHistory() { return SearchView( searchHistory: _searchHistory, onTapClear: () { _searchHistory.clear(); setState(() {}); }, onTapHistory: (value) { print('object: $value'); HelpNav.to(ResultPage(keyword: value)); }, ); } Widget _buildTitle(String title, {double fontSize = 18}) { return Padding( padding: EdgeInsets.symmetric(horizontal: 15.w), child: Text( title, style: TextStyle( color: CommonColor.black, fontSize: fontSize.sp, fontWeight: FontWeight.w700, height: 1.1, ), ), ); } Widget _buildTrendingList() { return SizedBox( height: 446.h, child: SingleChildScrollView( scrollDirection: Axis.horizontal, padding: EdgeInsets.symmetric(horizontal: 15.w), child: Wrap( direction: Axis.vertical, spacing: 10.h, runSpacing: 10.w, children: _titles .map((title) => _TrendingItem(title: title)) .toList(), ), ), ); } } class _TrendingItem extends StatelessWidget { const _TrendingItem({required this.title}); final String title; @override Widget build(BuildContext context) { return SizedBox( width: 236.w, height: 104.h, child: Row( children: [ const PosterImage( width: 80, height: 104, borderRadius: 4, showBorder: false, ), SizedBox(width: 8.w), Expanded( child: Padding( padding: EdgeInsets.symmetric(vertical: 10.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( title, maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle( color: CommonColor.black, fontSize: 13.sp, fontWeight: FontWeight.bold, height: 1.2, ), ), Row( children: [ HelpImg.asset(ConstImg.hot, width: 15.w, height: 15.w), SizedBox(width: 2.w), Text( '17.3K', style: TextStyle( color: const Color(0x80000000), fontSize: 13.w, height: 1, ), ), ], ), ], ), ), ), ], ), ); } }