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-25 00:18:43 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2154df5a7febcb7c0e6025ed91c4b11c868e5a15
2154df5a
1 parent
ee74e180
color bug fixed
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
189 additions
and
24 deletions
tex_markdown/CHANGELOG.md
tex_markdown/example/lib/main.dart
tex_markdown/example/pubspec.lock
tex_markdown/lib/custom_widgets/custom_error_image.dart
tex_markdown/lib/markdown_component.dart
tex_markdown/lib/md_widget.dart
tex_markdown/lib/tex_markdown.dart
tex_markdown/pubspec.yaml
tex_markdown/CHANGELOG.md
View file @
2154df5
## 0.1.7
*
Color bug fixed.
## 0.1.6
*
Engine improved.
...
...
tex_markdown/example/lib/main.dart
View file @
2154df5
...
...
@@ -3,7 +3,6 @@ import 'dart:io';
import
'package:file_picker/file_picker.dart'
;
import
'package:flutter/material.dart'
;
// import 'package:flutter/services.dart';
import
'package:tex_markdown/tex_markdown.dart'
;
import
'package:url_launcher/url_launcher_string.dart'
;
...
...
@@ -71,7 +70,7 @@ class _MyHomePageState extends State<MyHomePage> {
hello
---
my name is


**bold
$x
^2
\
cfrac a{
\
cfrac ab}
$
text**
*Italic text
$x
^2
\
cfrac a{b}
$
*
**hello**
...
...
tex_markdown/example/pubspec.lock
View file @
2154df5
...
...
@@ -491,7 +491,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.
6
"
version: "0.1.
7
"
tex_text:
dependency: transitive
description:
...
...
tex_markdown/lib/custom_widgets/custom_error_image.dart
View file @
2154df5
...
...
@@ -67,8 +67,22 @@ class RenderCustomImageError extends RenderProxyBox {
@override
void
performLayout
()
{
if
(
constraints
.
hasBoundedHeight
&&
constraints
.
hasBoundedWidth
)
{
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxWidth
,
constraints
.
maxHeight
),
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
)));
return
;
}
if
(
constraints
.
hasBoundedHeight
||
constraints
.
hasBoundedWidth
)
{
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
),
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
),
));
return
;
}
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxWidth
,
80
),
min
(
constraints
.
maxHeight
,
80
)));
const
Size
(
80
,
80
),
);
}
@override
...
...
@@ -101,3 +115,132 @@ class RenderCustomImageError extends RenderProxyBox {
);
}
}
class
CustomImageLoading
extends
LeafRenderObjectWidget
{
const
CustomImageLoading
({
super
.
key
,
this
.
iconColor
,
this
.
backgroundColor
,
this
.
outlineColor
,
this
.
progress
=
1
,
});
final
Color
?
iconColor
;
final
Color
?
backgroundColor
;
final
Color
?
outlineColor
;
final
double
progress
;
@override
RenderObject
createRenderObject
(
BuildContext
context
)
{
return
RenderCustomImageLoading
(
iconColor
??
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
backgroundColor
??
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
,
outlineColor
??
Theme
.
of
(
context
).
colorScheme
.
outline
,
progress
,
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderCustomImageLoading
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
;
renderObject
.
progress
=
progress
;
}
}
class
RenderCustomImageLoading
extends
RenderProxyBox
{
RenderCustomImageLoading
(
this
.
_iconColor
,
this
.
_backgroundColor
,
this
.
_outlineColor
,
this
.
_progress
);
Color
_iconColor
;
Color
_outlineColor
;
Color
_backgroundColor
;
double
_progress
;
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
();
}
set
progress
(
double
value
)
{
if
(
value
==
_progress
)
{
return
;
}
_progress
=
value
;
markNeedsPaint
();
}
@override
void
performLayout
()
{
if
(
constraints
.
hasBoundedHeight
&&
constraints
.
hasBoundedWidth
)
{
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxWidth
,
constraints
.
maxHeight
),
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
)));
return
;
}
if
(
constraints
.
hasBoundedHeight
||
constraints
.
hasBoundedWidth
)
{
size
=
constraints
.
constrain
(
Size
(
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
),
min
(
constraints
.
maxHeight
,
constraints
.
maxWidth
),
));
return
;
}
size
=
constraints
.
constrain
(
const
Size
(
80
,
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
;
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
();
context
.
canvas
.
drawRect
(
(
offset
+
Offset
(
0
,
size
.
height
-
5
))
&
Size
(
size
.
width
*
_progress
,
5
),
Paint
()..
color
=
_iconColor
);
textPainter
.
paint
(
context
.
canvas
,
offset
+
Offset
(
size
.
width
/
2
-
textPainter
.
size
.
width
/
2
,
size
.
height
/
2
-
textPainter
.
size
.
height
/
2
),
);
}
}
...
...
tex_markdown/lib/markdown_component.dart
View file @
2154df5
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'
;
...
...
@@ -72,19 +70,21 @@ abstract class MarkdownComponent {
}
else
{
if
(
each
is
BlockMd
)
{
spans
.
addAll
([
const
TextSpan
(
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
,
height:
0
,
color:
style
?.
color
,
),
),
each
.
span
(
context
,
element
.
trim
(),
style
,
onLinkTab
),
const
TextSpan
(
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
fontSize:
0
,
height:
0
,
color:
style
?.
color
,
),
),
]);
...
...
@@ -505,15 +505,24 @@ class ImageMd extends InlineMd {
child:
SizedBox
(
width:
width
,
height:
height
,
child:
Image
.
network
(
child:
Image
(
image:
NetworkImage
(
"
${match?[2]}
"
,
),
loadingBuilder:
(
BuildContext
context
,
Widget
child
,
ImageChunkEvent
?
loadingProgress
)
{
if
(
loadingProgress
==
null
)
{
return
child
;
}
return
CustomImageLoading
(
progress:
loadingProgress
.
expectedTotalBytes
!=
null
?
loadingProgress
.
cumulativeBytesLoaded
/
loadingProgress
.
expectedTotalBytes
!
:
1
,
);
},
fit:
BoxFit
.
fill
,
errorBuilder:
(
context
,
error
,
stackTrace
)
{
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 @
2154df5
...
...
@@ -53,7 +53,13 @@ $value
RegExp
(
r"\n\n+"
),
onMatch:
(
p0
)
{
list
.
add
(
const
TextSpan
(
text:
"
\n\n
"
,
style:
TextStyle
(
fontSize:
16
)),
TextSpan
(
text:
"
\n\n
"
,
style:
TextStyle
(
fontSize:
16
,
color:
style
?.
color
,
),
),
);
return
""
;
},
...
...
@@ -79,14 +85,11 @@ $value
maxCol
=
each
.
keys
.
length
;
}
}
// if (maxCol == 0) {
// return Text("", style: style);
// }
list
.
addAll
(
[
const
TextSpan
(
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
height:
0
,
fontSize:
0
),
style:
TextStyle
(
height:
0
,
fontSize:
0
,
color:
style
?.
color
),
),
WidgetSpan
(
child:
Table
(
...
...
@@ -114,9 +117,9 @@ $value
.
toList
(),
),
),
const
TextSpan
(
TextSpan
(
text:
"
\n
"
,
style:
TextStyle
(
height:
0
,
fontSize:
0
),
style:
TextStyle
(
height:
0
,
fontSize:
0
,
color:
style
?.
color
),
),
],
);
...
...
@@ -132,6 +135,7 @@ $value
return
Text
.
rich
(
TextSpan
(
children:
list
,
style:
style
,
),
);
}
...
...
tex_markdown/lib/tex_markdown.dart
View file @
2154df5
...
...
@@ -27,6 +27,12 @@ class TexMarkdown extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
return
ClipRRect
(
child:
MdWidget
(
data
.
trim
()));
return
ClipRRect
(
child:
MdWidget
(
data
.
trim
(),
style:
style
,
onLinkTab:
onLinkTab
,
followLinkColor:
followLinkColor
,
));
}
}
...
...
tex_markdown/pubspec.yaml
View file @
2154df5
name
:
tex_markdown
description
:
This package is used to create flutter widget that can render markdown and latex formulas. It is very simple to use and uses native flutter components.
version
:
0.1.
6
version
:
0.1.
7
homepage
:
https://github.com/saminsohag/flutter_packages/tree/main/tex_markdown
environment
:
...
...
Please
register
or
login
to post a comment