|
@@ -1,8 +1,10 @@
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
|
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
|
|
|
+import 'package:appflowy/util/google_font_family_extension.dart';
|
|
import 'package:appflowy/workspace/application/appearance.dart';
|
|
import 'package:appflowy/workspace/application/appearance.dart';
|
|
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
|
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
|
|
|
+import 'package:appflowy_popover/appflowy_popover.dart';
|
|
import 'package:collection/collection.dart';
|
|
import 'package:collection/collection.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
@@ -29,9 +31,6 @@ class ThemeFontFamilySetting extends StatefulWidget {
|
|
}
|
|
}
|
|
|
|
|
|
class _ThemeFontFamilySettingState extends State<ThemeFontFamilySetting> {
|
|
class _ThemeFontFamilySettingState extends State<ThemeFontFamilySetting> {
|
|
- final List<String> availableFonts = GoogleFonts.asMap().keys.toList();
|
|
|
|
- final ValueNotifier<String> query = ValueNotifier('');
|
|
|
|
-
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
return ThemeSettingEntryTemplateWidget(
|
|
return ThemeSettingEntryTemplateWidget(
|
|
@@ -44,61 +43,101 @@ class _ThemeFontFamilySettingState extends State<ThemeFontFamilySetting> {
|
|
.syncFontFamily(DefaultAppearanceSettings.kDefaultFontFamily);
|
|
.syncFontFamily(DefaultAppearanceSettings.kDefaultFontFamily);
|
|
},
|
|
},
|
|
trailing: [
|
|
trailing: [
|
|
- ThemeValueDropDown(
|
|
|
|
- popoverKey: ThemeFontFamilySetting.popoverKey,
|
|
|
|
- currentValue: parseFontFamilyName(widget.currentFontFamily),
|
|
|
|
- onClose: () {
|
|
|
|
- query.value = '';
|
|
|
|
- },
|
|
|
|
- popupBuilder: (_) => CustomScrollView(
|
|
|
|
- shrinkWrap: true,
|
|
|
|
- slivers: [
|
|
|
|
- SliverPadding(
|
|
|
|
- padding: const EdgeInsets.only(right: 8),
|
|
|
|
- sliver: SliverToBoxAdapter(
|
|
|
|
- child: FlowyTextField(
|
|
|
|
- key: ThemeFontFamilySetting.textFieldKey,
|
|
|
|
- hintText:
|
|
|
|
- LocaleKeys.settings_appearance_fontFamily_search.tr(),
|
|
|
|
- autoFocus: false,
|
|
|
|
- debounceDuration: const Duration(milliseconds: 300),
|
|
|
|
- onChanged: (value) {
|
|
|
|
- query.value = value;
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
|
|
+ FontFamilyDropDown(
|
|
|
|
+ currentFontFamily: widget.currentFontFamily,
|
|
|
|
+ )
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class FontFamilyDropDown extends StatefulWidget {
|
|
|
|
+ const FontFamilyDropDown({
|
|
|
|
+ super.key,
|
|
|
|
+ required this.currentFontFamily,
|
|
|
|
+ this.onOpen,
|
|
|
|
+ this.onClose,
|
|
|
|
+ this.onFontFamilyChanged,
|
|
|
|
+ this.child,
|
|
|
|
+ this.popoverController,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ final String currentFontFamily;
|
|
|
|
+ final VoidCallback? onOpen;
|
|
|
|
+ final VoidCallback? onClose;
|
|
|
|
+ final void Function(String fontFamily)? onFontFamilyChanged;
|
|
|
|
+ final Widget? child;
|
|
|
|
+ final PopoverController? popoverController;
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ State<FontFamilyDropDown> createState() => _FontFamilyDropDownState();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class _FontFamilyDropDownState extends State<FontFamilyDropDown> {
|
|
|
|
+ final List<String> availableFonts = GoogleFonts.asMap().keys.toList();
|
|
|
|
+ final ValueNotifier<String> query = ValueNotifier('');
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ Widget build(BuildContext context) {
|
|
|
|
+ return ThemeValueDropDown(
|
|
|
|
+ popoverKey: ThemeFontFamilySetting.popoverKey,
|
|
|
|
+ popoverController: widget.popoverController,
|
|
|
|
+ currentValue: parseFontFamilyName(widget.currentFontFamily),
|
|
|
|
+ onClose: () {
|
|
|
|
+ query.value = '';
|
|
|
|
+ widget.onClose?.call();
|
|
|
|
+ },
|
|
|
|
+ child: widget.child,
|
|
|
|
+ popupBuilder: (_) {
|
|
|
|
+ widget.onOpen?.call();
|
|
|
|
+ return CustomScrollView(
|
|
|
|
+ shrinkWrap: true,
|
|
|
|
+ slivers: [
|
|
|
|
+ SliverPadding(
|
|
|
|
+ padding: const EdgeInsets.only(right: 8),
|
|
|
|
+ sliver: SliverToBoxAdapter(
|
|
|
|
+ child: FlowyTextField(
|
|
|
|
+ key: ThemeFontFamilySetting.textFieldKey,
|
|
|
|
+ hintText:
|
|
|
|
+ LocaleKeys.settings_appearance_fontFamily_search.tr(),
|
|
|
|
+ autoFocus: false,
|
|
|
|
+ debounceDuration: const Duration(milliseconds: 300),
|
|
|
|
+ onChanged: (value) {
|
|
|
|
+ query.value = value;
|
|
|
|
+ },
|
|
),
|
|
),
|
|
),
|
|
),
|
|
- const SliverToBoxAdapter(
|
|
|
|
- child: SizedBox(height: 4),
|
|
|
|
- ),
|
|
|
|
- ValueListenableBuilder(
|
|
|
|
- valueListenable: query,
|
|
|
|
- builder: (context, value, child) {
|
|
|
|
- var displayed = availableFonts;
|
|
|
|
- if (value.isNotEmpty) {
|
|
|
|
- displayed = availableFonts
|
|
|
|
- .where(
|
|
|
|
- (font) => font
|
|
|
|
- .toLowerCase()
|
|
|
|
- .contains(value.toLowerCase().toString()),
|
|
|
|
- )
|
|
|
|
- .sorted((a, b) => levenshtein(a, b))
|
|
|
|
- .toList();
|
|
|
|
- }
|
|
|
|
- return SliverFixedExtentList.builder(
|
|
|
|
- itemBuilder: (context, index) => _fontFamilyItemButton(
|
|
|
|
- context,
|
|
|
|
- GoogleFonts.getFont(displayed[index]),
|
|
|
|
- ),
|
|
|
|
- itemCount: displayed.length,
|
|
|
|
- itemExtent: 32,
|
|
|
|
- );
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
|
|
+ ),
|
|
|
|
+ const SliverToBoxAdapter(
|
|
|
|
+ child: SizedBox(height: 4),
|
|
|
|
+ ),
|
|
|
|
+ ValueListenableBuilder(
|
|
|
|
+ valueListenable: query,
|
|
|
|
+ builder: (context, value, child) {
|
|
|
|
+ var displayed = availableFonts;
|
|
|
|
+ if (value.isNotEmpty) {
|
|
|
|
+ displayed = availableFonts
|
|
|
|
+ .where(
|
|
|
|
+ (font) => font
|
|
|
|
+ .toLowerCase()
|
|
|
|
+ .contains(value.toLowerCase().toString()),
|
|
|
|
+ )
|
|
|
|
+ .sorted((a, b) => levenshtein(a, b))
|
|
|
|
+ .toList();
|
|
|
|
+ }
|
|
|
|
+ return SliverFixedExtentList.builder(
|
|
|
|
+ itemBuilder: (context, index) => _fontFamilyItemButton(
|
|
|
|
+ context,
|
|
|
|
+ GoogleFonts.getFont(displayed[index]),
|
|
|
|
+ ),
|
|
|
|
+ itemCount: displayed.length,
|
|
|
|
+ itemExtent: 32,
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
|
|
+ },
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -128,14 +167,17 @@ class _ThemeFontFamilySettingState extends State<ThemeFontFamilySetting> {
|
|
)
|
|
)
|
|
: null,
|
|
: null,
|
|
onTap: () {
|
|
onTap: () {
|
|
- if (parseFontFamilyName(widget.currentFontFamily) !=
|
|
|
|
- buttonFontFamily) {
|
|
|
|
- context
|
|
|
|
- .read<AppearanceSettingsCubit>()
|
|
|
|
- .setFontFamily(parseFontFamilyName(style.fontFamily!));
|
|
|
|
- context
|
|
|
|
- .read<DocumentAppearanceCubit>()
|
|
|
|
- .syncFontFamily(parseFontFamilyName(style.fontFamily!));
|
|
|
|
|
|
+ if (widget.onFontFamilyChanged != null) {
|
|
|
|
+ widget.onFontFamilyChanged!(style.fontFamily!);
|
|
|
|
+ } else {
|
|
|
|
+ final fontFamily = style.fontFamily!.parseFontFamilyName();
|
|
|
|
+ if (parseFontFamilyName(widget.currentFontFamily) !=
|
|
|
|
+ buttonFontFamily) {
|
|
|
|
+ context.read<AppearanceSettingsCubit>().setFontFamily(fontFamily);
|
|
|
|
+ context
|
|
|
|
+ .read<DocumentAppearanceCubit>()
|
|
|
|
+ .syncFontFamily(fontFamily);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
),
|
|
),
|