From 37b119172bb2a25c90ad59b0fec464d27aa004e2 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 28 Nov 2022 13:26:43 +0800 Subject: [PATCH] feat: Customize Font Size In AppFlowy #1479 --- .../lib/plugins/doc/.document.dart.icloud | Bin 0 -> 161 bytes .../plugins/doc/.document_page.dart.icloud | Bin 0 -> 168 bytes .../plugins/doc/.editor_styles.dart.icloud | Bin 0 -> 168 bytes .../lib/plugins/doc/.styles.dart.icloud | Bin 0 -> 159 bytes .../presentation/more/font_size_switcher.dart | 77 +++++++++++------- .../presentation/more/more_button.dart | 12 ++- 6 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 frontend/app_flowy/lib/plugins/doc/.document.dart.icloud create mode 100644 frontend/app_flowy/lib/plugins/doc/.document_page.dart.icloud create mode 100644 frontend/app_flowy/lib/plugins/doc/.editor_styles.dart.icloud create mode 100644 frontend/app_flowy/lib/plugins/doc/.styles.dart.icloud diff --git a/frontend/app_flowy/lib/plugins/doc/.document.dart.icloud b/frontend/app_flowy/lib/plugins/doc/.document.dart.icloud new file mode 100644 index 0000000000000000000000000000000000000000..3dfd2ddd1aca4e3f372c6ee9a1099c917ec6f651 GIT binary patch literal 161 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QF*p&R_(%jU%61|kfq7p%=XYm3uSk(rlrkCa<7IE;)=zB#(Gk^gjBZOvP Jhte>r3II()ELi{m literal 0 HcmV?d00001 diff --git a/frontend/app_flowy/lib/plugins/doc/.document_page.dart.icloud b/frontend/app_flowy/lib/plugins/doc/.document_page.dart.icloud new file mode 100644 index 0000000000000000000000000000000000000000..373f78aca282714771d6fbff98eaabc4b0a75c44 GIT binary patch literal 168 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?4zfp_KgO(%jU%lK6te^i;i+#G(>Go=fopGFY_)rKXqWBo=Y-%jkQ>CozBl OBO`=nV29E$su2LP4lZl} literal 0 HcmV?d00001 diff --git a/frontend/app_flowy/lib/plugins/doc/.editor_styles.dart.icloud b/frontend/app_flowy/lib/plugins/doc/.editor_styles.dart.icloud new file mode 100644 index 0000000000000000000000000000000000000000..31095f5c0acadc7c7db54e6706d4c0ef0d42ede8 GIT binary patch literal 168 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?4zfq12SjlKi6h;*!do)MCAq#G(>G_6zX>GFY_)rKXqWBo=Y-%jkQ>CozBl OBO`=nV29E$su2Lb?k createState() => _FontSizeSwitcherState(); } class _FontSizeSwitcherState extends State { + final _selectedFontSizes = [false, true, false]; + final List> _fontSizes = [ + Tuple2(LocaleKeys.moreAction_small.tr(), 12.0), + Tuple2(LocaleKeys.moreAction_medium.tr(), 14.0), + Tuple2(LocaleKeys.moreAction_large.tr(), 18.0), + ]; + @override Widget build(BuildContext context) { return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - const FlowyText.semibold(LocaleKeys.moreAction_fontSize), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _buildFontSizeSwitchButton(LocaleKeys.moreAction_small, 12.0), - _buildFontSizeSwitchButton(LocaleKeys.moreAction_medium, 14.0), - _buildFontSizeSwitchButton(LocaleKeys.moreAction_large, 18.0), + FlowyText.semibold( + LocaleKeys.moreAction_fontSize.tr(), + fontSize: 12, + ), + const SizedBox( + height: 5, + ), + ToggleButtons( + isSelected: _selectedFontSizes, + onPressed: (int index) { + setState(() { + for (int i = 0; i < _selectedFontSizes.length; i++) { + _selectedFontSizes[i] = i == index; + } + context.read().fontSize = _fontSizes[index].item2; + }); + }, + borderRadius: const BorderRadius.all(Radius.circular(5)), + selectedBorderColor: Theme.of(context).colorScheme.primaryContainer, + selectedColor: Theme.of(context).colorScheme.onSurface, + fillColor: Theme.of(context).colorScheme.primaryContainer, + color: Theme.of(context).hintColor, + constraints: const BoxConstraints( + minHeight: 40.0, + minWidth: 80.0, + ), + children: const [ + Text( + 'small', + style: TextStyle(fontSize: 12), + ), + Text( + 'medium', + style: TextStyle(fontSize: 14), + ), + Text( + 'large', + style: TextStyle(fontSize: 18), + ) ], ) ], ); } - - Widget _buildFontSizeSwitchButton(String name, double fontSize) { - return Center( - child: TextButton( - onPressed: () { - final x = Provider.of(context, listen: false); - x; - Provider.of(context, listen: false).fontSize = - fontSize; - }, - child: Text( - name, - style: TextStyle(fontSize: fontSize), - ), - ), - ); - } } diff --git a/frontend/app_flowy/lib/plugins/document/presentation/more/more_button.dart b/frontend/app_flowy/lib/plugins/document/presentation/more/more_button.dart index fc70f78b5c..3ee0a867e0 100644 --- a/frontend/app_flowy/lib/plugins/document/presentation/more/more_button.dart +++ b/frontend/app_flowy/lib/plugins/document/presentation/more/more_button.dart @@ -1,6 +1,8 @@ +import 'package:app_flowy/plugins/document/document.dart'; import 'package:app_flowy/plugins/document/presentation/more/font_size_switcher.dart'; import 'package:flowy_infra/image.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class DocumentMoreButton extends StatelessWidget { const DocumentMoreButton({ @@ -13,14 +15,16 @@ class DocumentMoreButton extends StatelessWidget { @override Widget build(BuildContext context) { return PopupMenuButton( + offset: const Offset(0, 30), itemBuilder: (context) { return [ - const PopupMenuItem( + PopupMenuItem( value: 1, enabled: false, - child: FontSizeSwitcher( - // documentStyle: documentStyle, - ), + child: ChangeNotifierProvider.value( + value: context.read(), + child: const FontSizeSwitcher(), + ), ) ]; },