Skip to content

Commit

Permalink
Use better library for latex views
Browse files Browse the repository at this point in the history
  • Loading branch information
paul019 committed Sep 18, 2024
1 parent d8a7e23 commit 1cd67be
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _IntegralsRowState extends State<IntegralsRow> {

return BasicWrapListItem(
item: integral != null
? LatexView(latex: integral.latexProblem, small: true)
? LatexView(latex: integral.latexProblem)
: Text(item),
showRemove: true,
onRemove: widget.enabled
Expand Down
18 changes: 16 additions & 2 deletions lib/screens/integrals_page/integral_add_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ class _IntegralAddDialogState extends State<IntegralAddDialog> {
width: 400,
child: Column(
children: [
Card(child: LatexView(latex: latexProblem)),
Card(
child: Container(
width: 400,
height: 150,
alignment: Alignment.center,
child: LatexView(latex: latexProblem),
),
),
TextField(
decoration: InputDecoration(
border: InputBorder.none,
Expand All @@ -133,7 +140,14 @@ class _IntegralAddDialogState extends State<IntegralAddDialog> {
width: 400,
child: Column(
children: [
Card(child: LatexView(latex: latexSolution)),
Card(
child: Container(
width: 400,
height: 150,
alignment: Alignment.center,
child: LatexView(latex: latexSolution),
),
),
TextField(
decoration: InputDecoration(
border: InputBorder.none,
Expand Down
12 changes: 10 additions & 2 deletions lib/screens/integrals_page/integral_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ class IntegralRow extends StatelessWidget {
Expanded(
flex: 3,
child: Card(
child: LatexView(latex: integral.latexProblem),
child: Container(
height: 150,
alignment: Alignment.center,
child: LatexView(latex: integral.latexProblem),
),
),
),

Expand All @@ -96,7 +100,11 @@ class IntegralRow extends StatelessWidget {
Expanded(
flex: 2,
child: Card(
child: LatexView(latex: integral.latexSolution),
child: Container(
height: 150,
alignment: Alignment.center,
child: LatexView(latex: integral.latexSolution),
),
),
),
],
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/mission_control_page/spare_integral_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:integration_bee_helper/models/integral_model/integral_model.dart';
import 'package:integration_bee_helper/services/basic_services/intl_service.dart';
import 'package:integration_bee_helper/widgets/latex_view.dart';
Expand Down Expand Up @@ -59,8 +60,10 @@ class _SpareIntegralDialogState extends State<SpareIntegralDialog> {
},
icon: const Icon(Icons.arrow_back_ios),
),
SizedBox(
Container(
width: 500,
height: 150,
alignment: Alignment.center,
child: LatexView(
latex: widget
.potentialSpareIntegrals[selectedIndex].latexProblem,
Expand Down
17 changes: 7 additions & 10 deletions lib/screens/presentation_screen/widgets/integral_view.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_tex/flutter_tex.dart';
import 'package:integration_bee_helper/models/agenda_item_model/problem_phase.dart';
import 'package:integration_bee_helper/models/basic_models/latex_expression.dart';
import 'package:integration_bee_helper/models/integral_model/integral_model.dart';
import 'package:integration_bee_helper/services/basic_services/intl_service.dart';
import 'package:integration_bee_helper/widgets/latex_view.dart';

class IntegralView extends StatelessWidget {
final IntegralModel? currentIntegral;
Expand All @@ -23,11 +24,11 @@ class IntegralView extends StatelessWidget {
case ProblemPhase.idle:
return '';
case ProblemPhase.showProblem:
return currentIntegral?.latexProblem.transformedWithDollarSigns ?? '';
return currentIntegral?.latexProblem.transformed ?? '';
case ProblemPhase.showSolution:
case ProblemPhase.showSolutionAndWinner:
return currentIntegral
?.latexProblemAndSolution.transformedWithDollarSigns ??
?.latexProblemAndSolution.transformed ??
'';
default:
return '';
Expand Down Expand Up @@ -63,13 +64,9 @@ class IntegralView extends StatelessWidget {
width: size.width,
height: size.height,
alignment: Alignment.center,
child: TeXView(
child: TeXViewDocument(
latex,
style: TeXViewStyle.fromCSS(
'padding: 5px; font-size: ${(_integralSize * p).toInt()}px',
),
),
child: LatexView(
latex: LatexExpression(latex),
fontSize: _integralSize * p,
),
);
}
Expand Down
24 changes: 10 additions & 14 deletions lib/widgets/latex_view.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter_tex/flutter_tex.dart';
import 'package:flutter_math_fork/flutter_math.dart';
import 'package:integration_bee_helper/models/basic_models/latex_expression.dart';

class LatexView extends StatelessWidget {
final LatexExpression latex;
final bool small;
final double fontSize;

const LatexView({super.key, required this.latex, this.small = false});
const LatexView({
super.key,
required this.latex,
this.fontSize = 16,
});

@override
Widget build(BuildContext context) {
return SizedBox(
height: small ? 50 : 150,
width: small ? 150 : null,
child: TeXView(
child: TeXViewDocument(
latex.transformedWithDollarSigns,
style: small
? const TeXViewStyle.fromCSS('padding: 5px; font-size: 8px;')
: const TeXViewStyle.fromCSS('padding: 5px;'),
),
),
return Math.tex(
latex.transformed,
textStyle: TextStyle(fontSize: fontSize),
);
}
}
48 changes: 48 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_math_fork:
dependency: "direct main"
description:
name: flutter_math_fork
sha256: "94bee4642892a94939af0748c6a7de0ff8318feee588379dcdfea7dc5cba06c8"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand All @@ -307,6 +315,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.19"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2"
url: "https://pub.dev"
source: hosted
version: "2.0.10+1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -541,6 +557,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
path_parsing:
dependency: transitive
description:
name: path_parsing
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
url: "https://pub.dev"
source: hosted
version: "1.0.1"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -810,6 +834,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.2.2"
vector_graphics:
dependency: transitive
description:
name: vector_graphics
sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3"
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
vector_graphics_codec:
dependency: transitive
description:
name: vector_graphics_codec
sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
vector_graphics_compiler:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81"
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
vector_math:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies:
image: ^4.2.0
image_picker: ^1.1.2
url_launcher: ^6.3.0
flutter_math_fork: ^0.7.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 1cd67be

Please sign in to comment.