saminsohag

Scrolling feature of block type latex added

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_math_fork/flutter_math.dart';
import 'package:gpt_markdown/gpt_markdown.dart';
void main() {
... ... @@ -134,8 +135,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
width: 1,
color: Theme.of(context).colorScheme.outline),
),
child:
LayoutBuilder(builder: (context, constraints) {
child: LayoutBuilder(builder: (context, constraints) {
return Theme(
data: Theme.of(context).copyWith(
textTheme: const TextTheme(
... ... @@ -167,15 +167,24 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
// Regular text font size here.
fontSize: 15,
),
latexWorkaround: (tex) =>
tex.replaceAllMapped(RegExp(r"align\*"),
(match) => "aligned"),
latexWorkaround: (tex) => tex.replaceAllMapped(
RegExp(r"align\*"), (match) => "aligned"),
latexBuilder: (contex, tex) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Math.tex(
tex,
textStyle: const TextStyle(fontSize: 17),
),
);
},
),
// child: const Text("Hello"),
);
}),
);
}),
},
),
],
),
),
... ...
... ... @@ -143,7 +143,7 @@ packages:
source: hosted
version: "2.0.3"
flutter_math_fork:
dependency: transitive
dependency: "direct main"
description:
name: flutter_math_fork
sha256: "94bee4642892a94939af0748c6a7de0ff8318feee588379dcdfea7dc5cba06c8"
... ...
... ... @@ -20,6 +20,7 @@ dependencies:
path_provider: ^2.0.14
permission_handler: ^10.2.0
file_picker: ^5.2.10
flutter_math_fork: ^0.7.2
dev_dependencies:
flutter_test:
... ...
... ... @@ -16,6 +16,7 @@ class TexMarkdown extends StatelessWidget {
this.textAlign,
this.textScaler,
this.onLinkTab,
this.latexBuilder,
});
final TextDirection textDirection;
final String data;
... ... @@ -24,6 +25,7 @@ class TexMarkdown extends StatelessWidget {
final TextScaler? textScaler;
final void Function(String url, String title)? onLinkTab;
final String Function(String tex)? latexWorkaround;
final Widget Function(BuildContext context, String tex)? latexBuilder;
final bool followLinkColor;
@override
... ... @@ -38,6 +40,7 @@ class TexMarkdown extends StatelessWidget {
textScaler: textScaler,
followLinkColor: followLinkColor,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
));
}
}
... ...
... ... @@ -32,6 +32,7 @@ abstract class MarkdownComponent {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
List<InlineSpan> spans = [];
List<String> regexes =
... ... @@ -57,6 +58,7 @@ abstract class MarkdownComponent {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
));
} else {
if (each is BlockMd) {
... ... @@ -76,6 +78,7 @@ abstract class MarkdownComponent {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
),
TextSpan(
text: "\n ",
... ... @@ -114,6 +117,7 @@ abstract class MarkdownComponent {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
);
RegExp get exp;
... ... @@ -133,6 +137,7 @@ abstract class InlineMd extends MarkdownComponent {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
);
}
... ... @@ -148,6 +153,7 @@ abstract class BlockMd extends MarkdownComponent {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
return WidgetSpan(
child: build(
... ... @@ -157,6 +163,7 @@ abstract class BlockMd extends MarkdownComponent {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
),
alignment: PlaceholderAlignment.middle,
);
... ... @@ -169,6 +176,7 @@ abstract class BlockMd extends MarkdownComponent {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
);
}
... ... @@ -184,6 +192,7 @@ class HTag extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return Text.rich(
... ... @@ -221,6 +230,7 @@ class HTag extends BlockMd {
textDirection,
(url, title) {},
latexWorkaround,
latexBuilder,
)),
if (match[1]!.length == 1) ...[
const TextSpan(
... ... @@ -259,6 +269,7 @@ class HrLine extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
return CustomDivider(
height: 2,
... ... @@ -281,6 +292,7 @@ class CheckBoxMd extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return CustomCb(
... ... @@ -292,6 +304,7 @@ class CheckBoxMd extends BlockMd {
textDirection: textDirection,
style: style,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
),
);
}
... ... @@ -311,6 +324,7 @@ class RadioButtonMd extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return CustomRb(
... ... @@ -322,6 +336,7 @@ class RadioButtonMd extends BlockMd {
textDirection: textDirection,
style: style,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
),
);
}
... ... @@ -341,6 +356,7 @@ class IndentMd extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
[
r"\\\[(.*?)\\\]",
... ... @@ -356,14 +372,8 @@ class IndentMd extends BlockMd {
textDirection: textDirection,
child: RichText(
text: TextSpan(
children: MarkdownComponent.generate(
context,
"${match?[2]}",
style,
textDirection,
onLinkTab,
latexWorkaround,
),
children: MarkdownComponent.generate(context, "${match?[2]}", style,
textDirection, onLinkTab, latexWorkaround, latexBuilder),
)),
);
}
... ... @@ -383,6 +393,7 @@ class UnOrderedList extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text);
return UnorderedListView(
... ... @@ -396,6 +407,7 @@ class UnOrderedList extends BlockMd {
textDirection: textDirection,
style: style,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
),
);
}
... ... @@ -416,6 +428,7 @@ class OrderedList extends BlockMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return OrderedListView(
... ... @@ -428,6 +441,7 @@ class OrderedList extends BlockMd {
textDirection: textDirection,
style: style,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
),
);
}
... ... @@ -446,6 +460,7 @@ class BoldMd extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return TextSpan(
... ... @@ -457,6 +472,7 @@ class BoldMd extends InlineMd {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
),
style: style?.copyWith(fontWeight: FontWeight.bold) ??
const TextStyle(fontWeight: FontWeight.bold),
... ... @@ -479,16 +495,16 @@ class LatexMathMultyLine extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var p0 = exp.firstMatch(text.trim());
p0?.group(0);
String mathText = p0?[1] ?? p0?[2] ?? "";
var workaround = latexWorkaround ?? (String tex) => tex;
return WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: Math.tex(
workaround(mathText),
var builder = latexBuilder ??
(BuildContext context, String tex) => Math.tex(
workaround(tex),
textStyle: style?.copyWith(
fontFamily: "SansSerif",
),
... ... @@ -518,12 +534,17 @@ class LatexMathMultyLine extends InlineMd {
return Text(
workaround(mathText),
textDirection: textDirection,
style:
style?.copyWith(color: Theme.of(context).colorScheme.error) ??
style: style?.copyWith(
color: Theme.of(context).colorScheme.error) ??
TextStyle(color: Theme.of(context).colorScheme.error),
);
},
),
);
return WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: builder(context, mathText),
);
}
}
... ... @@ -547,6 +568,7 @@ class LatexMath extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var p0 = exp.firstMatch(text.trim());
p0?.group(0);
... ... @@ -609,6 +631,7 @@ class ItalicMd extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
return TextSpan(
... ... @@ -619,6 +642,7 @@ class ItalicMd extends InlineMd {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
),
style: (style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic),
);
... ... @@ -638,6 +662,7 @@ class ATagMd extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
if (match?[1] == null && match?[2] == null) {
... ... @@ -682,6 +707,7 @@ class ImageMd extends InlineMd {
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
var match = exp.firstMatch(text.trim());
double? height;
... ... @@ -733,6 +759,7 @@ class TableMd extends BlockMd {
TextDirection textDirection,
void Function(String url, String title)? onLinkTab,
final String Function(String tex)? latexWorkaround,
final Widget Function(BuildContext context, String tex)? latexBuilder,
) {
final List<Map<int, String>> value = text
.split('\n')
... ...
... ... @@ -13,6 +13,7 @@ class MdWidget extends StatelessWidget {
this.textAlign,
this.textScaler,
this.latexWorkaround,
this.latexBuilder,
this.followLinkColor = false});
final String exp;
final TextDirection textDirection;
... ... @@ -21,6 +22,7 @@ class MdWidget extends StatelessWidget {
final TextScaler? textScaler;
final void Function(String url, String title)? onLinkTab;
final String Function(String tex)? latexWorkaround;
final Widget Function(BuildContext context, String tex)? latexBuilder;
final bool followLinkColor;
@override
... ... @@ -94,6 +96,7 @@ class MdWidget extends StatelessWidget {
onLinkTab: onLinkTab,
style: style,
latexWorkaround: latexWorkaround,
latexBuilder: latexBuilder,
),
);
},
... ... @@ -128,6 +131,7 @@ class MdWidget extends StatelessWidget {
textDirection,
onLinkTab,
latexWorkaround,
latexBuilder,
),
);
}
... ...