Skip to content

Commit

Permalink
Features🌍
Browse files Browse the repository at this point in the history
1. 🌍Title searching #13
  • Loading branch information
Cierra-Runis committed Aug 4, 2023
1 parent afa77b9 commit 5647c9f
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 42 deletions.
18 changes: 11 additions & 7 deletions lib/database/isar_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ class IsarService {

/// 创建 `Stream` 监听所有含有 `contains` 字符串的日记
Stream<List<Diary>> listenToDiariesContains(
String contains, {
DiarySearch diarySearch, {
int delayed = 300,
}) async* {
final isar = await _db;
await Future.delayed(Duration(milliseconds: delayed));
yield* isar.diarys
.filter()
.editingEqualTo(false)
.contentJsonStringContains(contains)
.sortByCreateDateTimeDesc()
.watch(fireImmediately: true);
QueryBuilder<Diary, Diary, QAfterFilterCondition> diaries =
isar.diarys.filter().editingEqualTo(false);

if (diarySearch.searchTitle) {
diaries = diaries.titleStringContains(diarySearch.text);
} else {
diaries = diaries.contentJsonStringContains(diarySearch.text);
}

yield* diaries.sortByCreateDateTimeDesc().watch(fireImmediately: true);
}

/// 创建 `Stream` 监听所有 `editing``true` 的日记
Expand Down
1 change: 1 addition & 0 deletions lib/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export 'package:photo_view/photo_view.dart'; // 图片视图
export 'package:pull_to_refresh/pull_to_refresh.dart'; // 下拉刷新
export 'package:qweather_icons/qweather_icons.dart'; // QWeather 图标
export 'package:share_plus/share_plus.dart'; // 分享
export 'package:star_menu/star_menu.dart'; // 浮动面板
export 'package:sticky_and_expandable_list/sticky_and_expandable_list.dart'; // 粘性头部与分组列表
export 'package:system_tray/system_tray.dart'; // 系统托盘
export 'package:syncfusion_flutter_charts/charts.dart'; // 图表
Expand Down
20 changes: 10 additions & 10 deletions lib/pages/mercurius/mercurius_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ class _MercuriusHomePageState extends ConsumerState<MercuriusHomePage> {
onPressed: _switchCurrentBarMode,
icon: const Icon(Icons.search),
),
title: GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (_) => windowManager.startDragging(),
onDoubleTap: windowManager.center,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
child: _searchBarMode
? const DiarySearchBarWidget()
: const MercuriusAppBarTitleWidget(),
),
title: AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
child: _searchBarMode
? const DiarySearchBarWidget()
: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanStart: (_) => windowManager.startDragging(),
onDoubleTap: windowManager.center,
child: const MercuriusAppBarTitleWidget(),
),
),
centerTitle: true,
actions: PlatformWindowsManager.getActions(),
Expand Down
32 changes: 27 additions & 5 deletions lib/states/diary/diary_search_text.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import 'package:mercurius/index.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'diary_search_text.g.dart';

@riverpod
class DiarySearchText extends _$DiarySearchText {
@override
String build() => '\\n';
DiarySearch build() => const DiarySearch();

void change([String? newString]) {
newString ??= '\\n';
state = newString == '' ? '\\n' : newString;
}
void change([DiarySearch? newDiarySearch]) =>
state = newDiarySearch ?? const DiarySearch();
}

@JsonSerializable()
class DiarySearch {
const DiarySearch({
this.text = '\\n',
this.searchTitle = false,
});
final String text;
final bool searchTitle;

DiarySearch copyWith({
String? text,
bool? searchTitle,
}) =>
DiarySearch(
text: text ?? this.text,
searchTitle: searchTitle ?? this.searchTitle,
);

factory DiarySearch.fromJson(Map<String, dynamic> json) =>
_$DiarySearchFromJson(json);
Map<String, dynamic> toJson() => _$DiarySearchToJson(this);
}
22 changes: 18 additions & 4 deletions lib/states/diary/diary_search_text.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/states/mercurius/current_position.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/states/mercurius/current_version.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/states/mercurius/github_latest_release.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/states/mercurius/mercurius_path.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/states/mercurius/qweather_now.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions lib/widgets/based/based_chip_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:mercurius/index.dart';

class BaseChipWidget extends StatelessWidget {
const BaseChipWidget({
super.key,
required this.label,
this.borderRadius = 8,
this.keepLeadingArea = true,
this.keepTracingArea = false,
this.labelLeadingSpacing = 4,
this.labelTracingSpacing = 4,
this.labelWidth,
this.labelColor,
this.fontWeight,
this.leadingIconData,
this.tracingIconData,
this.leadingIconColor,
this.tracingIconColor,
this.onTap,
});

final String label;
final double borderRadius;
final bool keepLeadingArea;
final bool keepTracingArea;
final double labelLeadingSpacing;
final double labelTracingSpacing;
final double? labelWidth;
final Color? labelColor;
final FontWeight? fontWeight;
final IconData? leadingIconData;
final Color? leadingIconColor;
final IconData? tracingIconData;
final Color? tracingIconColor;
final GestureTapCallback? onTap;

@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;

return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(borderRadius),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Wrap(
children: [
if (keepLeadingArea || leadingIconData != null)
Icon(
leadingIconData,
color: leadingIconColor ?? colorScheme.onSurface,
size: 20,
),
Padding(
padding: EdgeInsets.fromLTRB(
labelLeadingSpacing,
0,
labelTracingSpacing,
0,
),
child: SizedBox(
width: labelWidth,
child: Text(
label,
style: TextStyle(
color: labelColor,
fontWeight: fontWeight,
),
),
),
),
if (keepTracingArea || tracingIconData != null)
Icon(
tracingIconData,
color: tracingIconColor ?? colorScheme.onSurface,
size: 20,
),
],
),
),
),
);
}
}
1 change: 1 addition & 0 deletions lib/widgets/based/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'based_chip_widget.dart';
65 changes: 54 additions & 11 deletions lib/widgets/diary/diary_search_bar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,62 @@ class DiarySearchBarWidget extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final MercuriusL10N l10n = MercuriusL10N.of(context);
final ColorScheme colorScheme = Theme.of(context).colorScheme;

return SizedBox(
width: 160,
child: TextField(
autofocus: true,
textAlign: TextAlign.center,
onChanged: (value) =>
ref.watch(diarySearchTextProvider.notifier).change(value),
decoration: InputDecoration(
hintText: l10n.searchDiaryContent,
border: InputBorder.none,
return Row(
children: [
Expanded(
child: TextField(
autofocus: true,
textAlign: TextAlign.center,
onChanged: (value) =>
ref.watch(diarySearchTextProvider.notifier).change(
ref.watch(diarySearchTextProvider).copyWith(text: value),
),
decoration: InputDecoration(
hintText: l10n.searchDiaryContent,
border: InputBorder.none,
),
),
),
),
StarMenu(
params: StarMenuParameters.dropdown(context).copyWith(
boundaryBackground: BoundaryBackground(
blurSigmaX: 4,
blurSigmaY: 4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
color: colorScheme.outlineVariant.withAlpha(32),
),
),
linearShapeParams: const LinearShapeParams(
space: 4,
angle: -90,
),
centerOffset: const Offset(0, 40),
closeDurationMs: 200,
),
onItemTapped: (index, controller) => controller.closeMenu!(),
lazyItems: () async {
final diarySearch = ref.watch(diarySearchTextProvider);
return [
BaseChipWidget(
leadingIconData: diarySearch.searchTitle ? Icons.check : null,
label: '搜索标题',
onTap: () => ref.watch(diarySearchTextProvider.notifier).change(
diarySearch.copyWith(
searchTitle: !diarySearch.searchTitle,
),
),
),
];
},
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.expand_more_rounded),
),
),
],
);
}
}
1 change: 1 addition & 0 deletions lib/widgets/index.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'based/index.dart';
export 'diary/index.dart';
export 'dialog/index.dart';
export 'mercurius/index.dart';
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
star_menu:
dependency: "direct main"
description:
name: star_menu
sha256: "8c5de0b5002dd09bee51bc4456c3424ba81e127a2b0a2a6e7b775fdacaed2a61"
url: "https://pub.dev"
source: hosted
version: "3.1.4"
state_notifier:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies:
qweather_icons: ^0.0.11 # QWeather 图标 [https://pub.dev/packages/qweather_icons]
riverpod_annotation: ^2.1.1 # 状态管理相关 [https://pub.dev/packages/riverpod_annotation]
share_plus: ^7.0.2 # 分享 [https://pub.dev/packages/share_plus]
star_menu: ^3.1.4 # 浮动面板
sticky_and_expandable_list: ^1.1.2 # 粘性头部与分组列表 [https://pub.dev/packages/sticky_and_expandable_list]
system_tray: ^2.0.3 # 系统托盘 [https://pub.dev/packages/system_tray]
syncfusion_flutter_charts: ^22.1.39 # 图表 [https://pub.dev/packages/syncfusion_flutter_charts]
Expand Down

0 comments on commit 5647c9f

Please sign in to comment.