Compare commits

...

2 Commits

Author SHA1 Message Date
41c40dfbc4 feat: 热搜词跳转直播 2024-02-04 00:26:20 +08:00
5d9ecab1b0 mod: code format 2024-02-04 00:20:51 +08:00
6 changed files with 16 additions and 114 deletions

View File

@ -1,14 +1,8 @@
import 'package:hive/hive.dart';
part 'hot.g.dart';
@HiveType(typeId: 6)
class HotSearchModel {
HotSearchModel({
this.list,
});
@HiveField(0)
List<HotSearchItem>? list;
HotSearchModel.fromJson(Map<String, dynamic> json) {
@ -18,7 +12,6 @@ class HotSearchModel {
}
}
@HiveType(typeId: 7)
class HotSearchItem {
HotSearchItem({
this.keyword,
@ -27,20 +20,19 @@ class HotSearchItem {
this.icon,
});
@HiveField(0)
String? keyword;
@HiveField(1)
String? showName;
// 4/5热 11话题 8普通 7直播
@HiveField(2)
int? wordType;
@HiveField(3)
String? icon;
List? liveId;
HotSearchItem.fromJson(Map<String, dynamic> json) {
keyword = json['keyword'];
showName = json['show_name'];
wordType = json['word_type'];
icon = json['icon'];
liveId = json['live_id'];
liveId = json['live_id'];
}
}

View File

@ -1,84 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'hot.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class HotSearchModelAdapter extends TypeAdapter<HotSearchModel> {
@override
final int typeId = 6;
@override
HotSearchModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HotSearchModel(
list: (fields[0] as List?)?.cast<HotSearchItem>(),
);
}
@override
void write(BinaryWriter writer, HotSearchModel obj) {
writer
..writeByte(1)
..writeByte(0)
..write(obj.list);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HotSearchModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class HotSearchItemAdapter extends TypeAdapter<HotSearchItem> {
@override
final int typeId = 7;
@override
HotSearchItem read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HotSearchItem(
keyword: fields[0] as String?,
showName: fields[1] as String?,
wordType: fields[2] as int?,
icon: fields[3] as String?,
);
}
@override
void write(BinaryWriter writer, HotSearchItem obj) {
writer
..writeByte(4)
..writeByte(0)
..write(obj.keyword)
..writeByte(1)
..write(obj.showName)
..writeByte(2)
..write(obj.wordType)
..writeByte(3)
..write(obj.icon);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HotSearchItemAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -29,7 +29,7 @@ class SSearchController extends GetxController {
// 其他页面跳转过来
if (Get.parameters.keys.isNotEmpty) {
if (Get.parameters['keyword'] != null) {
onClickKeyword(Get.parameters['keyword']!);
onClickKeyword(Get.parameters['keyword']!, null);
}
if (Get.parameters['hintText'] != null) {
hintText = Get.parameters['hintText']!;
@ -88,7 +88,12 @@ class SSearchController extends GetxController {
}
// 点击热搜关键词
void onClickKeyword(String keyword) {
void onClickKeyword(String keyword, item) {
if (item != null && item.wordType == 7) {
Get.toNamed('/liveRoom?roomid=${item.liveId.first}',
arguments: {'liveItem': null, 'heroTag': '${item.liveId.first}'});
return;
}
searchKeyWord.value = keyword;
controller.value.text = keyword;
// 移动光标

View File

@ -115,8 +115,8 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
onTap: () => ssCtr
.onClickKeyword(ssCtr.searchSuggestList[index].term!),
onTap: () => ssCtr.onClickKeyword(
ssCtr.searchSuggestList[index].term!, null),
child: Padding(
padding: const EdgeInsets.only(left: 20, top: 9, bottom: 9),
child: ssCtr.searchSuggestList[index].textRich,
@ -178,11 +178,11 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
width: width,
// ignore: invalid_use_of_protected_member
hotSearchList: _searchController.hotSearchList.value,
onClick: (keyword) async {
onClick: (keyword, item) async {
_searchController.searchFocusNode.unfocus();
await Future.delayed(
const Duration(milliseconds: 150));
_searchController.onClickKeyword(keyword);
_searchController.onClickKeyword(keyword, item);
},
),
);
@ -193,15 +193,7 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
);
}
} else {
// 缓存数据
if (_searchController.hotSearchList.isNotEmpty) {
return HotKeyword(
width: width,
hotSearchList: _searchController.hotSearchList,
);
} else {
return const SizedBox();
}
return const SizedBox();
}
},
);

View File

@ -26,7 +26,7 @@ class HotKeyword extends StatelessWidget {
borderRadius: BorderRadius.circular(3),
clipBehavior: Clip.hardEdge,
child: InkWell(
onTap: () => onClick!(i.keyword),
onTap: () => onClick!(i.keyword, i),
child: Padding(
padding: EdgeInsets.only(
left: 2,

View File

@ -4,7 +4,6 @@ import 'dart:io';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pilipala/models/model_owner.dart';
import 'package:pilipala/models/search/hot.dart';
import 'package:pilipala/models/user/info.dart';
class GStrorage {
@ -48,8 +47,6 @@ class GStrorage {
Hive.registerAdapter(OwnerAdapter());
Hive.registerAdapter(UserInfoDataAdapter());
Hive.registerAdapter(LevelInfoAdapter());
Hive.registerAdapter(HotSearchModelAdapter());
Hive.registerAdapter(HotSearchItemAdapter());
}
static Future<void> lazyInit() async {