Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only break line if meet break line symbols #91

Closed
coderof19clc7 opened this issue Apr 2, 2023 · 13 comments
Closed

Only break line if meet break line symbols #91

coderof19clc7 opened this issue Apr 2, 2023 · 13 comments
Labels
enhancement New feature or request

Comments

@coderof19clc7
Copy link

Can this package update the rendering feature so that it can render full text in 1 line instead of soft wrap and only break line when there is a break line symbols ?

@coderof19clc7 coderof19clc7 added the enhancement New feature or request label Apr 2, 2023
@asjqkkkk
Copy link
Owner

asjqkkkk commented Apr 3, 2023

Hi @coderof19clc7 , do you mean something like that, this effect only occurs within code blocks.

test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code;

test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  test code;  

test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code; test code;

@coderof19clc7
Copy link
Author

yes that right, how can I do that ?

@asjqkkkk
Copy link
Owner

asjqkkkk commented Apr 3, 2023

Hi @coderof19clc7 , there is a temporary solution, insert codeBlockGenerator into MarkdownGeneratorConfig -> generators

And I'll implement it as a default feature in the next version.

import 'package:flutter/material.dart';
import 'package:markdown_widget/markdown_widget.dart';

SpanNodeGeneratorWithTag codeBlockGenerator = SpanNodeGeneratorWithTag(
    tag: MarkdownTag.pre.name,
    generator: (e, config, visitor) =>
        CustomCodeBlockNode(e.textContent, config.pre));

class CustomCodeBlockNode extends ElementNode {
  CustomCodeBlockNode(this.content, this.preConfig);

  final String content;
  final PreConfig preConfig;

  @override
  InlineSpan build() {
    final splitContents = content.split(RegExp(r'(\r?\n)|(\r?\t)|(\r)'));
    if(splitContents.last.isEmpty) splitContents.removeLast();
    return WidgetSpan(
        child: Container(
      decoration: preConfig.decoration,
      margin: preConfig.margin,
      padding: preConfig.padding,
      width: double.infinity,
      child: Scrollbar(
        thumbVisibility: true,
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: List.generate(splitContents.length, (index) {
              final currentContent = splitContents[index];
              return ProxyRichText(TextSpan(
                children: highLightSpans(currentContent,
                    language: preConfig.language,
                    theme: preConfig.theme,
                    textStyle: style),
              ));
            }),
          ),
        ),
      ),
    ));
  }

  @override
  TextStyle get style => preConfig.textStyle.merge(parentStyle);
}

@coderof19clc7
Copy link
Author

thanks for your solution, i will try it out

@coderof19clc7
Copy link
Author

@asjqkkkk your solution work as expected but it causes this error

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
The Scrollbar's ScrollController has no ScrollPosition attached.

A Scrollbar cannot be painted without a ScrollPosition.

The Scrollbar attempted to use the PrimaryScrollController. This ScrollController should be associated with the ScrollView that the Scrollbar is being applied to.A ScrollView with an Axis.vertical ScrollDirection on mobile platforms will automatically use the PrimaryScrollController if the user has not provided a ScrollController. To use the PrimaryScrollController explicitly, set ScrollView.primary to true for the Scrollable widget.

When the exception was thrown, this was the stack:
#0 RawScrollbarState._debugCheckHasValidScrollPosition. (package:flutter/src/widgets/scrollbar.dart:1597:9)
#1 RawScrollbarState._debugCheckHasValidScrollPosition (package:flutter/src/widgets/scrollbar.dart:1622:6)
#2 RawScrollbarState._debugScheduleCheckHasValidScrollPosition. (package:flutter/src/widgets/scrollbar.dart:1551:14)
#3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#5 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:942:7)
#9 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
(elided 3 frames from class _Timer and dart:async-patch)

The error does not cause any unexpected behavior, I just want to tell you about it.
Thanks for your solution again.

@asjqkkkk
Copy link
Owner

asjqkkkk commented Apr 3, 2023

@asjqkkkk your solution work as expected but it causes this error

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
The Scrollbar's ScrollController has no ScrollPosition attached.

A Scrollbar cannot be painted without a ScrollPosition.

The Scrollbar attempted to use the PrimaryScrollController. This ScrollController should be associated with the ScrollView that the Scrollbar is being applied to.A ScrollView with an Axis.vertical ScrollDirection on mobile platforms will automatically use the PrimaryScrollController if the user has not provided a ScrollController. To use the PrimaryScrollController explicitly, set ScrollView.primary to true for the Scrollable widget.

When the exception was thrown, this was the stack: #0 RawScrollbarState._debugCheckHasValidScrollPosition. (package:flutter/src/widgets/scrollbar.dart:1597:9) #1 RawScrollbarState._debugCheckHasValidScrollPosition (package:flutter/src/widgets/scrollbar.dart:1622:6) #2 RawScrollbarState._debugScheduleCheckHasValidScrollPosition. (package:flutter/src/widgets/scrollbar.dart:1551:14) #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15) #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9) #5 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:942:7) #9 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26) (elided 3 frames from class _Timer and dart:async-patch)

The error does not cause any unexpected behavior, I just want to tell you about it. Thanks for your solution again.

this issue is associated with flutter/flutter#97873

you can have a try by pass the same ScrollController between Scrollbar and SingleChildScrollView

    final scrollController = ScrollController();
    return WidgetSpan(
           ...
          child: Scrollbar(
            controller: scrollController,
            thumbVisibility: true,
            child: SingleChildScrollView(
              controller: scrollController,

@coderof19clc7
Copy link
Author

ok, I will try out

@coderof19clc7
Copy link
Author

coderof19clc7 commented Apr 6, 2023

sorry for late reply, the scroll and render of your solution work really good, but when try to select the text in markdown, if I not hold into the text but the background instead, this exception occurs

======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 1194 pos 14: '!_selectionStartsInScrollable': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack:
#2 _ScrollableSelectionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/scrollable.dart:1194:14)
#3 MultiSelectableSelectionContainerDelegate.dispatchSelectionEvent (package:flutter/src/widgets/selectable_region.dart:2002:18)
#4 _SelectionContainerState.dispatchSelectionEvent (package:flutter/src/widgets/selection_container.dart:187:29)
#5 MultiSelectableSelectionContainerDelegate.dispatchSelectionEventToChild (package:flutter/src/widgets/selectable_region.dart:2056:23)
#6 _SelectableRegionContainerDelegate.dispatchSelectionEventToChild (package:flutter/src/widgets/selectable_region.dart:1370:18)
#7 MultiSelectableSelectionContainerDelegate._initSelection (package:flutter/src/widgets/selectable_region.dart:2077:43)
#8 MultiSelectableSelectionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/selectable_region.dart:1983:47)
#9 _SelectableRegionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/selectable_region.dart:1335:18)
#10 MultiSelectableSelectionContainerDelegate.dispatchSelectionEvent (package:flutter/src/widgets/selectable_region.dart:2002:18)
#11 _SelectionContainerState.dispatchSelectionEvent (package:flutter/src/widgets/selection_container.dart:187:29)
#12 SelectableRegionState._selectEndTo (package:flutter/src/widgets/selectable_region.dart:795:20)
#13 SelectableRegionState._handleTouchLongPressMoveUpdate (package:flutter/src/widgets/selectable_region.dart:479:5)
#14 LongPressGestureRecognizer._checkLongPressMoveUpdate. (package:flutter/src/gestures/long_press.dart:765:85)
#15 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
#16 LongPressGestureRecognizer._checkLongPressMoveUpdate (package:flutter/src/gestures/long_press.dart:765:11)
#17 LongPressGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/long_press.dart:655:9)
#18 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:615:9)
#19 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
#20 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:143:9)
#21 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#22 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#23 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
#24 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:460:19)
#25 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
#26 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:336:11)
#27 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
#28 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
#29 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
#30 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
#31 _invoke1 (dart:ui/hooks.dart:164:13)
#32 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:361:7)
#33 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:31)
(elided 2 frames from class _AssertionError)
Handler: "onLongPressMoveUpdate"
Recognizer: LongPressGestureRecognizer#1d7e0
debugOwner: SelectableRegionState#a4ff0
state: possible

@asjqkkkk
Copy link
Owner

asjqkkkk commented Apr 7, 2023

sorry for late reply, the scroll and render of your solution work really good, but when try to select the text in markdown, if I not hold into the text but the background instead, this exception occurs

======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 1194 pos 14: '!_selectionStartsInScrollable': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 _ScrollableSelectionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/scrollable.dart:1194:14)
#3 MultiSelectableSelectionContainerDelegate.dispatchSelectionEvent (package:flutter/src/widgets/selectable_region.dart:2002:18)
#4 _SelectionContainerState.dispatchSelectionEvent (package:flutter/src/widgets/selection_container.dart:187:29)
#5 MultiSelectableSelectionContainerDelegate.dispatchSelectionEventToChild (package:flutter/src/widgets/selectable_region.dart:2056:23)
#6 _SelectableRegionContainerDelegate.dispatchSelectionEventToChild (package:flutter/src/widgets/selectable_region.dart:1370:18)
#7 MultiSelectableSelectionContainerDelegate._initSelection (package:flutter/src/widgets/selectable_region.dart:2077:43)
#8 MultiSelectableSelectionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/selectable_region.dart:1983:47)
#9 _SelectableRegionContainerDelegate.handleSelectionEdgeUpdate (package:flutter/src/widgets/selectable_region.dart:1335:18)
#10 MultiSelectableSelectionContainerDelegate.dispatchSelectionEvent (package:flutter/src/widgets/selectable_region.dart:2002:18)
#11 _SelectionContainerState.dispatchSelectionEvent (package:flutter/src/widgets/selection_container.dart:187:29)
#12 SelectableRegionState._selectEndTo (package:flutter/src/widgets/selectable_region.dart:795:20)
#13 SelectableRegionState._handleTouchLongPressMoveUpdate (package:flutter/src/widgets/selectable_region.dart:479:5)
#14 LongPressGestureRecognizer._checkLongPressMoveUpdate. (package:flutter/src/gestures/long_press.dart:765:85)
#15 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
#16 LongPressGestureRecognizer._checkLongPressMoveUpdate (package:flutter/src/gestures/long_press.dart:765:11)
#17 LongPressGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/long_press.dart:655:9)
#18 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:615:9)
#19 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
#20 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:143:9)
#21 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#22 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#23 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
#24 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:460:19)
#25 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
#26 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:336:11)
#27 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
#28 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
#29 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
#30 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
#31 _invoke1 (dart:ui/hooks.dart:164:13)
#32 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:361:7)
#33 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:31)
(elided 2 frames from class _AssertionError)
Handler: "onLongPressMoveUpdate"
Recognizer: LongPressGestureRecognizer#1d7e0
debugOwner: SelectableRegionState#a4ff0
state: possible

Yes, it's the flutter issue flutter/flutter#115787
perhaps we need to wait for them to fix it

@coderof19clc7
Copy link
Author

got it, thanks so much for your support

@coderof19clc7
Copy link
Author

@asjqkkkk although this issue is completed but I want to ask 1 more question is that I saw that your package depends on visibility_detector package, what does that package do inside your package?

@asjqkkkk
Copy link
Owner

asjqkkkk commented Apr 8, 2023

@asjqkkkk although this issue is completed but I want to ask 1 more question is that I saw that your package depends on visibility_detector package, what does that package do inside your package?

It can detect if the headings in a Markdown document are visible or not, which can be used to implement a table of contents functionality.

@coderof19clc7
Copy link
Author

I see, thanks for your answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants