diff --git a/example/lib/main.dart b/example/lib/main.dart index 2bdb0bd..3a7b71d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -32,7 +32,7 @@ class _MyAppState extends State { primaryColor: const Color(0xFF2C1C6B), colorScheme: ColorScheme.light().copyWith(secondary: const Color(0xFF200681)), cardColor: const Color(0xFFF8F9FC), - textTheme: const TextTheme(bodyText1: TextStyle(fontSize: 20, color: Color(0xFF2C1C6B))), + textTheme: const TextTheme(bodyLarge: TextStyle(fontSize: 20, color: Color(0xFF2C1C6B))), ), child: Scaffold( appBar: AppBar( @@ -58,7 +58,8 @@ class _MyAppState extends State { controller: controller, textStyle: TextStyle(fontSize: 16), optionnalActionButtons: [ - ActionButton(widget: Icon(Icons.add), action: () => controller.text = '${controller.text} test ') + ActionButton( + widget: Icon(Icons.add), action: () => controller.text = '${controller.text} test ') ], ), TextButton( diff --git a/example/pubspec.lock b/example/pubspec.lock index e790cc5..9d9ec8b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,79 +5,82 @@ packages: dependency: transitive description: name: args - url: "https://pub.dartlang.org" + sha256: "0bd9a99b6eb96f07af141f0eb53eace8983e8e5aa5de59777aca31684680ef22" + url: "https://pub.dev" source: hosted version: "2.3.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" source: hosted - version: "0.1.3" + version: "1.0.8" effective_dart: dependency: transitive description: name: effective_dart - url: "https://pub.dartlang.org" + sha256: "6a69783c808344084b65667e87ff600823531e95810a8a15882cb542fe22de80" + url: "https://pub.dev" source: hosted version: "1.3.2" expandable: dependency: transitive description: name: expandable - url: "https://pub.dartlang.org" + sha256: "9604d612d4d1146dafa96c6d8eec9c2ff0994658d6d09fed720ab788c7f5afc2" + url: "https://pub.dev" source: hosted version: "5.0.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -87,21 +90,47 @@ packages: dependency: "direct main" description: name: flutter_markdown - url: "https://pub.dartlang.org" + sha256: "9921f9deda326f8a885e202b1e35237eadfc1345239a0f6f0f1ff287e047547f" + url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" markdown: dependency: transitive description: name: markdown - url: "https://pub.dartlang.org" + sha256: ef2a1298144e3f985cc736b22e0ccdaf188b5b3970648f2d9dc13efd1d9df051 + url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "7.2.2" markdown_editable_textinput: dependency: "direct main" description: @@ -113,23 +142,34 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.12.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -139,58 +179,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" source: hosted - version: "0.4.3" - typed_data: + version: "0.7.0" + vector_math: dependency: transitive description: - name: typed_data - url: "https://pub.dartlang.org" + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "1.3.0" - vector_math: + version: "2.1.4" + vm_service: dependency: transitive description: - name: vector_math - url: "https://pub.dartlang.org" + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "14.2.1" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.19.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 72de1f6..9eb642e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter application. version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" publish_to: none @@ -14,10 +14,10 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.8 markdown_editable_textinput: path: ../ - flutter_markdown: ^0.6.7 + flutter_markdown: ^0.7.1 dev_dependencies: diff --git a/lib/markdown_text_input.dart b/lib/markdown_text_input.dart index 95bff0f..9a7db0a 100644 --- a/lib/markdown_text_input.dart +++ b/lib/markdown_text_input.dart @@ -74,7 +74,13 @@ class MarkdownTextInput extends StatefulWidget { this.validators, this.textDirection = TextDirection.ltr, this.maxLines = 10, - this.actions = const [MarkdownType.bold, MarkdownType.italic, MarkdownType.title, MarkdownType.link, MarkdownType.list], + this.actions = const [ + MarkdownType.bold, + MarkdownType.italic, + MarkdownType.title, + MarkdownType.link, + MarkdownType.list + ], this.textStyle, this.controller, this.insertLinksByDialog = true, @@ -88,7 +94,6 @@ class MarkdownTextInput extends StatefulWidget { this.customSubmitDialogText, this.optionnalActionButtons = const []}); - @override _MarkdownTextInputState createState() => _MarkdownTextInputState(controller ?? TextEditingController()); } @@ -107,10 +112,11 @@ class _MarkdownTextInputState extends State { var fromIndex = min(textSelection.baseOffset, textSelection.extentOffset); var toIndex = max(textSelection.extentOffset, textSelection.baseOffset); - final result = - FormatMarkdown.convertToMarkdown(type, _controller.text, fromIndex, toIndex, titleSize: titleSize, link: link, selectedText: selectedText ?? _controller.text.substring(fromIndex, toIndex)); + final result = FormatMarkdown.convertToMarkdown(type, _controller.text, fromIndex, toIndex, + titleSize: titleSize, link: link, selectedText: selectedText ?? _controller.text.substring(fromIndex, toIndex)); - _controller.value = _controller.value.copyWith(text: result.data, selection: TextSelection.collapsed(offset: basePosition + result.cursorIndex)); + _controller.value = _controller.value + .copyWith(text: result.data, selection: TextSelection.collapsed(offset: basePosition + result.cursorIndex)); if (noTextSelected) { _controller.selection = TextSelection.collapsed(offset: _controller.selection.end - result.replaceCursorIndex); @@ -138,6 +144,25 @@ class _MarkdownTextInputState extends State { @override Widget build(BuildContext context) { + var textFormField = TextFormField( + focusNode: focusNode, + textInputAction: TextInputAction.newline, + maxLines: widget.maxLines, + expands: widget.maxLines == null, + controller: _controller, + textCapitalization: TextCapitalization.sentences, + validator: widget.validators != null ? (value) => widget.validators!(value) : null, + style: widget.textStyle ?? Theme.of(context).textTheme.bodyLarge, + cursorColor: Theme.of(context).primaryColor, + textDirection: widget.textDirection, + decoration: InputDecoration( + enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).colorScheme.secondary)), + focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).colorScheme.secondary)), + hintText: widget.label, + hintStyle: const TextStyle(color: Color.fromRGBO(63, 61, 86, 0.5)), + contentPadding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), + ), + ); return Container( decoration: BoxDecoration( color: Theme.of(context).cardColor, @@ -146,24 +171,11 @@ class _MarkdownTextInputState extends State { ), child: Column( children: [ - TextFormField( - focusNode: focusNode, - textInputAction: TextInputAction.newline, - maxLines: widget.maxLines, - controller: _controller, - textCapitalization: TextCapitalization.sentences, - validator: widget.validators != null ? (value) => widget.validators!(value) : null, - style: widget.textStyle ?? Theme.of(context).textTheme.bodyText1, - cursorColor: Theme.of(context).primaryColor, - textDirection: widget.textDirection, - decoration: InputDecoration( - enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).colorScheme.secondary)), - focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).colorScheme.secondary)), - hintText: widget.label, - hintStyle: const TextStyle(color: Color.fromRGBO(63, 61, 86, 0.5)), - contentPadding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), + if (widget.maxLines == null) + Expanded( + child: textFormField, ), - ), + if (widget.maxLines != null) textFormField, SizedBox( height: 44, child: Material( @@ -220,10 +232,13 @@ class _MarkdownTextInputState extends State { } else if (type == MarkdownType.link || type == MarkdownType.image) { return _basicInkwell( type, - customOnTap: (type == MarkdownType.link ? !widget.insertLinksByDialog : !widget.insertImageByDialog) + customOnTap: (type == MarkdownType.link + ? !widget.insertLinksByDialog + : !widget.insertImageByDialog) ? null : () async { - var text = _controller.text.substring(textSelection.baseOffset, textSelection.extentOffset); + var text = + _controller.text.substring(textSelection.baseOffset, textSelection.extentOffset); var textController = TextEditingController()..text = text; var linkController = TextEditingController(); @@ -237,8 +252,6 @@ class _MarkdownTextInputState extends State { return _basicInkwell(type); } }).toList(), - - ...widget.optionnalActionButtons.map((ActionButton optionActionButton) { return _basicInkwell(optionActionButton, customOnTap: optionActionButton.action); }).toList() @@ -283,8 +296,10 @@ class _MarkdownTextInputState extends State { String text, MarkdownType type, ) async { - var finalTextInputDecoration = type == MarkdownType.link ? widget.linkDialogTextDecoration : widget.imageDialogTextDecoration; - var finalLinkInputDecoration = type == MarkdownType.link ? widget.linkDialogLinkDecoration : widget.imageDialogLinkDecoration; + var finalTextInputDecoration = + type == MarkdownType.link ? widget.linkDialogTextDecoration : widget.imageDialogTextDecoration; + var finalLinkInputDecoration = + type == MarkdownType.link ? widget.linkDialogLinkDecoration : widget.imageDialogLinkDecoration; var textFocus = FocusNode(); var linkFocus = FocusNode(); diff --git a/pubspec.lock b/pubspec.lock index c925182..6bacde4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,65 +5,66 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.18.0" effective_dart: dependency: "direct main" description: name: effective_dart - url: "https://pub.dartlang.org" + sha256: "6a69783c808344084b65667e87ff600823531e95810a8a15882cb542fe22de80" + url: "https://pub.dev" source: hosted version: "1.3.2" expandable: dependency: "direct main" description: name: expandable - url: "https://pub.dartlang.org" + sha256: "9604d612d4d1146dafa96c6d8eec9c2ff0994658d6d09fed720ab788c7f5afc2" + url: "https://pub.dev" source: hosted version: "5.0.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -74,27 +75,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.12.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -104,58 +140,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" source: hosted - version: "0.4.3" - typed_data: + version: "0.7.0" + vector_math: dependency: transitive description: - name: typed_data - url: "https://pub.dartlang.org" + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "1.3.0" - vector_math: + version: "2.1.4" + vm_service: dependency: transitive description: - name: vector_math - url: "https://pub.dartlang.org" + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "14.2.1" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index ec5204d..22a1e8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/playmoweb/markdown-editable-textinput repository: https://github.com/playmoweb/markdown-editable-textinput environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.12.0 <4.0.0' dependencies: flutter: