Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
gpt_markdown
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
saminsohag
2024-01-20 15:31:16 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
14162f13d6e9a5fd6660e1166c274dc49d624862
14162f13
1 parent
d3deb040
textDirection is added to all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
10 deletions
tex_markdown/example/lib/main.dart
tex_markdown/lib/custom_widgets/custom_rb_cb.dart
tex_markdown/lib/custom_widgets/unordered_ordered_list.dart
tex_markdown/lib/markdown_component.dart
tex_markdown/example/lib/main.dart
View file @
14162f1
...
...
@@ -60,6 +60,7 @@ class MyHomePage extends StatefulWidget {
}
class
_MyHomePageState
extends
State
<
MyHomePage
>
{
TextDirection
_direction
=
TextDirection
.
ltr
;
final
TextEditingController
_controller
=
TextEditingController
(
text:
r''
'
# hi how are you?
$my
is^2
$
## hi how are you
$
(
\
frac ab)^2
$
?
...
...
@@ -97,6 +98,14 @@ $hello$
title:
Text
(
widget
.
title
),
actions:
[
IconButton
(
onPressed:
()
{
setState
(()
{
_direction
=
TextDirection
.
values
[(
_direction
.
index
+
1
)
%
2
];
});
},
icon:
const
[
Text
(
"LTR"
),
Text
(
"RTL"
)][
_direction
.
index
],
),
IconButton
(
onPressed:
widget
.
onPressed
,
icon:
const
Icon
(
Icons
.
sunny
),
),
...
...
@@ -123,9 +132,12 @@ $hello$
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
reverse:
_direction
==
TextDirection
.
rtl
,
child:
SizedBox
(
width:
400
,
child:
TexMarkdown
(
_controller
.
text
,
textDirection:
TextDirection
.
rtl
,
textDirection:
_direction
,
onLinkTab:
(
url
,
title
)
{
log
(
title
,
name:
"title"
);
log
(
url
,
name:
"url"
);
...
...
@@ -134,6 +146,7 @@ $hello$
// color: Colors.green,
),
),
),
);
}),
);
...
...
tex_markdown/lib/custom_widgets/custom_rb_cb.dart
View file @
14162f1
...
...
@@ -10,11 +10,17 @@ enum CustomRbSlot {
class
CustomRb
extends
SlottedMultiChildRenderObjectWidget
<
CustomRbSlot
,
RenderBox
>
{
const
CustomRb
(
{
super
.
key
,
this
.
spacing
=
5
,
required
this
.
child
,
required
this
.
value
});
const
CustomRb
({
super
.
key
,
this
.
spacing
=
5
,
required
this
.
child
,
this
.
textDirection
=
TextDirection
.
ltr
,
required
this
.
value
,
});
final
Widget
child
;
final
bool
value
;
final
double
spacing
;
final
TextDirection
textDirection
;
@override
Widget
?
childForSlot
(
CustomRbSlot
slot
)
{
...
...
@@ -34,13 +40,14 @@ class CustomRb
@override
SlottedContainerRenderObjectMixin
<
CustomRbSlot
,
RenderBox
>
createRenderObject
(
BuildContext
context
)
{
return
RenderCustomRb
(
spacing
);
return
RenderCustomRb
(
spacing
,
textDirection
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderCustomRb
renderObject
)
{
renderObject
.
spacing
=
spacing
;
renderObject
.
textDirection
=
textDirection
;
}
@override
...
...
@@ -49,8 +56,17 @@ class CustomRb
class
RenderCustomRb
extends
RenderBox
with
SlottedContainerRenderObjectMixin
<
CustomRbSlot
,
RenderBox
>
{
RenderCustomRb
(
this
.
_spacing
);
RenderCustomRb
(
this
.
_spacing
,
this
.
_textDirection
);
double
_spacing
;
TextDirection
_textDirection
;
set
textDirection
(
TextDirection
value
)
{
if
(
_textDirection
==
value
)
{
return
;
}
_textDirection
=
value
;
markNeedsLayout
();
}
set
spacing
(
double
value
)
{
if
(
_spacing
==
value
)
{
return
;
...
...
@@ -80,6 +96,7 @@ class RenderCustomRb extends RenderBox
body
!,
BoxConstraints
(
maxWidth:
constraints
.
maxWidth
-
rbSize
.
width
-
_spacing
));
if
(
_textDirection
==
TextDirection
.
ltr
)
{
body
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
rbSize
.
width
+
_spacing
,
0
);
rb
!.
parentData
=
BoxParentData
()
...
...
@@ -88,6 +105,15 @@ class RenderCustomRb extends RenderBox
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
,
);
}
else
{
body
!.
parentData
=
BoxParentData
()..
offset
=
Offset
(-
_spacing
,
0
);
rb
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
bodySize
.
width
,
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
,
);
}
size
=
constraints
.
constrain
(
Size
(
bodySize
.
width
+
rbSize
.
width
+
_spacing
,
max
(
rbSize
.
height
,
bodySize
.
height
)));
}
...
...
@@ -132,8 +158,13 @@ enum CustomCbSlot {
class
CustomCb
extends
SlottedMultiChildRenderObjectWidget
<
CustomCbSlot
,
RenderBox
>
{
const
CustomCb
(
{
super
.
key
,
this
.
spacing
=
5
,
required
this
.
child
,
required
this
.
value
});
{
super
.
key
,
this
.
spacing
=
5
,
this
.
textDirection
=
TextDirection
.
ltr
,
required
this
.
child
,
required
this
.
value
});
final
Widget
child
;
final
TextDirection
textDirection
;
final
bool
value
;
final
double
spacing
;
...
...
@@ -150,13 +181,14 @@ class CustomCb
@override
SlottedContainerRenderObjectMixin
<
CustomCbSlot
,
RenderBox
>
createRenderObject
(
BuildContext
context
)
{
return
RenderCustomCb
(
spacing
);
return
RenderCustomCb
(
spacing
,
textDirection
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderCustomCb
renderObject
)
{
renderObject
.
spacing
=
spacing
;
renderObject
.
textDirection
=
textDirection
;
}
@override
...
...
@@ -165,8 +197,17 @@ class CustomCb
class
RenderCustomCb
extends
RenderBox
with
SlottedContainerRenderObjectMixin
<
CustomCbSlot
,
RenderBox
>
{
RenderCustomCb
(
this
.
_spacing
);
RenderCustomCb
(
this
.
_spacing
,
this
.
_textDirection
);
double
_spacing
;
TextDirection
_textDirection
;
set
textDirection
(
TextDirection
value
)
{
if
(
_textDirection
==
value
)
{
return
;
}
_textDirection
=
value
;
markNeedsLayout
();
}
set
spacing
(
double
value
)
{
if
(
_spacing
==
value
)
{
return
;
...
...
@@ -196,6 +237,7 @@ class RenderCustomCb extends RenderBox
body
!,
BoxConstraints
(
maxWidth:
constraints
.
maxWidth
-
rbSize
.
width
-
_spacing
));
if
(
_textDirection
==
TextDirection
.
ltr
)
{
body
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
rbSize
.
width
+
_spacing
,
0
);
rb
!.
parentData
=
BoxParentData
()
...
...
@@ -203,6 +245,14 @@ class RenderCustomCb extends RenderBox
0
,
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
);
}
else
{
body
!.
parentData
=
BoxParentData
()..
offset
=
Offset
(-
_spacing
,
0
);
rb
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
bodySize
.
width
,
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
);
}
size
=
constraints
.
constrain
(
Size
(
bodySize
.
width
+
rbSize
.
width
+
_spacing
,
max
(
rbSize
.
height
,
bodySize
.
height
)));
}
...
...
tex_markdown/lib/custom_widgets/unordered_ordered_list.dart
View file @
14162f1
...
...
@@ -8,10 +8,12 @@ class UnorderedListView extends SingleChildRenderObjectWidget {
this
.
padding
=
10
,
this
.
bulletColor
,
this
.
bulletSize
=
4
,
this
.
textDirection
=
TextDirection
.
ltr
,
required
super
.
child
});
final
double
bulletSize
;
final
double
spacing
;
final
double
padding
;
final
TextDirection
textDirection
;
final
Color
?
bulletColor
;
@override
...
...
@@ -20,6 +22,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget {
spacing
,
padding
,
bulletColor
??
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
textDirection
,
bulletSize
,
);
}
...
...
@@ -32,6 +35,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget {
renderObject
.
bulletSize
=
bulletSize
;
renderObject
.
spacing
=
spacing
;
renderObject
.
padding
=
padding
;
renderObject
.
textDirection
=
textDirection
;
}
}
...
...
@@ -40,15 +44,18 @@ class UnorderedListRenderObject extends RenderProxyBox {
double
spacing
,
double
padding
,
Color
bulletColor
,
TextDirection
textDirection
,
this
.
_bulletSize
,
{
RenderBox
?
child
,
})
:
_bulletColor
=
bulletColor
,
_spacing
=
spacing
,
_padding
=
padding
,
_textDirection
=
textDirection
,
super
(
child
);
double
_spacing
;
double
_padding
;
Offset
_bulletOffset
=
Offset
.
zero
;
TextDirection
_textDirection
;
set
spacing
(
double
value
)
{
if
(
_spacing
==
value
)
{
return
;
...
...
@@ -65,6 +72,15 @@ class UnorderedListRenderObject extends RenderProxyBox {
markNeedsLayout
();
}
set
textDirection
(
TextDirection
value
)
{
if
(
_textDirection
==
value
)
{
return
;
}
_textDirection
=
value
;
markNeedsLayout
();
markNeedsPaint
();
}
Color
_bulletColor
;
double
_bulletSize
;
set
bulletSize
(
double
value
)
{
...
...
@@ -139,10 +155,20 @@ class UnorderedListRenderObject extends RenderProxyBox {
constraints
.
maxWidth
-
_spacing
-
6
-
_bulletSize
-
_padding
,
),
parentUsesSize:
true
);
if
(
_textDirection
==
TextDirection
.
ltr
)
{
child
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
_spacing
+
_padding
+
6
+
_bulletSize
,
0
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
_bulletOffset
=
Offset
(
4
+
_padding
,
value
!
-
_bulletSize
);
}
else
{
child
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(-
_spacing
-
_padding
+
6
+
_bulletSize
,
0
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
_bulletOffset
=
Offset
(
child
!.
size
.
width
-
4
+
_padding
,
value
!
-
_bulletSize
);
}
size
=
constraints
.
constrain
(
Size
(
child
!.
size
.
width
+
_spacing
+
_padding
+
6
+
_bulletSize
,
child
!.
size
.
height
));
...
...
@@ -153,11 +179,18 @@ class UnorderedListRenderObject extends RenderProxyBox {
if
(
child
==
null
)
{
return
;
}
if
(
_textDirection
==
TextDirection
.
ltr
)
{
context
.
paintChild
(
child
!,
offset
+
(
child
!.
parentData
as
BoxParentData
).
offset
);
context
.
canvas
.
drawCircle
(
offset
+
_bulletOffset
,
_bulletSize
,
Paint
()..
color
=
_bulletColor
);
}
else
{
context
.
paintChild
(
child
!,
offset
+
(
child
!.
parentData
as
BoxParentData
).
offset
);
context
.
canvas
.
drawCircle
(
offset
+
_bulletOffset
,
_bulletSize
,
Paint
()..
color
=
_bulletColor
);
}
}
}
class
OrderedListView
extends
SingleChildRenderObjectWidget
{
...
...
@@ -170,9 +203,11 @@ class OrderedListView extends SingleChildRenderObjectWidget {
this
.
padding
=
10
,
TextStyle
?
style
,
required
super
.
child
,
this
.
textDirection
=
TextDirection
.
ltr
,
required
this
.
no
})
:
_style
=
style
;
final
TextStyle
?
_style
;
final
TextDirection
textDirection
;
TextStyle
getStyle
(
BuildContext
context
)
{
if
(
_style
==
null
||
_style
!.
inherit
)
{
...
...
@@ -187,6 +222,7 @@ class OrderedListView extends SingleChildRenderObjectWidget {
no
,
spacing
,
padding
,
textDirection
,
getStyle
(
context
),
);
}
...
...
@@ -198,6 +234,7 @@ class OrderedListView extends SingleChildRenderObjectWidget {
renderObject
.
spacing
=
spacing
;
renderObject
.
padding
=
padding
;
renderObject
.
style
=
getStyle
(
context
);
renderObject
.
textDirection
=
textDirection
;
}
}
...
...
@@ -206,15 +243,18 @@ class OrderedListRenderObject extends RenderProxyBox {
String
no
,
double
spacing
,
double
padding
,
TextDirection
textDirection
,
TextStyle
style
,
{
RenderBox
?
child
,
})
:
_no
=
no
,
_style
=
style
,
_spacing
=
spacing
,
_padding
=
padding
,
_textDirection
=
textDirection
,
super
(
child
);
double
_spacing
;
double
_padding
;
TextDirection
_textDirection
;
Offset
_ptOffset
=
Offset
.
zero
;
set
spacing
(
double
value
)
{
if
(
_spacing
==
value
)
{
...
...
@@ -232,6 +272,15 @@ class OrderedListRenderObject extends RenderProxyBox {
markNeedsLayout
();
}
set
textDirection
(
TextDirection
value
)
{
if
(
_textDirection
==
value
)
{
return
;
}
_textDirection
=
value
;
markNeedsLayout
();
markNeedsPaint
();
}
TextStyle
_style
;
set
style
(
TextStyle
value
)
{
_style
=
value
;
...
...
@@ -292,11 +341,21 @@ class OrderedListRenderObject extends RenderProxyBox {
maxWidth:
constraints
.
maxWidth
-
pt
.
width
-
_spacing
-
_padding
,
),
parentUsesSize:
true
);
if
(
_textDirection
==
TextDirection
.
ltr
)
{
child
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
_spacing
+
_padding
+
pt
.
width
,
0
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
_ptOffset
=
Offset
(
_padding
,
value
!
-
pt
.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
));
}
else
{
child
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(-
_spacing
-
_padding
+
pt
.
width
,
0
);
var
value
=
child
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
);
_ptOffset
=
Offset
(
child
!.
size
.
width
+
_padding
-
4
,
value
!
-
pt
.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
));
}
size
=
constraints
.
constrain
(
Size
(
child
!.
size
.
width
+
_spacing
+
_padding
+
pt
.
width
,
child
!.
size
.
height
));
...
...
tex_markdown/lib/markdown_component.dart
View file @
14162f1
...
...
@@ -275,6 +275,7 @@ class CheckBoxMd extends BlockMd {
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomCb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
onLinkTab:
onLinkTab
,
...
...
@@ -309,6 +310,7 @@ class RadioButtonMd extends BlockMd {
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomRb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
onLinkTab:
onLinkTab
,
...
...
@@ -343,6 +345,7 @@ class UnOrderedList extends BlockMd {
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
UnorderedListView
(
bulletColor:
style
?.
color
,
textDirection:
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
onLinkTab:
onLinkTab
,
...
...
@@ -380,6 +383,7 @@ class OrderedList extends BlockMd {
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
OrderedListView
(
no:
"
${match?[1]}
"
,
textDirection:
textDirection
,
style:
(
style
??
const
TextStyle
()).
copyWith
(
fontWeight:
FontWeight
.
bold
),
child:
MdWidget
(
"
${match?[2]}
"
,
...
...
Please
register
or
login
to post a comment