Update header style

pull/1575/head
Aleksei 1 year ago
parent 8bba105170
commit cb77385ad5
  1. 42
      lib/src/l10n/generated/quill_localizations.dart
  2. 4
      lib/src/models/config/toolbar/buttons/dropdown_header_style.dart
  3. 12
      lib/src/models/documents/attribute.dart
  4. 85
      lib/src/widgets/default_styles.dart
  5. 36
      lib/src/widgets/toolbar/buttons/dropdown_header_style.dart

@ -636,6 +636,48 @@ abstract class FlutterQuillLocalizations {
/// In en, this message translates to: /// In en, this message translates to:
/// **'Paste a video using a link'** /// **'Paste a video using a link'**
String get pasteAVideoUsingALink; String get pasteAVideoUsingALink;
/// No description provided for @normal.
///
/// In en, this message translates to:
/// **'Normal'**
String get normal => 'Normal';
/// No description provided for @heading1.
///
/// In en, this message translates to:
/// **'Heading 1'**
String get heading1 => 'Heading 1';
/// No description provided for @heading2.
///
/// In en, this message translates to:
/// **'Heading 2'**
String get heading2 => 'Heading 2';
/// No description provided for @heading3.
///
/// In en, this message translates to:
/// **'Heading 3'**
String get heading3 => 'Heading 3';
/// No description provided for @heading4.
///
/// In en, this message translates to:
/// **'Heading 4'**
String get heading4 => 'Heading 4';
/// No description provided for @heading5.
///
/// In en, this message translates to:
/// **'Heading 5'**
String get heading5 => 'Heading 5';
/// No description provided for @heading6.
///
/// In en, this message translates to:
/// **'Heading 6'**
String get heading6 => 'Heading 6';
} }
class _FlutterQuillLocalizationsDelegate class _FlutterQuillLocalizationsDelegate

@ -32,7 +32,6 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
this.fillColor, this.fillColor,
this.hoverElevation = 1, this.hoverElevation = 1,
this.highlightElevation = 1, this.highlightElevation = 1,
this.rawItemsMap,
this.onSelected, this.onSelected,
this.attributes, this.attributes,
this.padding, this.padding,
@ -50,7 +49,6 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
final Color? fillColor; final Color? fillColor;
final double hoverElevation; final double hoverElevation;
final double highlightElevation; final double highlightElevation;
final Map<String, String>? rawItemsMap;
final ValueChanged<String>? onSelected; final ValueChanged<String>? onSelected;
final List<Attribute>? attributes; final List<Attribute>? attributes;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
@ -67,7 +65,6 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
double? hoverElevation, double? hoverElevation,
double? highlightElevation, double? highlightElevation,
List<PopupMenuEntry<String>>? items, List<PopupMenuEntry<String>>? items,
Map<String, String>? rawItemsMap,
ValueChanged<String>? onSelected, ValueChanged<String>? onSelected,
List<Attribute>? attributes, List<Attribute>? attributes,
EdgeInsetsGeometry? padding, EdgeInsetsGeometry? padding,
@ -91,7 +88,6 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
}) { }) {
return QuillToolbarSelectHeaderStyleDropdownButtonOptions( return QuillToolbarSelectHeaderStyleDropdownButtonOptions(
attributes: attributes ?? this.attributes, attributes: attributes ?? this.attributes,
rawItemsMap: rawItemsMap ?? this.rawItemsMap,
controller: controller ?? this.controller, controller: controller ?? this.controller,
iconData: iconData ?? this.iconData, iconData: iconData ?? this.iconData,
afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed, afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed,

@ -158,12 +158,24 @@ class Attribute<T> extends Equatable {
Attribute.video.key, Attribute.video.key,
}; };
/// "attributes":{"header": 1 }
static const Attribute<int?> h1 = HeaderAttribute(level: 1); static const Attribute<int?> h1 = HeaderAttribute(level: 1);
/// "attributes":{"header": 2 }
static const Attribute<int?> h2 = HeaderAttribute(level: 2); static const Attribute<int?> h2 = HeaderAttribute(level: 2);
/// "attributes":{"header": 3 }
static const Attribute<int?> h3 = HeaderAttribute(level: 3); static const Attribute<int?> h3 = HeaderAttribute(level: 3);
/// "attributes":{"header": 4 }
static const Attribute<int?> h4 = HeaderAttribute(level: 4);
/// "attributes":{"header": 5 }
static const Attribute<int?> h5 = HeaderAttribute(level: 5);
/// "attributes":{"header": 6 }
static const Attribute<int?> h6 = HeaderAttribute(level: 6);
// "attributes":{"align":"left"} // "attributes":{"align":"left"}
static const Attribute<String?> leftAlignment = AlignAttribute('left'); static const Attribute<String?> leftAlignment = AlignAttribute('left');

@ -144,6 +144,9 @@ class DefaultStyles {
this.h1, this.h1,
this.h2, this.h2,
this.h3, this.h3,
this.h4,
this.h5,
this.h6,
this.paragraph, this.paragraph,
this.bold, this.bold,
this.subscript, this.subscript,
@ -170,6 +173,9 @@ class DefaultStyles {
final DefaultTextBlockStyle? h1; final DefaultTextBlockStyle? h1;
final DefaultTextBlockStyle? h2; final DefaultTextBlockStyle? h2;
final DefaultTextBlockStyle? h3; final DefaultTextBlockStyle? h3;
final DefaultTextBlockStyle? h4;
final DefaultTextBlockStyle? h5;
final DefaultTextBlockStyle? h6;
final DefaultTextBlockStyle? paragraph; final DefaultTextBlockStyle? paragraph;
final TextStyle? bold; final TextStyle? bold;
final TextStyle? subscript; final TextStyle? subscript;
@ -220,9 +226,10 @@ class DefaultStyles {
h1: DefaultTextBlockStyle( h1: DefaultTextBlockStyle(
defaultTextStyle.style.copyWith( defaultTextStyle.style.copyWith(
fontSize: 34, fontSize: 34,
color: defaultTextStyle.style.color!.withOpacity(0.70), color: defaultTextStyle.style.color,
height: 1.15, letterSpacing: -1,
fontWeight: FontWeight.w300, height: 1,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none, decoration: TextDecoration.none,
), ),
const VerticalSpacing(16, 0), const VerticalSpacing(16, 0),
@ -230,37 +237,84 @@ class DefaultStyles {
null), null),
h2: DefaultTextBlockStyle( h2: DefaultTextBlockStyle(
defaultTextStyle.style.copyWith( defaultTextStyle.style.copyWith(
fontSize: 24, fontSize: 30,
color: defaultTextStyle.style.color!.withOpacity(0.70), color: defaultTextStyle.style.color,
height: 1.15, letterSpacing: -0.8,
fontWeight: FontWeight.normal, height: 1.067,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none, decoration: TextDecoration.none,
), ),
const VerticalSpacing(8, 0), const VerticalSpacing(8, 0),
const VerticalSpacing(0, 0), const VerticalSpacing(0, 0),
null), null),
h3: DefaultTextBlockStyle( h3: DefaultTextBlockStyle(
defaultTextStyle.style.copyWith(
fontSize: 24,
color: defaultTextStyle.style.color,
letterSpacing: -0.5,
height: 1.083,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none,
),
const VerticalSpacing(8, 0),
const VerticalSpacing(0, 0),
null,
),
h4: DefaultTextBlockStyle(
defaultTextStyle.style.copyWith( defaultTextStyle.style.copyWith(
fontSize: 20, fontSize: 20,
color: defaultTextStyle.style.color!.withOpacity(0.70), color: defaultTextStyle.style.color,
height: 1.25, letterSpacing: -0.4,
fontWeight: FontWeight.w500, height: 1.1,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none, decoration: TextDecoration.none,
), ),
const VerticalSpacing(8, 0), const VerticalSpacing(8, 0),
const VerticalSpacing(0, 0), const VerticalSpacing(0, 0),
null, null,
), ),
paragraph: DefaultTextBlockStyle(baseStyle, const VerticalSpacing(0, 0), h5: DefaultTextBlockStyle(
const VerticalSpacing(0, 0), null), defaultTextStyle.style.copyWith(
fontSize: 18,
color: defaultTextStyle.style.color,
letterSpacing: -0.2,
height: 1.11,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none,
),
const VerticalSpacing(8, 0),
const VerticalSpacing(0, 0),
null,
),
h6: DefaultTextBlockStyle(
defaultTextStyle.style.copyWith(
fontSize: 16,
color: defaultTextStyle.style.color,
letterSpacing: -0.1,
height: 1.125,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none,
),
const VerticalSpacing(8, 0),
const VerticalSpacing(0, 0),
null,
),
paragraph: DefaultTextBlockStyle(
baseStyle,
const VerticalSpacing(0, 0),
const VerticalSpacing(0, 0),
null,
),
bold: const TextStyle(fontWeight: FontWeight.bold), bold: const TextStyle(fontWeight: FontWeight.bold),
subscript: const TextStyle( subscript: const TextStyle(
fontFeatures: [ fontFeatures: [
FontFeature.liningFigures(),
FontFeature.subscripts(), FontFeature.subscripts(),
], ],
), ),
superscript: const TextStyle( superscript: const TextStyle(
fontFeatures: [ fontFeatures: [
FontFeature.liningFigures(),
FontFeature.superscripts(), FontFeature.superscripts(),
], ],
), ),
@ -274,9 +328,12 @@ class DefaultStyles {
style: inlineCodeStyle, style: inlineCodeStyle,
header1: inlineCodeStyle.copyWith( header1: inlineCodeStyle.copyWith(
fontSize: 32, fontSize: 32,
fontWeight: FontWeight.w300, fontWeight: FontWeight.w500,
),
header2: inlineCodeStyle.copyWith(
fontSize: 22,
fontWeight: FontWeight.w500,
), ),
header2: inlineCodeStyle.copyWith(fontSize: 22),
header3: inlineCodeStyle.copyWith( header3: inlineCodeStyle.copyWith(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,

@ -27,11 +27,14 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
Style get _selectionStyle => controller.getSelectionStyle(); Style get _selectionStyle => controller.getSelectionStyle();
final _valueToText = <Attribute, String>{ late final _valueToText = <Attribute, String>{
Attribute.header: 'Normal', Attribute.header: context.loc.normal,
Attribute.h1: 'H1', Attribute.h1: context.loc.heading1,
Attribute.h2: 'H2', Attribute.h2: context.loc.heading2,
Attribute.h3: 'H3', Attribute.h3: context.loc.heading3,
Attribute.h4: context.loc.heading4,
Attribute.h5: context.loc.heading5,
Attribute.h6: context.loc.heading6,
}; };
QuillToolbarSelectHeaderStyleDropdownButtonOptions get options { QuillToolbarSelectHeaderStyleDropdownButtonOptions get options {
@ -74,13 +77,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
} }
List<Attribute> get _attrbuites { List<Attribute> get _attrbuites {
return options.attributes ?? return options.attributes ?? _valueToText.keys.toList();
const [
Attribute.header,
Attribute.h1,
Attribute.h2,
Attribute.h3,
];
} }
@override @override
@ -103,18 +100,13 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_selectedAttribute = _getHeaderValue();
controller.addListener(_didChangeEditingValue); controller.addListener(_didChangeEditingValue);
_selectedAttribute = _getHeaderValue();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert( assert(_attrbuites.every((element) => _valueToText.keys.contains(element)));
_attrbuites.every(
(element) => _valueToText.keys.contains(element),
),
'All attributes must be one of them: header, h1, h2 or h3',
);
final baseButtonConfigurations = final baseButtonConfigurations =
context.requireQuillToolbarBaseButtonOptions; context.requireQuillToolbarBaseButtonOptions;
@ -189,7 +181,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
enabled: hasFinalWidth, enabled: hasFinalWidth,
wrapper: (child) => Expanded(child: child), wrapper: (child) => Expanded(child: child),
child: Text( child: Text(
_selectedAttribute!.key, _valueToText[_selectedAttribute]!,
overflow: options.labelOverflow, overflow: options.labelOverflow,
style: options.style ?? style: options.style ??
TextStyle( TextStyle(
@ -240,7 +232,9 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
child: Text( child: Text(
header.value, header.value,
style: TextStyle( style: TextStyle(
color: header.value == 'N' ? options.defaultItemColor : null, color: header.key == Attribute.header
? options.defaultItemColor
: null,
), ),
), ),
), ),

Loading…
Cancel
Save