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
2023-04-24 13:59:54 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
089357a44466fec5a690f352fb45dc6d3f73b01e
089357a4
1 parent
144362a6
bug fixed
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
151 additions
and
44 deletions
tex_markdown/example/lib/main.dart
tex_markdown/lib/custom_widgets/custom_divider.dart
tex_markdown/lib/custom_widgets/custom_error_image.dart
tex_markdown/lib/custom_widgets/custom_rb_cb.dart
tex_markdown/lib/markdown_component.dart
tex_markdown/lib/md_widget.dart
tex_markdown/example/lib/main.dart
View file @
089357a
...
...
@@ -16,7 +16,7 @@ class MyApp extends StatefulWidget {
}
class
_MyAppState
extends
State
<
MyApp
>
{
ThemeMode
_themeMode
=
ThemeMode
.
system
;
ThemeMode
_themeMode
=
ThemeMode
.
dark
;
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
...
...
@@ -37,7 +37,9 @@ class _MyAppState extends State<MyApp> {
title:
'Flutter Demo Home Page'
,
onPressed:
()
{
setState
(()
{
_themeMode
=
ThemeMode
.
values
[(
_themeMode
.
index
+
1
)
%
3
];
_themeMode
=
(
_themeMode
==
ThemeMode
.
dark
)
?
ThemeMode
.
light
:
ThemeMode
.
dark
;
});
},
),
...
...
@@ -107,6 +109,7 @@ $hello$
animation:
_controller
,
builder:
(
context
,
_
)
{
return
Material
(
color:
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
,
shape:
const
RoundedRectangleBorder
(
side:
BorderSide
(
width:
1
),
),
...
...
tex_markdown/lib/custom_widgets/custom_divider.dart
View file @
089357a
...
...
@@ -7,17 +7,14 @@ class CustomDivider extends LeafRenderObjectWidget {
@override
RenderObject
createRenderObject
(
BuildContext
context
)
{
return
RenderDivider
(
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
MediaQuery
.
of
(
context
).
size
.
width
,
height
??
2
);
return
RenderDivider
(
color
??
Theme
.
of
(
context
).
colorScheme
.
outline
,
MediaQuery
.
of
(
context
).
size
.
width
,
height
??
2
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderDivider
renderObject
)
{
renderObject
.
color
=
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
;
renderObject
.
color
=
color
??
Theme
.
of
(
context
).
colorScheme
.
outline
;
renderObject
.
height
=
height
??
2
;
renderObject
.
width
=
MediaQuery
.
of
(
context
).
size
.
width
;
}
...
...
tex_markdown/lib/custom_widgets/custom_error_image.dart
0 → 100644
View file @
089357a
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
class
CustomImageError
extends
LeafRenderObjectWidget
{
const
CustomImageError
({
super
.
key
,
this
.
iconColor
,
this
.
backgroundColor
,
this
.
outlineColor
,
});
final
Color
?
iconColor
;
final
Color
?
backgroundColor
;
final
Color
?
outlineColor
;
@override
RenderObject
createRenderObject
(
BuildContext
context
)
{
return
RenderCustomImageError
(
iconColor
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
backgroundColor
??
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
,
outlineColor
??
Theme
.
of
(
context
).
colorScheme
.
outline
,
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderCustomImageError
renderObject
)
{
renderObject
.
_backgroundColor
=
backgroundColor
??
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
;
renderObject
.
_iconColor
=
iconColor
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
;
renderObject
.
_outlineColor
=
outlineColor
??
Theme
.
of
(
context
).
colorScheme
.
outline
;
}
}
class
RenderCustomImageError
extends
RenderProxyBox
{
RenderCustomImageError
(
this
.
_iconColor
,
this
.
_backgroundColor
,
this
.
_outlineColor
);
Color
_iconColor
;
Color
_outlineColor
;
Color
_backgroundColor
;
set
iconColor
(
Color
value
)
{
if
(
value
==
_iconColor
)
{
return
;
}
_iconColor
=
value
;
markNeedsPaint
();
}
set
backgroundColor
(
Color
value
)
{
if
(
value
==
_backgroundColor
)
{
return
;
}
_backgroundColor
=
value
;
markNeedsPaint
();
}
set
outlineColor
(
Color
value
)
{
if
(
value
==
_outlineColor
)
{
return
;
}
_outlineColor
=
value
;
markNeedsPaint
();
}
@override
void
performLayout
()
{
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxWidth
,
80
),
min
(
constraints
.
maxHeight
,
80
)));
}
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
context
.
canvas
.
drawRect
(
offset
&
size
,
Paint
()..
color
=
_backgroundColor
,
);
context
.
canvas
.
drawRect
(
offset
&
size
,
Paint
()
..
style
=
PaintingStyle
.
stroke
..
color
=
_outlineColor
,
);
const
icon
=
Icons
.
image_not_supported
;
TextPainter
textPainter
=
TextPainter
(
textDirection:
TextDirection
.
rtl
);
textPainter
.
text
=
TextSpan
(
text:
String
.
fromCharCode
(
icon
.
codePoint
),
style:
TextStyle
(
fontSize:
min
(
min
(
size
.
width
,
size
.
height
),
35
),
fontFamily:
icon
.
fontFamily
,
color:
_iconColor
),
);
textPainter
.
layout
();
textPainter
.
paint
(
context
.
canvas
,
offset
+
Offset
(
size
.
width
/
2
-
textPainter
.
size
.
width
/
2
,
size
.
height
/
2
-
textPainter
.
size
.
height
/
2
),
);
}
}
...
...
tex_markdown/lib/custom_widgets/custom_rb_cb.dart
View file @
089357a
...
...
@@ -20,7 +20,12 @@ class CustomRb extends RenderObjectWidget
Widget
?
childForSlot
(
CustomRbSlot
slot
)
{
switch
(
slot
)
{
case
CustomRbSlot
.
rb
:
return
Radio
(
value:
value
,
groupValue:
true
,
onChanged:
(
value
)
{});
return
Radio
(
value:
value
,
groupValue:
true
,
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
,
onChanged:
(
value
)
{},
);
case
CustomRbSlot
.
child
:
return
child
;
}
...
...
@@ -69,7 +74,8 @@ class RenderCustomRb extends RenderBox
return
;
}
rb
;
Size
rbSize
=
_layoutBox
(
rb
!,
const
BoxConstraints
(
maxWidth:
50
));
Size
rbSize
=
_layoutBox
(
rb
!,
const
BoxConstraints
(
maxWidth:
50
,
maxHeight:
20
));
Size
bodySize
=
_layoutBox
(
body
!,
BoxConstraints
(
...
...
@@ -78,9 +84,10 @@ class RenderCustomRb extends RenderBox
..
offset
=
Offset
(
rbSize
.
width
+
_spacing
,
0
);
rb
!.
parentData
=
BoxParentData
()
..
offset
=
Offset
(
0
,
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
);
0
,
body
!.
computeDistanceToActualBaseline
(
TextBaseline
.
alphabetic
)!
-
rb
!.
size
.
height
/
1.5
,
);
size
=
constraints
.
constrain
(
Size
(
bodySize
.
width
+
rbSize
.
width
+
_spacing
,
max
(
rbSize
.
height
,
bodySize
.
height
)));
}
...
...
@@ -183,7 +190,8 @@ class RenderCustomCb extends RenderBox
return
;
}
rb
;
Size
rbSize
=
_layoutBox
(
rb
!,
const
BoxConstraints
(
maxWidth:
50
));
Size
rbSize
=
_layoutBox
(
rb
!,
const
BoxConstraints
(
maxWidth:
50
,
maxHeight:
20
));
Size
bodySize
=
_layoutBox
(
body
!,
BoxConstraints
(
...
...
tex_markdown/lib/markdown_component.dart
View file @
089357a
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:tex_markdown/custom_widgets/custom_divider.dart'
;
import
'package:tex_markdown/custom_widgets/custom_error_image.dart'
;
import
'package:tex_markdown/custom_widgets/custom_rb_cb.dart'
;
import
'package:tex_markdown/custom_widgets/unordered_ordered_list.dart'
;
import
'package:tex_text/tex_text.dart'
;
...
...
@@ -127,9 +130,10 @@ abstract class BlockMd extends MarkdownComponent {
return
TextSpan
(
children:
[
const
TextSpan
(
text:
"
\n
"
,
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
,
height:
0
,
),
),
WidgetSpan
(
...
...
@@ -137,14 +141,10 @@ abstract class BlockMd extends MarkdownComponent {
alignment:
PlaceholderAlignment
.
middle
,
),
const
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
),
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
,
height:
0
),
),
],
// child: Align(
// alignment: Alignment.centerLeft,
// child: build(context, text, style, onLinkTab),
// ),
);
}
...
...
@@ -202,15 +202,13 @@ class HTag extends BlockMd {
),
if
(
match
[
1
]!.
length
==
1
)
...[
const
TextSpan
(
text:
"
\n
"
,
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
,
height:
0
),
),
WidgetSpan
(
alignment:
PlaceholderAlignment
.
top
,
child:
CustomDivider
(
height:
2
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
outline
,
),
),
],
...
...
@@ -238,7 +236,7 @@ class HrLine extends BlockMd {
)
{
return
CustomDivider
(
height:
2
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
o
nSurfaceVariant
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
o
utline
,
);
}
...
...
@@ -518,13 +516,12 @@ class ImageMd extends InlineMd {
"
${match?[2]}
"
,
fit:
BoxFit
.
fill
,
errorBuilder:
(
context
,
error
,
stackTrace
)
{
return
Placeholder
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
,
child:
Text
(
"
${match?[2]}
\n
$error
"
,
style:
style
,
),
);
double
size
=
35
;
// if (height != null && width != null) {
size
=
min
(
size
,
height
??
size
);
size
=
min
(
size
,
width
??
size
);
// }
return
const
CustomImageError
();
},
),
),
...
...
tex_markdown/lib/md_widget.dart
View file @
089357a
...
...
@@ -53,16 +53,17 @@ $value
RegExp
(
r"\n\n+"
),
onMatch:
(
p0
)
{
list
.
add
(
const
TextSpan
(
text:
"
\n
"
),
const
TextSpan
(
text:
"
\n
\n
"
,
style:
TextStyle
(
fontSize:
16
)
),
);
return
""
;
},
onNonMatch:
(
eachLn
)
{
final
RegExp
table
=
RegExp
(
r"^(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)
?
$"
,
r"^(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)$"
,
);
if
(
table
.
hasMatch
(
eachLn
))
{
if
(
table
.
hasMatch
(
eachLn
.
trim
()
))
{
final
List
<
Map
<
int
,
String
>>
value
=
eachLn
.
trim
()
.
split
(
'
\n
'
)
.
map
<
Map
<
int
,
String
>>(
(
e
)
=>
e
...
...
@@ -84,8 +85,8 @@ $value
list
.
addAll
(
[
const
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
height:
0
),
text:
"
\n
"
,
style:
TextStyle
(
height:
0
,
fontSize:
0
),
),
WidgetSpan
(
child:
Table
(
...
...
@@ -115,14 +116,15 @@ $value
),
),
const
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
height:
0
),
text:
"
\n
"
,
style:
TextStyle
(
height:
0
,
fontSize:
0
),
),
],
);
}
else
{
list
.
addAll
(
MarkdownComponent
.
generate
(
context
,
eachLn
,
style
,
onLinkTab
),
MarkdownComponent
.
generate
(
context
,
eachLn
.
trim
(),
style
,
onLinkTab
),
);
}
return
""
;
...
...
@@ -144,9 +146,6 @@ class CustomTableColumnWidth extends TableColumnWidth {
each
.
layout
(
const
BoxConstraints
(),
parentUsesSize:
true
);
width
=
max
(
width
,
each
.
size
.
width
);
}
if
(
containerWidth
==
double
.
infinity
)
{
return
width
;
}
return
min
(
containerWidth
,
width
);
}
...
...
Please
register
or
login
to post a comment