From 1c48af5e8473911951d9f9a45a2bcbadda664233 Mon Sep 17 00:00:00 2001 From: juliotati Date: Wed, 21 Jun 2023 16:25:51 +0100 Subject: [PATCH 1/2] fix: markdown paragraph and code text selection --- lib/helpers/dart_syntax_highlighter.dart | 2 +- .../widgets/markdown_view.dart | 45 ++++++++++--------- .../widgets/rich_markdown_body.dart | 3 +- pubspec.yaml | 2 +- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/helpers/dart_syntax_highlighter.dart b/lib/helpers/dart_syntax_highlighter.dart index a09051d..d42e9e2 100644 --- a/lib/helpers/dart_syntax_highlighter.dart +++ b/lib/helpers/dart_syntax_highlighter.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart' show BuildContext, Color, TextSpan, TextStyle, Theme; -import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:flutter_markdown_selectionarea/flutter_markdown_selectionarea.dart'; import 'package:highlight/highlight.dart'; class DartSyntaxHighlighter extends SyntaxHighlighter { diff --git a/lib/modules/design_pattern_details/widgets/markdown_view.dart b/lib/modules/design_pattern_details/widgets/markdown_view.dart index b44a391..6d8ae7f 100644 --- a/lib/modules/design_pattern_details/widgets/markdown_view.dart +++ b/lib/modules/design_pattern_details/widgets/markdown_view.dart @@ -22,30 +22,33 @@ class MarkdownView extends ConsumerWidget { behavior: const ScrollBehavior(), child: SingleChildScrollView( padding: const EdgeInsets.all(LayoutConstants.paddingL), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - designPattern.description, - style: Theme.of(context).textTheme.titleMedium, - textAlign: TextAlign.justify, - overflow: TextOverflow.ellipsis, - maxLines: 99, - ), - const SizedBox(height: LayoutConstants.spaceL), - markdown.when( - data: (data) => RichMarkdownBody(data: data), - loading: () => Center( - child: CircularProgressIndicator( - backgroundColor: lightBackgroundColor, - valueColor: AlwaysStoppedAnimation( - Colors.black.withOpacity(0.65), + child: SelectionArea( + focusNode: FocusNode(), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + designPattern.description, + style: Theme.of(context).textTheme.titleMedium, + textAlign: TextAlign.justify, + overflow: TextOverflow.ellipsis, + maxLines: 99, + ), + const SizedBox(height: LayoutConstants.spaceL), + markdown.when( + data: (data) => RichMarkdownBody(data: data), + loading: () => Center( + child: CircularProgressIndicator( + backgroundColor: lightBackgroundColor, + valueColor: AlwaysStoppedAnimation( + Colors.black.withOpacity(0.65), + ), ), ), + error: (_, __) => const Text('Oops, something went wrong...'), ), - error: (_, __) => const Text('Oops, something went wrong...'), - ), - ], + ], + ), ), ), ); diff --git a/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart b/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart index c77aa4b..2c699ac 100644 --- a/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart +++ b/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:flutter_markdown_selectionarea/flutter_markdown_selectionarea.dart'; import '../../../constants/constants.dart'; import '../../../helpers/dart_syntax_highlighter.dart'; @@ -20,7 +20,6 @@ class RichMarkdownBody extends StatelessWidget { final fontSize = bodyMedium?.fontSize ?? 14.0; return MarkdownBody( - selectable: true, fitContent: false, styleSheet: MarkdownStyleSheet( h1: textTheme.headlineMedium, diff --git a/pubspec.yaml b/pubspec.yaml index 9dbfda9..0a52577 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: faker: ^2.1.0 flutter: sdk: flutter - flutter_markdown: ^0.6.14 + flutter_markdown_selectionarea: ^0.6.14+3 flutter_riverpod: ^2.3.6 font_awesome_flutter: ^10.4.0 go_router: ^7.0.1 From 1ba22bc7da8754bb3a5930fe8bc1288a7f68e659 Mon Sep 17 00:00:00 2001 From: _juliotati <59662912+Juliotati@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:11:27 +0100 Subject: [PATCH 2/2] use official `flutter_markdown` again - The official package fixed the conflict between `SelectionArea` and `MarkdownBody` --- lib/helpers/dart_syntax_highlighter.dart | 2 +- .../design_pattern_details/widgets/rich_markdown_body.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/helpers/dart_syntax_highlighter.dart b/lib/helpers/dart_syntax_highlighter.dart index d42e9e2..a09051d 100644 --- a/lib/helpers/dart_syntax_highlighter.dart +++ b/lib/helpers/dart_syntax_highlighter.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart' show BuildContext, Color, TextSpan, TextStyle, Theme; -import 'package:flutter_markdown_selectionarea/flutter_markdown_selectionarea.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:highlight/highlight.dart'; class DartSyntaxHighlighter extends SyntaxHighlighter { diff --git a/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart b/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart index 2c699ac..dcb09e6 100644 --- a/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart +++ b/lib/modules/design_pattern_details/widgets/rich_markdown_body.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_markdown_selectionarea/flutter_markdown_selectionarea.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; import '../../../constants/constants.dart'; import '../../../helpers/dart_syntax_highlighter.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 0a52577..4880084 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: faker: ^2.1.0 flutter: sdk: flutter - flutter_markdown_selectionarea: ^0.6.14+3 + flutter_markdown: ^0.7.3+1 flutter_riverpod: ^2.3.6 font_awesome_flutter: ^10.4.0 go_router: ^7.0.1