saminsohag

color bug fixed

## 0.1.7
* Color bug fixed.
## 0.1.6
* Engine improved.
... ...
... ... @@ -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
![100x100](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/800px-Image_created_with_a_mobile_phone.png)
![300](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/800px-Image_created_with_a_mobile_phone.png)
**bold$x^2\cfrac a{\cfrac ab}$ text**
*Italic text$x^2\cfrac a{b}$*
**hello**
... ...
... ... @@ -491,7 +491,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.6"
version: "0.1.7"
tex_text:
dependency: transitive
description:
... ...
... ... @@ -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),
);
}
}
... ...
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();
},
),
... ...
... ... @@ -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,
),
);
}
... ...
... ... @@ -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,
));
}
}
... ...
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:
... ...