saminsohag

bug fixed

@@ -16,7 +16,7 @@ class MyApp extends StatefulWidget { @@ -16,7 +16,7 @@ class MyApp extends StatefulWidget {
16 } 16 }
17 17
18 class _MyAppState extends State<MyApp> { 18 class _MyAppState extends State<MyApp> {
19 - ThemeMode _themeMode = ThemeMode.system; 19 + ThemeMode _themeMode = ThemeMode.dark;
20 @override 20 @override
21 Widget build(BuildContext context) { 21 Widget build(BuildContext context) {
22 return MaterialApp( 22 return MaterialApp(
@@ -37,7 +37,9 @@ class _MyAppState extends State<MyApp> { @@ -37,7 +37,9 @@ class _MyAppState extends State<MyApp> {
37 title: 'Flutter Demo Home Page', 37 title: 'Flutter Demo Home Page',
38 onPressed: () { 38 onPressed: () {
39 setState(() { 39 setState(() {
40 - _themeMode = ThemeMode.values[(_themeMode.index + 1) % 3]; 40 + _themeMode = (_themeMode == ThemeMode.dark)
  41 + ? ThemeMode.light
  42 + : ThemeMode.dark;
41 }); 43 });
42 }, 44 },
43 ), 45 ),
@@ -107,6 +109,7 @@ $hello$ @@ -107,6 +109,7 @@ $hello$
107 animation: _controller, 109 animation: _controller,
108 builder: (context, _) { 110 builder: (context, _) {
109 return Material( 111 return Material(
  112 + color: Theme.of(context).colorScheme.surfaceVariant,
110 shape: const RoundedRectangleBorder( 113 shape: const RoundedRectangleBorder(
111 side: BorderSide(width: 1), 114 side: BorderSide(width: 1),
112 ), 115 ),
@@ -7,17 +7,14 @@ class CustomDivider extends LeafRenderObjectWidget { @@ -7,17 +7,14 @@ class CustomDivider extends LeafRenderObjectWidget {
7 7
8 @override 8 @override
9 RenderObject createRenderObject(BuildContext context) { 9 RenderObject createRenderObject(BuildContext context) {
10 - return RenderDivider(  
11 - color ?? Theme.of(context).colorScheme.onSurfaceVariant,  
12 - MediaQuery.of(context).size.width,  
13 - height ?? 2); 10 + return RenderDivider(color ?? Theme.of(context).colorScheme.outline,
  11 + MediaQuery.of(context).size.width, height ?? 2);
14 } 12 }
15 13
16 @override 14 @override
17 void updateRenderObject( 15 void updateRenderObject(
18 BuildContext context, covariant RenderDivider renderObject) { 16 BuildContext context, covariant RenderDivider renderObject) {
19 - renderObject.color =  
20 - color ?? Theme.of(context).colorScheme.onSurfaceVariant; 17 + renderObject.color = color ?? Theme.of(context).colorScheme.outline;
21 renderObject.height = height ?? 2; 18 renderObject.height = height ?? 2;
22 renderObject.width = MediaQuery.of(context).size.width; 19 renderObject.width = MediaQuery.of(context).size.width;
23 } 20 }
  1 +import 'dart:math';
  2 +
  3 +import 'package:flutter/material.dart';
  4 +import 'package:flutter/rendering.dart';
  5 +
  6 +class CustomImageError extends LeafRenderObjectWidget {
  7 + const CustomImageError({
  8 + super.key,
  9 + this.iconColor,
  10 + this.backgroundColor,
  11 + this.outlineColor,
  12 + });
  13 + final Color? iconColor;
  14 + final Color? backgroundColor;
  15 + final Color? outlineColor;
  16 +
  17 + @override
  18 + RenderObject createRenderObject(BuildContext context) {
  19 + return RenderCustomImageError(
  20 + iconColor ?? Theme.of(context).colorScheme.onSurfaceVariant,
  21 + backgroundColor ?? Theme.of(context).colorScheme.surfaceVariant,
  22 + outlineColor ?? Theme.of(context).colorScheme.outline,
  23 + );
  24 + }
  25 +
  26 + @override
  27 + void updateRenderObject(
  28 + BuildContext context, covariant RenderCustomImageError renderObject) {
  29 + renderObject._backgroundColor =
  30 + backgroundColor ?? Theme.of(context).colorScheme.surfaceVariant;
  31 + renderObject._iconColor =
  32 + iconColor ?? Theme.of(context).colorScheme.onSurfaceVariant;
  33 + renderObject._outlineColor =
  34 + outlineColor ?? Theme.of(context).colorScheme.outline;
  35 + }
  36 +}
  37 +
  38 +class RenderCustomImageError extends RenderProxyBox {
  39 + RenderCustomImageError(
  40 + this._iconColor, this._backgroundColor, this._outlineColor);
  41 + Color _iconColor;
  42 + Color _outlineColor;
  43 + Color _backgroundColor;
  44 + set iconColor(Color value) {
  45 + if (value == _iconColor) {
  46 + return;
  47 + }
  48 + _iconColor = value;
  49 + markNeedsPaint();
  50 + }
  51 +
  52 + set backgroundColor(Color value) {
  53 + if (value == _backgroundColor) {
  54 + return;
  55 + }
  56 + _backgroundColor = value;
  57 + markNeedsPaint();
  58 + }
  59 +
  60 + set outlineColor(Color value) {
  61 + if (value == _outlineColor) {
  62 + return;
  63 + }
  64 + _outlineColor = value;
  65 + markNeedsPaint();
  66 + }
  67 +
  68 + @override
  69 + void performLayout() {
  70 + size = constraints.constrain(
  71 + Size(min(constraints.maxWidth, 80), min(constraints.maxHeight, 80)));
  72 + }
  73 +
  74 + @override
  75 + void paint(PaintingContext context, Offset offset) {
  76 + context.canvas.drawRect(
  77 + offset & size,
  78 + Paint()..color = _backgroundColor,
  79 + );
  80 + context.canvas.drawRect(
  81 + offset & size,
  82 + Paint()
  83 + ..style = PaintingStyle.stroke
  84 + ..color = _outlineColor,
  85 + );
  86 + const icon = Icons.image_not_supported;
  87 + TextPainter textPainter = TextPainter(textDirection: TextDirection.rtl);
  88 + textPainter.text = TextSpan(
  89 + text: String.fromCharCode(icon.codePoint),
  90 + style: TextStyle(
  91 + fontSize: min(min(size.width, size.height), 35),
  92 + fontFamily: icon.fontFamily,
  93 + color: _iconColor),
  94 + );
  95 + textPainter.layout();
  96 + textPainter.paint(
  97 + context.canvas,
  98 + offset +
  99 + Offset(size.width / 2 - textPainter.size.width / 2,
  100 + size.height / 2 - textPainter.size.height / 2),
  101 + );
  102 + }
  103 +}
@@ -20,7 +20,12 @@ class CustomRb extends RenderObjectWidget @@ -20,7 +20,12 @@ class CustomRb extends RenderObjectWidget
20 Widget? childForSlot(CustomRbSlot slot) { 20 Widget? childForSlot(CustomRbSlot slot) {
21 switch (slot) { 21 switch (slot) {
22 case CustomRbSlot.rb: 22 case CustomRbSlot.rb:
23 - return Radio(value: value, groupValue: true, onChanged: (value) {}); 23 + return Radio(
  24 + value: value,
  25 + groupValue: true,
  26 + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  27 + onChanged: (value) {},
  28 + );
24 case CustomRbSlot.child: 29 case CustomRbSlot.child:
25 return child; 30 return child;
26 } 31 }
@@ -69,7 +74,8 @@ class RenderCustomRb extends RenderBox @@ -69,7 +74,8 @@ class RenderCustomRb extends RenderBox
69 return; 74 return;
70 } 75 }
71 rb; 76 rb;
72 - Size rbSize = _layoutBox(rb!, const BoxConstraints(maxWidth: 50)); 77 + Size rbSize =
  78 + _layoutBox(rb!, const BoxConstraints(maxWidth: 50, maxHeight: 20));
73 Size bodySize = _layoutBox( 79 Size bodySize = _layoutBox(
74 body!, 80 body!,
75 BoxConstraints( 81 BoxConstraints(
@@ -80,7 +86,8 @@ class RenderCustomRb extends RenderBox @@ -80,7 +86,8 @@ class RenderCustomRb extends RenderBox
80 ..offset = Offset( 86 ..offset = Offset(
81 0, 87 0,
82 body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - 88 body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! -
83 - rb!.size.height / 1.5); 89 + rb!.size.height / 1.5,
  90 + );
84 size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing, 91 size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing,
85 max(rbSize.height, bodySize.height))); 92 max(rbSize.height, bodySize.height)));
86 } 93 }
@@ -183,7 +190,8 @@ class RenderCustomCb extends RenderBox @@ -183,7 +190,8 @@ class RenderCustomCb extends RenderBox
183 return; 190 return;
184 } 191 }
185 rb; 192 rb;
186 - Size rbSize = _layoutBox(rb!, const BoxConstraints(maxWidth: 50)); 193 + Size rbSize =
  194 + _layoutBox(rb!, const BoxConstraints(maxWidth: 50, maxHeight: 20));
187 Size bodySize = _layoutBox( 195 Size bodySize = _layoutBox(
188 body!, 196 body!,
189 BoxConstraints( 197 BoxConstraints(
  1 +import 'dart:math';
  2 +
1 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
2 import 'package:tex_markdown/custom_widgets/custom_divider.dart'; 4 import 'package:tex_markdown/custom_widgets/custom_divider.dart';
  5 +import 'package:tex_markdown/custom_widgets/custom_error_image.dart';
3 import 'package:tex_markdown/custom_widgets/custom_rb_cb.dart'; 6 import 'package:tex_markdown/custom_widgets/custom_rb_cb.dart';
4 import 'package:tex_markdown/custom_widgets/unordered_ordered_list.dart'; 7 import 'package:tex_markdown/custom_widgets/unordered_ordered_list.dart';
5 import 'package:tex_text/tex_text.dart'; 8 import 'package:tex_text/tex_text.dart';
@@ -127,9 +130,10 @@ abstract class BlockMd extends MarkdownComponent { @@ -127,9 +130,10 @@ abstract class BlockMd extends MarkdownComponent {
127 return TextSpan( 130 return TextSpan(
128 children: [ 131 children: [
129 const TextSpan( 132 const TextSpan(
130 - text: "\n", 133 + text: "\n ",
131 style: TextStyle( 134 style: TextStyle(
132 fontSize: 0, 135 fontSize: 0,
  136 + height: 0,
133 ), 137 ),
134 ), 138 ),
135 WidgetSpan( 139 WidgetSpan(
@@ -137,14 +141,10 @@ abstract class BlockMd extends MarkdownComponent { @@ -137,14 +141,10 @@ abstract class BlockMd extends MarkdownComponent {
137 alignment: PlaceholderAlignment.middle, 141 alignment: PlaceholderAlignment.middle,
138 ), 142 ),
139 const TextSpan( 143 const TextSpan(
140 - text: "\n",  
141 - style: TextStyle(fontSize: 0), 144 + text: "\n ",
  145 + style: TextStyle(fontSize: 0, height: 0),
142 ), 146 ),
143 ], 147 ],
144 - // child: Align(  
145 - // alignment: Alignment.centerLeft,  
146 - // child: build(context, text, style, onLinkTab),  
147 - // ),  
148 ); 148 );
149 } 149 }
150 150
@@ -202,15 +202,13 @@ class HTag extends BlockMd { @@ -202,15 +202,13 @@ class HTag extends BlockMd {
202 ), 202 ),
203 if (match[1]!.length == 1) ...[ 203 if (match[1]!.length == 1) ...[
204 const TextSpan( 204 const TextSpan(
205 - text: "\n", 205 + text: "\n ",
206 style: TextStyle(fontSize: 0, height: 0), 206 style: TextStyle(fontSize: 0, height: 0),
207 ), 207 ),
208 WidgetSpan( 208 WidgetSpan(
209 - alignment: PlaceholderAlignment.top,  
210 child: CustomDivider( 209 child: CustomDivider(
211 height: 2, 210 height: 2,
212 - color: style?.color ??  
213 - Theme.of(context).colorScheme.onSurfaceVariant, 211 + color: style?.color ?? Theme.of(context).colorScheme.outline,
214 ), 212 ),
215 ), 213 ),
216 ], 214 ],
@@ -238,7 +236,7 @@ class HrLine extends BlockMd { @@ -238,7 +236,7 @@ class HrLine extends BlockMd {
238 ) { 236 ) {
239 return CustomDivider( 237 return CustomDivider(
240 height: 2, 238 height: 2,
241 - color: style?.color ?? Theme.of(context).colorScheme.onSurfaceVariant, 239 + color: style?.color ?? Theme.of(context).colorScheme.outline,
242 ); 240 );
243 } 241 }
244 242
@@ -518,13 +516,12 @@ class ImageMd extends InlineMd { @@ -518,13 +516,12 @@ class ImageMd extends InlineMd {
518 "${match?[2]}", 516 "${match?[2]}",
519 fit: BoxFit.fill, 517 fit: BoxFit.fill,
520 errorBuilder: (context, error, stackTrace) { 518 errorBuilder: (context, error, stackTrace) {
521 - return Placeholder(  
522 - color: Theme.of(context).colorScheme.error,  
523 - child: Text(  
524 - "${match?[2]}\n$error",  
525 - style: style,  
526 - ),  
527 - ); 519 + double size = 35;
  520 + // if (height != null && width != null) {
  521 + size = min(size, height ?? size);
  522 + size = min(size, width ?? size);
  523 + // }
  524 + return const CustomImageError();
528 }, 525 },
529 ), 526 ),
530 ), 527 ),
@@ -53,16 +53,17 @@ $value @@ -53,16 +53,17 @@ $value
53 RegExp(r"\n\n+"), 53 RegExp(r"\n\n+"),
54 onMatch: (p0) { 54 onMatch: (p0) {
55 list.add( 55 list.add(
56 - const TextSpan(text: "\n"), 56 + const TextSpan(text: "\n\n", style: TextStyle(fontSize: 16)),
57 ); 57 );
58 return ""; 58 return "";
59 }, 59 },
60 onNonMatch: (eachLn) { 60 onNonMatch: (eachLn) {
61 final RegExp table = RegExp( 61 final RegExp table = RegExp(
62 - r"^(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)?$", 62 + r"^(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)$",
63 ); 63 );
64 - if (table.hasMatch(eachLn)) { 64 + if (table.hasMatch(eachLn.trim())) {
65 final List<Map<int, String>> value = eachLn 65 final List<Map<int, String>> value = eachLn
  66 + .trim()
66 .split('\n') 67 .split('\n')
67 .map<Map<int, String>>( 68 .map<Map<int, String>>(
68 (e) => e 69 (e) => e
@@ -84,8 +85,8 @@ $value @@ -84,8 +85,8 @@ $value
84 list.addAll( 85 list.addAll(
85 [ 86 [
86 const TextSpan( 87 const TextSpan(
87 - text: "\n",  
88 - style: TextStyle(height: 0), 88 + text: "\n ",
  89 + style: TextStyle(height: 0, fontSize: 0),
89 ), 90 ),
90 WidgetSpan( 91 WidgetSpan(
91 child: Table( 92 child: Table(
@@ -115,14 +116,15 @@ $value @@ -115,14 +116,15 @@ $value
115 ), 116 ),
116 ), 117 ),
117 const TextSpan( 118 const TextSpan(
118 - text: "\n",  
119 - style: TextStyle(height: 0), 119 + text: "\n ",
  120 + style: TextStyle(height: 0, fontSize: 0),
120 ), 121 ),
121 ], 122 ],
122 ); 123 );
123 } else { 124 } else {
124 list.addAll( 125 list.addAll(
125 - MarkdownComponent.generate(context, eachLn, style, onLinkTab), 126 + MarkdownComponent.generate(
  127 + context, eachLn.trim(), style, onLinkTab),
126 ); 128 );
127 } 129 }
128 return ""; 130 return "";
@@ -144,9 +146,6 @@ class CustomTableColumnWidth extends TableColumnWidth { @@ -144,9 +146,6 @@ class CustomTableColumnWidth extends TableColumnWidth {
144 each.layout(const BoxConstraints(), parentUsesSize: true); 146 each.layout(const BoxConstraints(), parentUsesSize: true);
145 width = max(width, each.size.width); 147 width = max(width, each.size.width);
146 } 148 }
147 - if (containerWidth == double.infinity) {  
148 - return width;  
149 - }  
150 return min(containerWidth, width); 149 return min(containerWidth, width);
151 } 150 }
152 151