saminsohag

improved documentation and optimised code

## 0.0.5
* Code optimized and documentation improved.
## 0.0.4
* New line support added.
... ...
... ... @@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> {
builder: (context, child) {
return TexText(
_text.text,
alignment: TexAlignment.start,
style: Theme.of(context)
.textTheme
.titleLarge
... ...
... ... @@ -2,40 +2,66 @@ library tex_text;
import 'package:flutter/material.dart';
import 'package:flutter_math_fork/flutter_math.dart';
export 'package:flutter_math_fork/flutter_math.dart';
export 'package:flutter_math_fork/flutter_math.dart' show MathStyle;
enum TexAlignment {
/// [TexAlignment.start] aligns the words at the start of the text
start,
/// It aligns the words at the end of the text
end,
/// It aligns the words at the center of the text
center,
}
/// A LaTex text view.
///
/// Example:
/// ```dart
/// TexText(r"The equation is <m>x^2+y^2=z^2<m>") //Output: The equation is <LaTex formatted equation>
///
/// // <m><m> shows <m> result
/// TexText(r"The equation is <m><m>") //Output: The equation is <m>
/// ```
class TexText extends StatelessWidget {
const TexText(this.text,
{super.key,
this.style,
this.mathStyle = MathStyle.display,
this.alignment = WrapAlignment.start});
this.alignment = TexAlignment.start});
final String text;
final TextStyle? style;
final MathStyle mathStyle;
final WrapAlignment alignment;
final TexAlignment alignment;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.values[alignment.index % 3],
crossAxisAlignment: CrossAxisAlignment.values[alignment.index],
children: text.split('\n').map<Widget>(
(e) {
return Wrap(
alignment: alignment,
alignment: WrapAlignment.values[alignment.index],
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4,
children: e
.split("<m>")
.asMap()
.map<int, List<Widget>>(
.map<int, Iterable<Widget>>(
(index, e) {
if (index.isOdd) {
return MapEntry(
index,
[
if (e.isEmpty)
Text(
"<m>",
textAlign: TextAlign.values[alignment.index],
style: style,
)
else
Math.tex(
e,
textStyle: style,
... ... @@ -46,17 +72,19 @@ class TexText extends StatelessWidget {
}
return MapEntry(
index,
e.split(" ").map<Widget>((e) {
e.split(" ").map<Widget>(
(e) {
return Text(
e,
textAlign: TextAlign.values[alignment.index],
style: style,
);
}).toList(),
},
),
);
},
)
.values
.toList()
.expand<Widget>((element) => element)
.toList(),
);
... ...
name: tex_text
description: This package for Flutter allows you to show text on a Flutter app with LaTex math formula and normal text from string. It is vary easy to use and works for all of the platforms.
version: 0.0.4
version: 0.0.5
homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_text
environment:
... ... @@ -17,39 +17,4 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
\ No newline at end of file
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
... ...