saminsohag

improved documentation and optimised code

  1 +## 0.0.5
  2 +
  3 +* Code optimized and documentation improved.
  4 +
1 ## 0.0.4 5 ## 0.0.4
2 6
3 * New line support added. 7 * New line support added.
@@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> { @@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> {
30 builder: (context, child) { 30 builder: (context, child) {
31 return TexText( 31 return TexText(
32 _text.text, 32 _text.text,
  33 + alignment: TexAlignment.start,
33 style: Theme.of(context) 34 style: Theme.of(context)
34 .textTheme 35 .textTheme
35 .titleLarge 36 .titleLarge
@@ -2,61 +2,89 @@ library tex_text; @@ -2,61 +2,89 @@ library tex_text;
2 2
3 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
4 import 'package:flutter_math_fork/flutter_math.dart'; 4 import 'package:flutter_math_fork/flutter_math.dart';
5 -export 'package:flutter_math_fork/flutter_math.dart'; 5 +export 'package:flutter_math_fork/flutter_math.dart' show MathStyle;
  6 +
  7 +enum TexAlignment {
  8 + /// [TexAlignment.start] aligns the words at the start of the text
  9 + start,
  10 +
  11 + /// It aligns the words at the end of the text
  12 + end,
  13 +
  14 + /// It aligns the words at the center of the text
  15 + center,
  16 +}
6 17
7 /// A LaTex text view. 18 /// A LaTex text view.
  19 +///
  20 +/// Example:
  21 +/// ```dart
  22 +/// TexText(r"The equation is <m>x^2+y^2=z^2<m>") //Output: The equation is <LaTex formatted equation>
  23 +///
  24 +/// // <m><m> shows <m> result
  25 +/// TexText(r"The equation is <m><m>") //Output: The equation is <m>
  26 +/// ```
8 class TexText extends StatelessWidget { 27 class TexText extends StatelessWidget {
9 const TexText(this.text, 28 const TexText(this.text,
10 {super.key, 29 {super.key,
11 this.style, 30 this.style,
12 this.mathStyle = MathStyle.display, 31 this.mathStyle = MathStyle.display,
13 - this.alignment = WrapAlignment.start}); 32 + this.alignment = TexAlignment.start});
14 final String text; 33 final String text;
15 final TextStyle? style; 34 final TextStyle? style;
16 final MathStyle mathStyle; 35 final MathStyle mathStyle;
17 - final WrapAlignment alignment; 36 + final TexAlignment alignment;
18 37
19 @override 38 @override
20 Widget build(BuildContext context) { 39 Widget build(BuildContext context) {
21 return Column( 40 return Column(
22 mainAxisSize: MainAxisSize.min, 41 mainAxisSize: MainAxisSize.min,
23 - crossAxisAlignment: CrossAxisAlignment.values[alignment.index % 3], 42 + crossAxisAlignment: CrossAxisAlignment.values[alignment.index],
24 children: text.split('\n').map<Widget>( 43 children: text.split('\n').map<Widget>(
25 (e) { 44 (e) {
26 return Wrap( 45 return Wrap(
27 - alignment: alignment, 46 + alignment: WrapAlignment.values[alignment.index],
28 crossAxisAlignment: WrapCrossAlignment.center, 47 crossAxisAlignment: WrapCrossAlignment.center,
29 spacing: 4, 48 spacing: 4,
30 children: e 49 children: e
31 .split("<m>") 50 .split("<m>")
32 .asMap() 51 .asMap()
33 - .map<int, List<Widget>>( 52 + .map<int, Iterable<Widget>>(
34 (index, e) { 53 (index, e) {
35 if (index.isOdd) { 54 if (index.isOdd) {
36 return MapEntry( 55 return MapEntry(
37 index, 56 index,
38 [ 57 [
39 - Math.tex(  
40 - e,  
41 - textStyle: style,  
42 - mathStyle: mathStyle,  
43 - ), 58 + if (e.isEmpty)
  59 + Text(
  60 + "<m>",
  61 + textAlign: TextAlign.values[alignment.index],
  62 + style: style,
  63 + )
  64 + else
  65 + Math.tex(
  66 + e,
  67 + textStyle: style,
  68 + mathStyle: mathStyle,
  69 + ),
44 ], 70 ],
45 ); 71 );
46 } 72 }
47 return MapEntry( 73 return MapEntry(
48 index, 74 index,
49 - e.split(" ").map<Widget>((e) {  
50 - return Text(  
51 - e,  
52 - style: style,  
53 - );  
54 - }).toList(), 75 + e.split(" ").map<Widget>(
  76 + (e) {
  77 + return Text(
  78 + e,
  79 + textAlign: TextAlign.values[alignment.index],
  80 + style: style,
  81 + );
  82 + },
  83 + ),
55 ); 84 );
56 }, 85 },
57 ) 86 )
58 .values 87 .values
59 - .toList()  
60 .expand<Widget>((element) => element) 88 .expand<Widget>((element) => element)
61 .toList(), 89 .toList(),
62 ); 90 );
1 name: tex_text 1 name: tex_text
2 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. 2 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.
3 -version: 0.0.4 3 +version: 0.0.5
4 homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_text 4 homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_text
5 5
6 environment: 6 environment:
@@ -17,39 +17,4 @@ dev_dependencies: @@ -17,39 +17,4 @@ dev_dependencies:
17 sdk: flutter 17 sdk: flutter
18 flutter_lints: ^2.0.0 18 flutter_lints: ^2.0.0
19 19
20 -# For information on the generic Dart part of this file, see the  
21 -# following page: https://dart.dev/tools/pub/pubspec  
22 -  
23 -# The following section is specific to Flutter packages.  
24 -flutter:  
25 -  
26 - # To add assets to your package, add an assets section, like this:  
27 - # assets:  
28 - # - images/a_dot_burr.jpeg  
29 - # - images/a_dot_ham.jpeg  
30 - #  
31 - # For details regarding assets in packages, see  
32 - # https://flutter.dev/assets-and-images/#from-packages  
33 - #  
34 - # An image asset can refer to one or more resolution-specific "variants", see  
35 - # https://flutter.dev/assets-and-images/#resolution-aware  
36 -  
37 - # To add custom fonts to your package, add a fonts section here,  
38 - # in this "flutter" section. Each entry in this list should have a  
39 - # "family" key with the font family name, and a "fonts" key with a  
40 - # list giving the asset and other descriptors for the font. For  
41 - # example:  
42 - # fonts:  
43 - # - family: Schyler  
44 - # fonts:  
45 - # - asset: fonts/Schyler-Regular.ttf  
46 - # - asset: fonts/Schyler-Italic.ttf  
47 - # style: italic  
48 - # - family: Trajan Pro  
49 - # fonts:  
50 - # - asset: fonts/TrajanPro.ttf  
51 - # - asset: fonts/TrajanPro_Bold.ttf  
52 - # weight: 700  
53 - #  
54 - # For details regarding fonts in packages, see  
55 - # https://flutter.dev/custom-fonts/#from-packages 20 +flutter: