Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: font size text being displayed out of range. (#3766)
Zakc0b0f12b0dab
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/more/font_size_switcher.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/more/font_size_switcher.dartindex 40328dc489..fd76b579f3 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/more/font_size_switcher.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/more/font_size_switcher.dart@@ -1,10 +1,13 @@+import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';+import 'package:collection/collection.dart';+import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra/theme_extension.dart';import 'package:flowy_infra_ui/style_widget/text.dart';import 'package:flutter/material.dart';-import 'package:appflowy/generated/locale_keys.g.dart';import 'package:flutter_bloc/flutter_bloc.dart';-import 'package:easy_localization/easy_localization.dart';++typedef _FontSizeSelection = (String, double, bool);class FontSizeSwitcher extends StatefulWidget {const FontSizeSwitcher({@@ -16,12 +19,21 @@ class FontSizeSwitcher extends StatefulWidget {}class _FontSizeSwitcherState extends State<FontSizeSwitcher> {- final List<(String, double, bool)> _fontSizes = [+ final List<_FontSizeSelection> _fontSizes = [(LocaleKeys.moreAction_small.tr(), 14.0, false),(LocaleKeys.moreAction_medium.tr(), 18.0, true),(LocaleKeys.moreAction_large.tr(), 22.0, false),];+ _FontSizeSelection? _selection;++ @override+ void initState() {+ super.initState();++ _selection = _fontSizes.firstWhereOrNull((element) => element.$3);+ }+@overrideWidget build(BuildContext context) {final selectedBgColor = AFThemeExtension.of(context).toggleButtonBGColor;@@ -39,34 +51,38 @@ class _FontSizeSwitcherState extends State<FontSizeSwitcher> {const SizedBox(height: 5,),- ToggleButtons(- isSelected:- _fontSizes.map((e) => e.$2 == state.fontSize).toList(),- onPressed: (int index) {- _updateSelectedFontSize(_fontSizes[index].$2);- },- color: foregroundColor,- borderRadius: const BorderRadius.all(Radius.circular(5)),- borderColor: foregroundColor,- borderWidth: 0.5,- // when selected- selectedColor: foregroundColor,- selectedBorderColor: foregroundColor,- fillColor: selectedBgColor,- // when hover- hoverColor: selectedBgColor.withOpacity(0.3),- constraints: const BoxConstraints(- minHeight: 40.0,- minWidth: 80.0,+ SegmentedButton<_FontSizeSelection>(+ showSelectedIcon: false,+ style: TextButton.styleFrom(+ foregroundColor: foregroundColor,+ shadowColor: selectedBgColor.withOpacity(0.3),+ padding: const EdgeInsets.all(16),+ side: BorderSide(+ width: 0.5,+ color: foregroundColor,+ ),+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(5),+ ),),- children: _fontSizes+ segments: _fontSizes.map(- (e) => Text(- e.$1,- style: TextStyle(fontSize: e.$2),+ (e) => ButtonSegment(+ value: e,+ label: FlowyText(+ e.$1,+ fontSize: e.$2,+ ),),).toList(),+ selected: {+ _selection ?? _fontSizes.first,+ },+ onSelectionChanged: (Set<(String, double, bool)> newSelection) {+ _selection = newSelection.firstOrNull;+ _updateSelectedFontSize(newSelection.first.$2);+ },),],);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/more/more_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/more/more_button.dartindex 5266d3f357..202e820bb5 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/more/more_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/more/more_button.dart@@ -3,6 +3,7 @@ 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/font_size_switcher.dart';import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';@@ -14,21 +15,9 @@ class DocumentMoreButton extends StatelessWidget {@overrideWidget build(BuildContext context) {- return PopupMenuButton<int>(- color: Theme.of(context).colorScheme.surfaceVariant,+ return AppFlowyPopover(+ constraints: const BoxConstraints(maxWidth: 400, maxHeight: 320),offset: const Offset(0, 30),- itemBuilder: (context) {- return [- PopupMenuItem(- value: 1,- enabled: false,- child: BlocProvider.value(- value: context.read<DocumentAppearanceCubit>(),- child: const FontSizeSwitcher(),- ),- ),- ];- },child: FlowyTooltip(message: LocaleKeys.moreAction_moreOptions.tr(),child: FlowySvg(@@ -37,6 +26,20 @@ class DocumentMoreButton extends StatelessWidget {color: Theme.of(context).iconTheme.color,),),+ popupBuilder: (context) {+ return Padding(+ padding: const EdgeInsets.all(8.0),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ BlocProvider.value(+ value: context.read<DocumentAppearanceCubit>(),+ child: const FontSizeSwitcher(),+ )+ ],+ ),+ );+ },);}}