Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major update step 3 #1452

Merged
merged 5 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [7.7.0]

- **Breaking change**: We have mirgrated more buttons in the toolbar configurations, you can do change them in the `QuillProvider`
- Important bug fixes

## [7.6.1]

- Bug fixes
Expand Down
56 changes: 54 additions & 2 deletions lib/src/models/config/toolbar/buttons/base.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show VoidCallback, immutable;
import 'package:flutter/widgets.dart' show IconData, Widget;
import 'package:flutter/widgets.dart' show BuildContext, IconData, Widget;

import '../../../../../flutter_quill.dart' show QuillController, QuillProvider;
import '../../../themes/quill_icon_theme.dart' show QuillIconTheme;
import '../../quill_configurations.dart' show kDefaultIconSize;

@immutable
class QuillToolbarBaseButtonExtraOptions extends Equatable {
const QuillToolbarBaseButtonExtraOptions({
required this.controller,
required this.context,
required this.onPressed,
});

/// if you need the not null controller for some usage in the [childBuilder]
/// then please use this instead of the one in the [options]
final QuillController controller;

/// if the child builder you must use this when the widget tapped or pressed
/// in order to do what it expected to do
final VoidCallback? onPressed;

final BuildContext context;
@override
List<Object?> get props => [
controller,
];
}

/// The [T] is the options for the button, usually should refresnce itself
/// it's used in [childBuilder] so the developer can custmize this when using it
/// The [I] is extra options for the button, usually for it's state
Expand Down Expand Up @@ -41,10 +65,13 @@ class QuillToolbarBaseButtonOptions<T, I> extends Equatable {
final QuillIconTheme? iconTheme;

/// If you want to dispaly a differnet widget based using a builder
final Widget Function(T options, I extraOptions)? childBuilder;
final QuillToolbarButtonOptionsChildBuilder<T, I> childBuilder;

/// By default it will be from the one in [QuillProvider]
/// To override it you must pass not null controller
/// if you wish to use the controller in the [childBuilder], please use the
/// one from the extraOptions since it will be not null and will be the one
/// which will be used from the quill toolbar
final QuillController? controller;

@override
Expand All @@ -57,4 +84,29 @@ class QuillToolbarBaseButtonOptions<T, I> extends Equatable {
childBuilder,
controller,
];

// QuillToolbarBaseButtonOptions<T, I> copyWith({
// IconData? iconData,
// double? globalIconSize,
// VoidCallback? afterButtonPressed,
// String? tooltip,
// QuillIconTheme? iconTheme,
// Widget Function(T options, I extraOptions)? childBuilder,
// QuillController? controller,
// }) {
// return QuillToolbarBaseButtonOptions<T, I>(
// iconData: iconData ?? this.iconData,
// globalIconSize: globalIconSize ?? this.globalIconSize,
// afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed,
// tooltip: tooltip ?? this.tooltip,
// iconTheme: iconTheme ?? this.iconTheme,
// childBuilder: childBuilder ?? this.childBuilder,
// controller: controller ?? this.controller,
// );
// }
}

typedef QuillToolbarButtonOptionsChildBuilder<T, I> = Widget Function(
T options,
I extraOptions,
)?;
69 changes: 65 additions & 4 deletions lib/src/models/config/toolbar/buttons/font_family.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ import 'package:flutter/material.dart' show Colors, PopupMenuEntry;
import 'package:flutter/widgets.dart'
show
Color,
ValueChanged,
EdgeInsets,
EdgeInsetsGeometry,
IconData,
TextOverflow,
TextStyle,
EdgeInsets,
TextOverflow;
ValueChanged,
VoidCallback;

import '../../../../../flutter_quill.dart';

@immutable
class QuillToolbarFontFamilyButtonExtraOptions {
class QuillToolbarFontFamilyButtonExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarFontFamilyButtonExtraOptions({
required this.defaultDisplayText,
required this.currentValue,
required super.controller,
required super.context,
required super.onPressed,
});
final String defaultDisplayText;
final String currentValue;
Expand Down Expand Up @@ -76,4 +82,59 @@ class QuillToolbarFontFamilyButtonOptions extends QuillToolbarBaseButtonOptions<

/// By default will use [globalIconSize]
final double? iconSize;

QuillToolbarFontFamilyButtonOptions copyWith({
Color? fillColor,
double? hoverElevation,
double? highlightElevation,
List<PopupMenuEntry<String>>? items,
Map<String, String>? rawItemsMap,
ValueChanged<String>? onSelected,
Attribute? attribute,
EdgeInsetsGeometry? padding,
TextStyle? style,
double? width,
String? initialValue,
TextOverflow? labelOverflow,
bool? renderFontFamilies,
bool? overrideTooltipByFontFamily,
double? itemHeight,
EdgeInsets? itemPadding,
Color? defaultItemColor,
double? iconSize,
// Add properties to override inherited properties
QuillController? controller,
IconData? iconData,
VoidCallback? afterButtonPressed,
String? tooltip,
QuillIconTheme? iconTheme,
}) {
return QuillToolbarFontFamilyButtonOptions(
attribute: attribute ?? this.attribute,
rawItemsMap: rawItemsMap ?? this.rawItemsMap,
controller: controller ?? this.controller,
iconData: iconData ?? this.iconData,
afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed,
tooltip: tooltip ?? this.tooltip,
iconTheme: iconTheme ?? this.iconTheme,
onSelected: onSelected ?? this.onSelected,
padding: padding ?? this.padding,
style: style ?? this.style,
width: width ?? this.width,
initialValue: initialValue ?? this.initialValue,
labelOverflow: labelOverflow ?? this.labelOverflow,
renderFontFamilies: renderFontFamilies ?? this.renderFontFamilies,
overrideTooltipByFontFamily:
overrideTooltipByFontFamily ?? this.overrideTooltipByFontFamily,
itemHeight: itemHeight ?? this.itemHeight,
itemPadding: itemPadding ?? this.itemPadding,
defaultItemColor: defaultItemColor ?? this.defaultItemColor,
iconSize: iconSize ?? this.iconSize,
fillColor: fillColor ?? this.fillColor,
hoverElevation: hoverElevation ?? this.hoverElevation,
highlightElevation: highlightElevation ?? this.highlightElevation,
// ignore: deprecated_member_use_from_same_package
items: items ?? this.items,
);
}
}
94 changes: 74 additions & 20 deletions lib/src/models/config/toolbar/buttons/font_size.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import 'dart:ui';

import 'package:flutter/foundation.dart' show immutable;
import 'package:flutter/material.dart'
show Colors, PopupMenuEntry, ValueChanged;
import 'package:flutter/widgets.dart'
show
Color,
EdgeInsetsGeometry,
TextStyle,
VoidCallback,
TextOverflow,
EdgeInsets;
show Color, EdgeInsets, EdgeInsetsGeometry, TextOverflow, TextStyle;

import '../../../../widgets/controller.dart';
import '../../../documents/attribute.dart';
import '../../../themes/quill_icon_theme.dart';
import '../../quill_configurations.dart';

class QuillToolbarFontSizeButtonExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarFontSizeButtonExtraOptions({
required super.controller,
required this.currentValue,
required this.defaultDisplayText,
required super.context,
required super.onPressed,
});

final String currentValue;
final String defaultDisplayText;
}

@immutable
class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions {
class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions<
QuillToolbarFontSizeButtonOptions, QuillToolbarFontSizeButtonExtraOptions> {
const QuillToolbarFontSizeButtonOptions({
this.iconSize,
this.fillColor,
Expand All @@ -25,11 +36,11 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions {
this.items,
this.rawItemsMap,
this.onSelected,
this.iconTheme,
super.iconTheme,
this.attribute = Attribute.size,
this.controller,
this.afterButtonPressed,
this.tooltip,
super.controller,
super.afterButtonPressed,
super.tooltip,
this.padding,
this.style,
this.width,
Expand All @@ -38,6 +49,7 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions {
this.itemHeight,
this.itemPadding,
this.defaultItemColor = Colors.red,
super.childBuilder,
});

final double? iconSize;
Expand All @@ -46,17 +58,12 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions {
final double highlightElevation;
@Deprecated('It is not required because of `rawItemsMap`')
final List<PopupMenuEntry<String>>? items;

/// By default it will be [fontSizesValues] from [QuillToolbarConfigurations]
/// You can override this if you want
final Map<String, String>? rawItemsMap;
final ValueChanged<String>? onSelected;
@override
final QuillIconTheme? iconTheme;
final Attribute attribute;
@override
final QuillController? controller;
@override
final VoidCallback? afterButtonPressed;
@override
final String? tooltip;
final EdgeInsetsGeometry? padding;
final TextStyle? style;
final double? width;
Expand All @@ -65,4 +72,51 @@ class QuillToolbarFontSizeButtonOptions extends QuillToolbarBaseButtonOptions {
final double? itemHeight;
final EdgeInsets? itemPadding;
final Color? defaultItemColor;

QuillToolbarFontSizeButtonOptions copyWith({
double? iconSize,
Color? fillColor,
double? hoverElevation,
double? highlightElevation,
List<PopupMenuEntry<String>>? items,
Map<String, String>? rawItemsMap,
ValueChanged<String>? onSelected,
Attribute? attribute,
EdgeInsetsGeometry? padding,
TextStyle? style,
double? width,
String? initialValue,
TextOverflow? labelOverflow,
double? itemHeight,
EdgeInsets? itemPadding,
Color? defaultItemColor,
VoidCallback? afterButtonPressed,
String? tooltip,
QuillIconTheme? iconTheme,
QuillController? controller,
}) {
return QuillToolbarFontSizeButtonOptions(
iconSize: iconSize ?? this.iconSize,
fillColor: fillColor ?? this.fillColor,
hoverElevation: hoverElevation ?? this.hoverElevation,
highlightElevation: highlightElevation ?? this.highlightElevation,
// ignore: deprecated_member_use_from_same_package
items: items ?? this.items,
rawItemsMap: rawItemsMap ?? this.rawItemsMap,
onSelected: onSelected ?? this.onSelected,
attribute: attribute ?? this.attribute,
padding: padding ?? this.padding,
style: style ?? this.style,
width: width ?? this.width,
initialValue: initialValue ?? this.initialValue,
labelOverflow: labelOverflow ?? this.labelOverflow,
itemHeight: itemHeight ?? this.itemHeight,
itemPadding: itemPadding ?? this.itemPadding,
defaultItemColor: defaultItemColor ?? this.defaultItemColor,
tooltip: tooltip ?? super.tooltip,
iconTheme: iconTheme ?? super.iconTheme,
afterButtonPressed: afterButtonPressed ?? super.afterButtonPressed,
controller: controller ?? super.controller,
);
}
}
16 changes: 8 additions & 8 deletions lib/src/models/config/toolbar/buttons/history.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import 'package:flutter/foundation.dart' show VoidCallback, immutable;
import 'package:flutter/foundation.dart' show immutable;

import '../../../../../flutter_quill.dart';

@immutable
class HistoryButtonExtraOptions {
const HistoryButtonExtraOptions({
required this.onPressed,
class QuillToolbarHistoryButtonExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarHistoryButtonExtraOptions({
required this.canPressed,
required super.controller,
required super.context,
required super.onPressed,
});

/// When the button pressed
final VoidCallback onPressed;

/// If it can redo or undo
final bool canPressed;
}

@immutable
class QuillToolbarHistoryButtonOptions extends QuillToolbarBaseButtonOptions<
QuillToolbarHistoryButtonOptions, HistoryButtonExtraOptions> {
QuillToolbarHistoryButtonOptions, QuillToolbarHistoryButtonExtraOptions> {
const QuillToolbarHistoryButtonOptions({
required this.isUndo,
super.iconData,
Expand Down
27 changes: 22 additions & 5 deletions lib/src/models/config/toolbar/buttons/toggle_style.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import 'package:flutter/foundation.dart' show immutable;
import 'package:flutter/widgets.dart' show IconData;
import 'package:flutter/widgets.dart' show Color;

import 'base.dart';

class QuillToolbarToggleStyleButtonExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarToggleStyleButtonExtraOptions({
required super.controller,
required super.context,
required super.onPressed,
});
}

@immutable
class QuillToolbarToggleStyleButtonOptions
extends QuillToolbarBaseButtonOptions {
extends QuillToolbarBaseButtonOptions<QuillToolbarToggleStyleButtonOptions,
QuillToolbarToggleStyleButtonExtraOptions> {
const QuillToolbarToggleStyleButtonOptions({
required this.iconData,
super.iconData,
this.iconSize,
this.fillColor,
super.tooltip,
super.afterButtonPressed,
super.iconTheme,
super.childBuilder,
super.controller,
});

@override
final IconData iconData;
final double? iconSize;
final Color? fillColor;
}
Loading