dartlangeditorflutterflutter-appsflutter-examplesflutter-packageflutter-widgetquillquill-deltaquilljsreactquillrich-textrich-text-editorwysiwygwysiwyg-editor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.8 KiB
141 lines
3.8 KiB
2 years ago
|
import 'package:flutter/material.dart';
|
||
|
|
||
1 year ago
|
import '../../../extensions/quill_provider.dart';
|
||
1 year ago
|
import '../../../l10n/extensions/localizations.dart';
|
||
2 years ago
|
import '../../controller.dart';
|
||
2 years ago
|
import '../base_toolbar.dart';
|
||
2 years ago
|
|
||
|
class QuillToolbarHistoryButton extends StatefulWidget {
|
||
|
const QuillToolbarHistoryButton({
|
||
|
required this.options,
|
||
2 years ago
|
required this.controller,
|
||
2 years ago
|
super.key,
|
||
|
});
|
||
|
|
||
|
final QuillToolbarHistoryButtonOptions options;
|
||
2 years ago
|
final QuillController controller;
|
||
2 years ago
|
|
||
|
@override
|
||
1 year ago
|
QuillToolbarHistoryButtonState createState() =>
|
||
|
QuillToolbarHistoryButtonState();
|
||
2 years ago
|
}
|
||
|
|
||
1 year ago
|
class QuillToolbarHistoryButtonState extends State<QuillToolbarHistoryButton> {
|
||
2 years ago
|
late ThemeData theme;
|
||
|
var _canPressed = false;
|
||
|
|
||
|
QuillToolbarHistoryButtonOptions get options {
|
||
|
return widget.options;
|
||
|
}
|
||
|
|
||
|
QuillController get controller {
|
||
2 years ago
|
return widget.controller;
|
||
2 years ago
|
}
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
_listenForChanges(); // Listen for changes and change it
|
||
|
}
|
||
|
|
||
2 years ago
|
void _listenForChanges() {
|
||
2 years ago
|
_updateCanPressed(); // Set the init state
|
||
|
|
||
|
// Listen for changes and change it
|
||
|
controller.changes.listen((event) async {
|
||
2 years ago
|
_updateCanPressedWithSetState();
|
||
2 years ago
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final baseButtonConfigurations =
|
||
|
context.requireQuillToolbarBaseButtonOptions;
|
||
|
final tooltip = options.tooltip ??
|
||
|
baseButtonConfigurations.tooltip ??
|
||
1 year ago
|
(options.isUndo ? context.loc.undo : context.loc.redo);
|
||
2 years ago
|
final iconData = options.iconData ??
|
||
|
baseButtonConfigurations.iconData ??
|
||
|
(options.isUndo ? Icons.undo_outlined : Icons.redo_outlined);
|
||
|
final childBuilder =
|
||
|
options.childBuilder ?? baseButtonConfigurations.childBuilder;
|
||
1 year ago
|
final iconSize =
|
||
|
options.iconSize ?? baseButtonConfigurations.globalIconSize;
|
||
1 year ago
|
final iconButtonFactor = options.iconButtonFactor ??
|
||
1 year ago
|
baseButtonConfigurations.globalIconButtonFactor;
|
||
2 years ago
|
final iconTheme = options.iconTheme ?? baseButtonConfigurations.iconTheme;
|
||
|
|
||
|
final afterButtonPressed = options.afterButtonPressed ??
|
||
|
baseButtonConfigurations.afterButtonPressed;
|
||
|
|
||
|
if (childBuilder != null) {
|
||
|
return childBuilder(
|
||
|
QuillToolbarHistoryButtonOptions(
|
||
|
isUndo: options.isUndo,
|
||
|
afterButtonPressed: afterButtonPressed,
|
||
|
controller: controller,
|
||
|
iconData: iconData,
|
||
|
iconSize: iconSize,
|
||
1 year ago
|
iconButtonFactor: iconButtonFactor,
|
||
2 years ago
|
iconTheme: iconTheme,
|
||
|
tooltip: tooltip,
|
||
|
),
|
||
2 years ago
|
QuillToolbarHistoryButtonExtraOptions(
|
||
2 years ago
|
onPressed: () {
|
||
|
_updateHistory();
|
||
|
afterButtonPressed?.call();
|
||
|
},
|
||
|
canPressed: _canPressed,
|
||
2 years ago
|
controller: controller,
|
||
|
context: context,
|
||
2 years ago
|
),
|
||
|
);
|
||
|
}
|
||
2 years ago
|
|
||
|
theme = Theme.of(context);
|
||
2 years ago
|
return QuillToolbarIconButton(
|
||
2 years ago
|
tooltip: tooltip,
|
||
1 year ago
|
size: iconSize * iconButtonFactor,
|
||
2 years ago
|
icon: Icon(
|
||
|
iconData,
|
||
|
size: iconSize,
|
||
|
color: _canPressed
|
||
|
? iconTheme?.iconUnselectedColor ?? theme.iconTheme.color
|
||
|
: iconTheme?.disabledIconColor ?? theme.disabledColor,
|
||
|
),
|
||
1 year ago
|
isFilled: false,
|
||
2 years ago
|
onPressed: _updateHistory,
|
||
|
afterPressed: afterButtonPressed,
|
||
|
);
|
||
|
}
|
||
|
|
||
2 years ago
|
void _updateCanPressedWithSetState() {
|
||
2 years ago
|
if (!mounted) return;
|
||
|
|
||
2 years ago
|
setState(_updateCanPressed);
|
||
|
}
|
||
|
|
||
|
void _updateCanPressed() {
|
||
|
if (options.isUndo) {
|
||
|
_canPressed = controller.hasUndo;
|
||
|
return;
|
||
|
}
|
||
|
_canPressed = controller.hasRedo;
|
||
2 years ago
|
}
|
||
|
|
||
|
void _updateHistory() {
|
||
|
if (options.isUndo) {
|
||
|
if (controller.hasUndo) {
|
||
|
controller.undo();
|
||
|
}
|
||
|
// _updateCanPressed(); // We are already listeneting for the changes
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (controller.hasRedo) {
|
||
|
controller.redo();
|
||
|
// _updateCanPressed(); // We are already listeneting for the changes
|
||
|
}
|
||
|
}
|
||
|
}
|