refactor: extracted RichEditorOptions
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
library rich_editor;
|
||||
|
||||
export 'src/models/enum/bar_position.dart';
|
||||
export 'src/models/rich_editor_options.dart';
|
||||
export 'src/rendering/rich_editor.dart';
|
||||
export 'src/utils/javascript_executor_base.dart';
|
||||
export 'src/widgets/editor_tool_bar.dart';
|
||||
export 'src/widgets/tab_button.dart';
|
||||
export 'src/models/enum.dart';
|
||||
export 'src/widgets/tab_button.dart';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:rich_editor/src/models/enum.dart';
|
||||
|
||||
import 'command_state.dart';
|
||||
import 'enum/command_name.dart';
|
||||
|
||||
class EditorState {
|
||||
bool? didHtmlChange;
|
||||
|
||||
1
lib/src/models/enum/bar_position.dart
Normal file
1
lib/src/models/enum/bar_position.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum BarPosition { TOP, BOTTOM, CUSTOM }
|
||||
@@ -38,6 +38,4 @@ enum CommandName {
|
||||
INSERTCHECKBOX,
|
||||
// pseudo commands for toggling grouped command views
|
||||
EXPANDING_SEARCH_VIEWING,
|
||||
}
|
||||
|
||||
enum BarPosition { TOP, BOTTOM }
|
||||
}
|
||||
28
lib/src/models/rich_editor_options.dart
Normal file
28
lib/src/models/rich_editor_options.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'enum/bar_position.dart';
|
||||
|
||||
class RichEditorOptions {
|
||||
Color? backgroundColor;
|
||||
Color? baseTextColor;
|
||||
EdgeInsets? padding;
|
||||
String? placeholder;
|
||||
String? baseFontFamily;
|
||||
BarPosition? barPosition;
|
||||
|
||||
RichEditorOptions({
|
||||
Color? backgroundColor,
|
||||
Color? baseTextColor,
|
||||
EdgeInsets? padding,
|
||||
String? placeholder,
|
||||
String? baseFontFamily,
|
||||
BarPosition? barPosition,
|
||||
}) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.baseTextColor = baseTextColor;
|
||||
this.padding = padding;
|
||||
this.placeholder = placeholder;
|
||||
this.baseFontFamily = baseFontFamily;
|
||||
this.barPosition = barPosition;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rich_editor/src/models/enum.dart';
|
||||
import 'package:rich_editor/src/models/enum/bar_position.dart';
|
||||
import 'package:rich_editor/src/models/rich_editor_options.dart';
|
||||
import 'package:rich_editor/src/services/local_server.dart';
|
||||
import 'package:rich_editor/src/utils/javascript_executor_base.dart';
|
||||
import 'package:rich_editor/src/widgets/editor_tool_bar.dart';
|
||||
@@ -12,24 +13,14 @@ import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class RichEditor extends StatefulWidget {
|
||||
final String? value;
|
||||
final Color? backgroundColor;
|
||||
final Color? baseTextColor;
|
||||
final EdgeInsets? padding;
|
||||
final String? placeholder;
|
||||
final String? baseFontFamily;
|
||||
final BarPosition barPosition;
|
||||
final RichEditorOptions? editorOptions;
|
||||
final Function(File image)? getImageUrl;
|
||||
final Function(File video)? getVideoUrl;
|
||||
|
||||
RichEditor({
|
||||
Key? key,
|
||||
this.value,
|
||||
this.backgroundColor,
|
||||
this.baseTextColor,
|
||||
this.padding,
|
||||
this.placeholder,
|
||||
this.baseFontFamily,
|
||||
this.barPosition = BarPosition.TOP,
|
||||
this.editorOptions,
|
||||
this.getImageUrl,
|
||||
this.getVideoUrl,
|
||||
}) : super(key: key);
|
||||
@@ -93,7 +84,7 @@ class RichEditorState extends State<RichEditor> {
|
||||
return Column(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: widget.barPosition == BarPosition.TOP,
|
||||
visible: widget.editorOptions!.barPosition == BarPosition.TOP,
|
||||
child: EditorToolBar(
|
||||
controller: _controller,
|
||||
getImageUrl: widget.getImageUrl,
|
||||
@@ -128,7 +119,7 @@ class RichEditorState extends State<RichEditor> {
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: widget.barPosition == BarPosition.BOTTOM,
|
||||
visible: widget.editorOptions!.barPosition == BarPosition.BOTTOM,
|
||||
child: EditorToolBar(
|
||||
controller: _controller,
|
||||
getImageUrl: widget.getImageUrl,
|
||||
@@ -141,16 +132,20 @@ class RichEditorState extends State<RichEditor> {
|
||||
|
||||
_setInitialValues() async {
|
||||
if (widget.value != null) await javascriptExecutor.setHtml(widget.value!);
|
||||
if (widget.padding != null)
|
||||
await javascriptExecutor.setPadding(widget.padding!);
|
||||
if (widget.backgroundColor != null)
|
||||
await javascriptExecutor.setBackgroundColor(widget.backgroundColor!);
|
||||
if (widget.baseTextColor != null)
|
||||
await javascriptExecutor.setBaseTextColor(widget.baseTextColor!);
|
||||
if (widget.placeholder != null)
|
||||
await javascriptExecutor.setPlaceholder(widget.placeholder!);
|
||||
if (widget.baseFontFamily != null)
|
||||
await javascriptExecutor.setBaseFontFamily(widget.baseFontFamily!);
|
||||
if (widget.editorOptions!.padding != null)
|
||||
await javascriptExecutor.setPadding(widget.editorOptions!.padding!);
|
||||
if (widget.editorOptions!.backgroundColor != null)
|
||||
await javascriptExecutor
|
||||
.setBackgroundColor(widget.editorOptions!.backgroundColor!);
|
||||
if (widget.editorOptions!.baseTextColor != null)
|
||||
await javascriptExecutor
|
||||
.setBaseTextColor(widget.editorOptions!.baseTextColor!);
|
||||
if (widget.editorOptions!.placeholder != null)
|
||||
await javascriptExecutor
|
||||
.setPlaceholder(widget.editorOptions!.placeholder!);
|
||||
if (widget.editorOptions!.baseFontFamily != null)
|
||||
await javascriptExecutor
|
||||
.setBaseFontFamily(widget.editorOptions!.baseFontFamily!);
|
||||
}
|
||||
|
||||
/// Get current HTML from editor
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rich_editor/src/extensions/extensions.dart';
|
||||
import 'package:rich_editor/src/models/editor_state.dart';
|
||||
import 'package:rich_editor/src/models/enum.dart';
|
||||
import 'package:rich_editor/src/models/enum/command_name.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import '../models/command_state.dart';
|
||||
|
||||
@@ -4,8 +4,9 @@ class TabButton extends StatelessWidget {
|
||||
final IconData? icon;
|
||||
final Function? onTap;
|
||||
final String tooltip;
|
||||
final bool selected;
|
||||
|
||||
TabButton({this.icon, this.onTap, this.tooltip = ''});
|
||||
TabButton({this.icon, this.onTap, this.tooltip = '', this.selected = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -17,7 +18,9 @@ class TabButton extends StatelessWidget {
|
||||
height: 40.0,
|
||||
width: 40.0,
|
||||
decoration: BoxDecoration(
|
||||
// color: Color(0xff212121),
|
||||
color: selected
|
||||
? Theme.of(context).accentColor.withOpacity(0.2)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(5.0),
|
||||
),
|
||||
@@ -32,7 +35,9 @@ class TabButton extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
child: Icon(
|
||||
icon,
|
||||
// color: Theme.of(context).accentColor,
|
||||
color: selected
|
||||
? Theme.of(context).accentColor
|
||||
: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user