Skip to content

Commit

Permalink
feat: custom btn in example app + refactor: remove useless properties…
Browse files Browse the repository at this point in the history
… on ActionButton + doc: document new properties/class
  • Loading branch information
Clémence Roumy committed Mar 24, 2023
1 parent 9fc3d85 commit d3fca06
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ MarkdownEditableTextInput is a TextField Widget that allow you to convert easily
- [x] Convert to Code, Quote, Links
- [x] Convert to Heading (H1, H2, H3, H4, H5, H6) and Links
- [x] Support text direction
- [x] Dialog mode to enter link and picture
- [x] Possibility to add custom buttons to the action bar

## Demo
![](pictures/test_edition.gif)
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class _MyAppState extends State<MyApp> {
actions: MarkdownType.values,
controller: controller,
textStyle: TextStyle(fontSize: 16),
optionnalActionButtons: [
ActionButton(widget: Icon(Icons.add), action: () => controller.text = '${controller.text} test ')
],
),
TextButton(
onPressed: () {
Expand Down
9 changes: 5 additions & 4 deletions lib/format_markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ enum MarkdownType {
image,
}
/// Custom button object
class ActionButton {
/// [widget] is the icon in the action bar
final Widget widget;
final String title;
/// Action to perform when button is pressed
final Function() action;
final List<ActionButton> children;
final Key key;
ActionButton(this.key, {required this.widget, required this.action, this.children = const [], this.title = ""});
/// return [ActionButton]
ActionButton({required this.widget, required this.action});
}
/// Add data to [MarkdownType] enum
Expand Down
2 changes: 1 addition & 1 deletion lib/markdown_text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MarkdownTextInput extends StatefulWidget {
/// List of action the component can handle
final List<MarkdownType> actions;

/// List of custom action buttons
final List<ActionButton> optionnalActionButtons;

/// Optional controller to manage the input
Expand Down Expand Up @@ -257,7 +258,6 @@ class _MarkdownTextInputState extends State<MarkdownTextInput> {
);
} else if (item is ActionButton) {
return InkWell(
key: item.key,
onTap: item.action,
child: Padding(
padding: EdgeInsets.all(10),
Expand Down

0 comments on commit d3fca06

Please sign in to comment.