pull/1566/head
parent
0d39d9d4e9
commit
d67bd71ca4
9 changed files with 271 additions and 279 deletions
@ -1,283 +1,283 @@ |
|||||||
import 'package:flutter/foundation.dart'; |
// import 'package:flutter/foundation.dart'; |
||||||
import 'package:flutter/material.dart'; |
// import 'package:flutter/material.dart'; |
||||||
|
|
||||||
import '../../../extensions/quill_provider.dart'; |
// import '../../../extensions/quill_provider.dart'; |
||||||
import '../../../l10n/extensions/localizations.dart'; |
// import '../../../l10n/extensions/localizations.dart'; |
||||||
import '../../../models/documents/attribute.dart'; |
// import '../../../models/documents/attribute.dart'; |
||||||
import '../../../models/documents/style.dart'; |
// import '../../../models/documents/style.dart'; |
||||||
import '../../../models/themes/quill_icon_theme.dart'; |
// import '../../../models/themes/quill_icon_theme.dart'; |
||||||
import '../../../utils/widgets.dart'; |
// import '../../../utils/widgets.dart'; |
||||||
import '../../others/controller.dart'; |
// import '../../others/controller.dart'; |
||||||
import '../base_toolbar.dart'; |
// import '../base_toolbar.dart'; |
||||||
|
|
||||||
@Deprecated('This button has been deprecated, use') |
// @Deprecated('This button has been deprecated, use') |
||||||
class QuillToolbarSelectAlignmentOldButtons extends StatefulWidget { |
// class QuillToolbarSelectAlignmentOldButtons extends StatefulWidget { |
||||||
const QuillToolbarSelectAlignmentOldButtons({ |
// const QuillToolbarSelectAlignmentOldButtons({ |
||||||
required this.controller, |
// required this.controller, |
||||||
required this.options, |
// required this.options, |
||||||
this.showLeftAlignment, |
// this.showLeftAlignment, |
||||||
this.showCenterAlignment, |
// this.showCenterAlignment, |
||||||
this.showRightAlignment, |
// this.showRightAlignment, |
||||||
this.showJustifyAlignment, |
// this.showJustifyAlignment, |
||||||
this.padding, |
// this.padding, |
||||||
super.key, |
// super.key, |
||||||
}); |
// }); |
||||||
|
|
||||||
final QuillController controller; |
// final QuillController controller; |
||||||
final QuillToolbarSelectAlignmentButtonOptions options; |
// final QuillToolbarSelectAlignmentButtonOptions options; |
||||||
|
|
||||||
final bool? showLeftAlignment; |
// final bool? showLeftAlignment; |
||||||
final bool? showCenterAlignment; |
// final bool? showCenterAlignment; |
||||||
final bool? showRightAlignment; |
// final bool? showRightAlignment; |
||||||
final bool? showJustifyAlignment; |
// final bool? showJustifyAlignment; |
||||||
final EdgeInsetsGeometry? padding; |
// final EdgeInsetsGeometry? padding; |
||||||
|
|
||||||
@override |
// @override |
||||||
QuillToolbarSelectAlignmentOldButtonsState createState() => |
// QuillToolbarSelectAlignmentOldButtonsState createState() => |
||||||
QuillToolbarSelectAlignmentOldButtonsState(); |
// QuillToolbarSelectAlignmentOldButtonsState(); |
||||||
} |
// } |
||||||
|
|
||||||
class QuillToolbarSelectAlignmentOldButtonsState |
// class QuillToolbarSelectAlignmentOldButtonsState |
||||||
extends State<QuillToolbarSelectAlignmentOldButtons> { |
// extends State<QuillToolbarSelectAlignmentOldButtons> { |
||||||
Attribute? _value; |
// Attribute? _value; |
||||||
|
|
||||||
Style get _selectionStyle => controller.getSelectionStyle(); |
// Style get _selectionStyle => controller.getSelectionStyle(); |
||||||
|
|
||||||
@override |
// @override |
||||||
void initState() { |
// void initState() { |
||||||
super.initState(); |
// super.initState(); |
||||||
setState(() { |
// setState(() { |
||||||
_value = _selectionStyle.attributes[Attribute.align.key] ?? |
// _value = _selectionStyle.attributes[Attribute.align.key] ?? |
||||||
Attribute.leftAlignment; |
// Attribute.leftAlignment; |
||||||
}); |
// }); |
||||||
controller.addListener(_didChangeEditingValue); |
// controller.addListener(_didChangeEditingValue); |
||||||
} |
// } |
||||||
|
|
||||||
QuillToolbarSelectAlignmentButtonOptions get options { |
// QuillToolbarSelectAlignmentButtonOptions get options { |
||||||
return widget.options; |
// return widget.options; |
||||||
} |
// } |
||||||
|
|
||||||
QuillController get controller { |
// QuillController get controller { |
||||||
return widget.controller; |
// return widget.controller; |
||||||
} |
// } |
||||||
|
|
||||||
double get _iconSize { |
// double get _iconSize { |
||||||
final baseFontSize = baseButtonExtraOptions.globalIconSize; |
// final baseFontSize = baseButtonExtraOptions.globalIconSize; |
||||||
final iconSize = options.iconSize; |
// final iconSize = options.iconSize; |
||||||
return iconSize ?? baseFontSize; |
// return iconSize ?? baseFontSize; |
||||||
} |
// } |
||||||
|
|
||||||
double get _iconButtonFactor { |
// double get _iconButtonFactor { |
||||||
final baseIconFactor = baseButtonExtraOptions.globalIconButtonFactor; |
// final baseIconFactor = baseButtonExtraOptions.globalIconButtonFactor; |
||||||
final iconButtonFactor = options.iconButtonFactor; |
// final iconButtonFactor = options.iconButtonFactor; |
||||||
return iconButtonFactor ?? baseIconFactor; |
// return iconButtonFactor ?? baseIconFactor; |
||||||
} |
// } |
||||||
|
|
||||||
VoidCallback? get _afterButtonPressed { |
// VoidCallback? get _afterButtonPressed { |
||||||
return options.afterButtonPressed ?? |
// return options.afterButtonPressed ?? |
||||||
baseButtonExtraOptions.afterButtonPressed; |
// baseButtonExtraOptions.afterButtonPressed; |
||||||
} |
// } |
||||||
|
|
||||||
QuillIconTheme? get _iconTheme { |
// QuillIconTheme? get _iconTheme { |
||||||
return options.iconTheme ?? baseButtonExtraOptions.iconTheme; |
// return options.iconTheme ?? baseButtonExtraOptions.iconTheme; |
||||||
} |
// } |
||||||
|
|
||||||
QuillToolbarBaseButtonOptions get baseButtonExtraOptions { |
// QuillToolbarBaseButtonOptions get baseButtonExtraOptions { |
||||||
return context.requireQuillToolbarBaseButtonOptions; |
// return context.requireQuillToolbarBaseButtonOptions; |
||||||
} |
// } |
||||||
|
|
||||||
QuillSelectAlignmentValues<IconData> get _iconsData { |
// QuillSelectAlignmentValues<IconData> get _iconsData { |
||||||
final iconsData = options.iconsData; |
// final iconsData = options.iconsData; |
||||||
if (iconsData != null) { |
// if (iconsData != null) { |
||||||
return iconsData; |
// return iconsData; |
||||||
} |
// } |
||||||
final baseIconData = baseButtonExtraOptions.iconData; |
// final baseIconData = baseButtonExtraOptions.iconData; |
||||||
if (baseIconData != null) { |
// if (baseIconData != null) { |
||||||
return QuillSelectAlignmentValues( |
// return QuillSelectAlignmentValues( |
||||||
leftAlignment: baseIconData, |
// leftAlignment: baseIconData, |
||||||
centerAlignment: baseIconData, |
// centerAlignment: baseIconData, |
||||||
rightAlignment: baseIconData, |
// rightAlignment: baseIconData, |
||||||
justifyAlignment: baseIconData, |
// justifyAlignment: baseIconData, |
||||||
); |
// ); |
||||||
} |
// } |
||||||
return const QuillSelectAlignmentValues( |
// return const QuillSelectAlignmentValues( |
||||||
leftAlignment: Icons.format_align_left, |
// leftAlignment: Icons.format_align_left, |
||||||
centerAlignment: Icons.format_align_center, |
// centerAlignment: Icons.format_align_center, |
||||||
rightAlignment: Icons.format_align_right, |
// rightAlignment: Icons.format_align_right, |
||||||
justifyAlignment: Icons.format_align_justify, |
// justifyAlignment: Icons.format_align_justify, |
||||||
); |
// ); |
||||||
} |
// } |
||||||
|
|
||||||
QuillSelectAlignmentValues<String> get _tooltips { |
// QuillSelectAlignmentValues<String> get _tooltips { |
||||||
final tooltips = options.tooltips; |
// final tooltips = options.tooltips; |
||||||
if (tooltips != null) { |
// if (tooltips != null) { |
||||||
return tooltips; |
// return tooltips; |
||||||
} |
// } |
||||||
final baseToolTip = baseButtonExtraOptions.tooltip; |
// final baseToolTip = baseButtonExtraOptions.tooltip; |
||||||
if (baseToolTip != null) { |
// if (baseToolTip != null) { |
||||||
return QuillSelectAlignmentValues( |
// return QuillSelectAlignmentValues( |
||||||
leftAlignment: baseToolTip, |
// leftAlignment: baseToolTip, |
||||||
centerAlignment: baseToolTip, |
// centerAlignment: baseToolTip, |
||||||
rightAlignment: baseToolTip, |
// rightAlignment: baseToolTip, |
||||||
justifyAlignment: baseToolTip, |
// justifyAlignment: baseToolTip, |
||||||
); |
// ); |
||||||
} |
// } |
||||||
return QuillSelectAlignmentValues( |
// return QuillSelectAlignmentValues( |
||||||
leftAlignment: context.loc.alignLeft, |
// leftAlignment: context.loc.alignLeft, |
||||||
centerAlignment: context.loc.alignCenter, |
// centerAlignment: context.loc.alignCenter, |
||||||
rightAlignment: context.loc.alignRight, |
// rightAlignment: context.loc.alignRight, |
||||||
justifyAlignment: context.loc.justifyWinWidth, |
// justifyAlignment: context.loc.justifyWinWidth, |
||||||
); |
// ); |
||||||
} |
// } |
||||||
|
|
||||||
void _didChangeEditingValue() { |
// void _didChangeEditingValue() { |
||||||
setState(() { |
// setState(() { |
||||||
_value = _selectionStyle.attributes[Attribute.align.key] ?? |
// _value = _selectionStyle.attributes[Attribute.align.key] ?? |
||||||
Attribute.leftAlignment; |
// Attribute.leftAlignment; |
||||||
}); |
// }); |
||||||
} |
// } |
||||||
|
|
||||||
@override |
// @override |
||||||
void didUpdateWidget( |
// void didUpdateWidget( |
||||||
covariant QuillToolbarSelectAlignmentOldButtons oldWidget) { |
// covariant QuillToolbarSelectAlignmentOldButtons oldWidget) { |
||||||
super.didUpdateWidget(oldWidget); |
// super.didUpdateWidget(oldWidget); |
||||||
if (oldWidget.controller != controller) { |
// if (oldWidget.controller != controller) { |
||||||
oldWidget.controller.removeListener(_didChangeEditingValue); |
// oldWidget.controller.removeListener(_didChangeEditingValue); |
||||||
controller.addListener(_didChangeEditingValue); |
// controller.addListener(_didChangeEditingValue); |
||||||
_value = _selectionStyle.attributes[Attribute.align.key] ?? |
// _value = _selectionStyle.attributes[Attribute.align.key] ?? |
||||||
Attribute.leftAlignment; |
// Attribute.leftAlignment; |
||||||
} |
// } |
||||||
} |
// } |
||||||
|
|
||||||
@override |
// @override |
||||||
void dispose() { |
// void dispose() { |
||||||
controller.removeListener(_didChangeEditingValue); |
// controller.removeListener(_didChangeEditingValue); |
||||||
super.dispose(); |
// super.dispose(); |
||||||
} |
// } |
||||||
|
|
||||||
@override |
// @override |
||||||
Widget build(BuildContext context) { |
// Widget build(BuildContext context) { |
||||||
final valueToText = <Attribute, String>{ |
// final valueToText = <Attribute, String>{ |
||||||
if (widget.showLeftAlignment!) |
|
||||||
Attribute.leftAlignment: Attribute.leftAlignment.value!, |
|
||||||
if (widget.showCenterAlignment!) |
|
||||||
Attribute.centerAlignment: Attribute.centerAlignment.value!, |
|
||||||
if (widget.showRightAlignment!) |
|
||||||
Attribute.rightAlignment: Attribute.rightAlignment.value!, |
|
||||||
if (widget.showJustifyAlignment!) |
|
||||||
Attribute.justifyAlignment: Attribute.justifyAlignment.value!, |
|
||||||
}; |
|
||||||
|
|
||||||
final valueAttribute = <Attribute>[ |
|
||||||
if (widget.showLeftAlignment!) Attribute.leftAlignment, |
|
||||||
if (widget.showCenterAlignment!) Attribute.centerAlignment, |
|
||||||
if (widget.showRightAlignment!) Attribute.rightAlignment, |
|
||||||
if (widget.showJustifyAlignment!) Attribute.justifyAlignment |
|
||||||
]; |
|
||||||
final valueString = <String>[ |
|
||||||
if (widget.showLeftAlignment!) Attribute.leftAlignment.value!, |
|
||||||
if (widget.showCenterAlignment!) Attribute.centerAlignment.value!, |
|
||||||
if (widget.showRightAlignment!) Attribute.rightAlignment.value!, |
|
||||||
if (widget.showJustifyAlignment!) Attribute.justifyAlignment.value!, |
|
||||||
]; |
|
||||||
// final _valueToButtons = <Attribute, ToolbarButtons>{ |
|
||||||
// if (widget.showLeftAlignment!) |
// if (widget.showLeftAlignment!) |
||||||
// Attribute.leftAlignment: ToolbarButtons.leftAlignment, |
// Attribute.leftAlignment: Attribute.leftAlignment.value!, |
||||||
// if (widget.showCenterAlignment!) |
// if (widget.showCenterAlignment!) |
||||||
// Attribute.centerAlignment: ToolbarButtons.centerAlignment, |
// Attribute.centerAlignment: Attribute.centerAlignment.value!, |
||||||
// if (widget.showRightAlignment!) |
// if (widget.showRightAlignment!) |
||||||
// Attribute.rightAlignment: ToolbarButtons.rightAlignment, |
// Attribute.rightAlignment: Attribute.rightAlignment.value!, |
||||||
// if (widget.showJustifyAlignment!) |
// if (widget.showJustifyAlignment!) |
||||||
// Attribute.justifyAlignment: ToolbarButtons.justifyAlignment, |
// Attribute.justifyAlignment: Attribute.justifyAlignment.value!, |
||||||
// }; |
// }; |
||||||
|
|
||||||
final buttonCount = ((widget.showLeftAlignment!) ? 1 : 0) + |
// final valueAttribute = <Attribute>[ |
||||||
((widget.showCenterAlignment!) ? 1 : 0) + |
// if (widget.showLeftAlignment!) Attribute.leftAlignment, |
||||||
((widget.showRightAlignment!) ? 1 : 0) + |
// if (widget.showCenterAlignment!) Attribute.centerAlignment, |
||||||
((widget.showJustifyAlignment!) ? 1 : 0); |
// if (widget.showRightAlignment!) Attribute.rightAlignment, |
||||||
|
// if (widget.showJustifyAlignment!) Attribute.justifyAlignment |
||||||
|
// ]; |
||||||
|
// final valueString = <String>[ |
||||||
|
// if (widget.showLeftAlignment!) Attribute.leftAlignment.value!, |
||||||
|
// if (widget.showCenterAlignment!) Attribute.centerAlignment.value!, |
||||||
|
// if (widget.showRightAlignment!) Attribute.rightAlignment.value!, |
||||||
|
// if (widget.showJustifyAlignment!) Attribute.justifyAlignment.value!, |
||||||
|
// ]; |
||||||
|
// // final _valueToButtons = <Attribute, ToolbarButtons>{ |
||||||
|
// // if (widget.showLeftAlignment!) |
||||||
|
// // Attribute.leftAlignment: ToolbarButtons.leftAlignment, |
||||||
|
// // if (widget.showCenterAlignment!) |
||||||
|
// // Attribute.centerAlignment: ToolbarButtons.centerAlignment, |
||||||
|
// // if (widget.showRightAlignment!) |
||||||
|
// // Attribute.rightAlignment: ToolbarButtons.rightAlignment, |
||||||
|
// // if (widget.showJustifyAlignment!) |
||||||
|
// // Attribute.justifyAlignment: ToolbarButtons.justifyAlignment, |
||||||
|
// // }; |
||||||
|
|
||||||
|
// final buttonCount = ((widget.showLeftAlignment!) ? 1 : 0) + |
||||||
|
// ((widget.showCenterAlignment!) ? 1 : 0) + |
||||||
|
// ((widget.showRightAlignment!) ? 1 : 0) + |
||||||
|
// ((widget.showJustifyAlignment!) ? 1 : 0); |
||||||
|
|
||||||
final childBuilder = |
// final childBuilder = |
||||||
options.childBuilder ?? baseButtonExtraOptions.childBuilder; |
// options.childBuilder ?? baseButtonExtraOptions.childBuilder; |
||||||
|
|
||||||
void sharedOnPressed(int index) { |
// void sharedOnPressed(int index) { |
||||||
valueAttribute[index] == Attribute.leftAlignment |
// valueAttribute[index] == Attribute.leftAlignment |
||||||
? controller.formatSelection( |
// ? controller.formatSelection( |
||||||
Attribute.clone(Attribute.align, null), |
// Attribute.clone(Attribute.align, null), |
||||||
) |
// ) |
||||||
: controller.formatSelection(valueAttribute[index]); |
// : controller.formatSelection(valueAttribute[index]); |
||||||
_afterButtonPressed?.call(); |
// _afterButtonPressed?.call(); |
||||||
} |
// } |
||||||
|
|
||||||
return Row( |
// return Row( |
||||||
mainAxisSize: MainAxisSize.min, |
// mainAxisSize: MainAxisSize.min, |
||||||
children: List.generate(buttonCount, (index) { |
// children: List.generate(buttonCount, (index) { |
||||||
if (childBuilder != null) { |
// if (childBuilder != null) { |
||||||
return childBuilder( |
// return childBuilder( |
||||||
QuillToolbarSelectAlignmentButtonOptions( |
// QuillToolbarSelectAlignmentButtonOptions( |
||||||
afterButtonPressed: _afterButtonPressed, |
// afterButtonPressed: _afterButtonPressed, |
||||||
iconSize: _iconSize, |
// iconSize: _iconSize, |
||||||
iconButtonFactor: _iconButtonFactor, |
// iconButtonFactor: _iconButtonFactor, |
||||||
iconTheme: _iconTheme, |
// iconTheme: _iconTheme, |
||||||
tooltips: _tooltips, |
// tooltips: _tooltips, |
||||||
iconsData: _iconsData, |
// iconsData: _iconsData, |
||||||
), |
// ), |
||||||
QuillToolbarSelectAlignmentButtonExtraOptions( |
// QuillToolbarSelectAlignmentButtonExtraOptions( |
||||||
context: context, |
// context: context, |
||||||
controller: controller, |
// controller: controller, |
||||||
onPressed: () => sharedOnPressed(index), |
// onPressed: () => sharedOnPressed(index), |
||||||
), |
// ), |
||||||
); |
// ); |
||||||
} |
// } |
||||||
final theme = Theme.of(context); |
// final theme = Theme.of(context); |
||||||
return Padding( |
// return Padding( |
||||||
padding: widget.padding ?? |
// padding: widget.padding ?? |
||||||
const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), |
// const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), |
||||||
child: ConstrainedBox( |
// child: ConstrainedBox( |
||||||
constraints: BoxConstraints.tightFor( |
// constraints: BoxConstraints.tightFor( |
||||||
width: _iconSize * _iconButtonFactor, |
// width: _iconSize * _iconButtonFactor, |
||||||
height: _iconSize * _iconButtonFactor, |
// height: _iconSize * _iconButtonFactor, |
||||||
), |
// ), |
||||||
child: UtilityWidgets.maybeTooltip( |
// child: UtilityWidgets.maybeTooltip( |
||||||
message: valueString[index] == Attribute.leftAlignment.value |
// message: valueString[index] == Attribute.leftAlignment.value |
||||||
? _tooltips.leftAlignment |
// ? _tooltips.leftAlignment |
||||||
: valueString[index] == Attribute.centerAlignment.value |
// : valueString[index] == Attribute.centerAlignment.value |
||||||
? _tooltips.centerAlignment |
// ? _tooltips.centerAlignment |
||||||
: valueString[index] == Attribute.rightAlignment.value |
// : valueString[index] == Attribute.rightAlignment.value |
||||||
? _tooltips.rightAlignment |
// ? _tooltips.rightAlignment |
||||||
: _tooltips.justifyAlignment, |
// : _tooltips.justifyAlignment, |
||||||
child: RawMaterialButton( |
// child: RawMaterialButton( |
||||||
hoverElevation: 0, |
// hoverElevation: 0, |
||||||
highlightElevation: 0, |
// highlightElevation: 0, |
||||||
elevation: 0, |
// elevation: 0, |
||||||
visualDensity: VisualDensity.compact, |
// visualDensity: VisualDensity.compact, |
||||||
shape: RoundedRectangleBorder( |
// shape: RoundedRectangleBorder( |
||||||
borderRadius: |
// borderRadius: |
||||||
BorderRadius.circular(_iconTheme?.borderRadius ?? 2)), |
// BorderRadius.circular(_iconTheme?.borderRadius ?? 2)), |
||||||
fillColor: valueToText[_value] == valueString[index] |
// fillColor: valueToText[_value] == valueString[index] |
||||||
? (_iconTheme?.iconSelectedFillColor ?? theme.primaryColor) |
// ? (_iconTheme?.iconSelectedFillColor ?? theme.primaryColor) |
||||||
: (_iconTheme?.iconUnselectedFillColor ?? |
// : (_iconTheme?.iconUnselectedFillColor ?? |
||||||
theme.canvasColor), |
// theme.canvasColor), |
||||||
onPressed: () => sharedOnPressed(index), |
// onPressed: () => sharedOnPressed(index), |
||||||
child: Icon( |
// child: Icon( |
||||||
valueString[index] == Attribute.leftAlignment.value |
// valueString[index] == Attribute.leftAlignment.value |
||||||
? _iconsData.leftAlignment |
// ? _iconsData.leftAlignment |
||||||
: valueString[index] == Attribute.centerAlignment.value |
// : valueString[index] == Attribute.centerAlignment.value |
||||||
? _iconsData.centerAlignment |
// ? _iconsData.centerAlignment |
||||||
: valueString[index] == Attribute.rightAlignment.value |
// : valueString[index] == Attribute.rightAlignment.value |
||||||
? _iconsData.rightAlignment |
// ? _iconsData.rightAlignment |
||||||
: _iconsData.justifyAlignment, |
// : _iconsData.justifyAlignment, |
||||||
size: _iconSize, |
// size: _iconSize, |
||||||
color: valueToText[_value] == valueString[index] |
// color: valueToText[_value] == valueString[index] |
||||||
? (_iconTheme?.iconSelectedColor ?? |
// ? (_iconTheme?.iconSelectedColor ?? |
||||||
theme.primaryIconTheme.color) |
// theme.primaryIconTheme.color) |
||||||
: (_iconTheme?.iconUnselectedColor ?? |
// : (_iconTheme?.iconUnselectedColor ?? |
||||||
theme.iconTheme.color), |
// theme.iconTheme.color), |
||||||
), |
// ), |
||||||
), |
// ), |
||||||
), |
// ), |
||||||
), |
// ), |
||||||
); |
// ); |
||||||
}), |
// }), |
||||||
); |
// ); |
||||||
} |
// } |
||||||
} |
// } |
||||||
|
Loading…
Reference in new issue