How to add custom values in inside expression in flutter math_fork library

155 Views Asked by At
class ResultPage extends StatefulWidget {
    DataModel dataModel;
    ResultPage({Key? key, required this.dataModel}) : super(key: key);

    @override
    _ResultPageState createState() => _ResultPageState();
}

class _ResultPageState extends State<ResultPage> {
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: Math.tex("m=/frac "${widget.datamodel.value}"")
        );
    }
}

but the math.tex is showing error in flutter how to pass custom values in any equation

2

There are 2 best solutions below

0
Ali Hassan On BEST ANSWER
class ResultPage extends StatefulWidget {
  DataModel dataModel;
   ResultPage({Key? key, required this.dataModel}) : super(key: key);

  @override
   _ResultPageState createState() => _ResultPageState();
    }

    class _ResultPageState extends State<ResultPage> {
           @override
    Widget build(BuildContext context) {
     return Scaffold( 
  body:Math.tex(
            "m = ${r'\frac'} {${widget.datamodel.value1}} 
               {$widget.datamodel.value2}",
            textStyle: textStyle,
          ),

    );}}

that is how you can add custom values in the equation in flutter math_fork

1
KuKu On

The 'Scaffold' need to have a 'body'. Try to add 'Math.text' under 'body'.

Here is a package's sample code that use 'Math.tex'.
https://github.com/simpleclub-extended/flutter_math_fork/blob/9015c77bc79f5e21820de3c927f43ff275b35078/test/helper.dart#L30

https://github.com/simpleclub-extended/flutter_math_fork/blob/9015c77bc79f5e21820de3c927f43ff275b35078/example/lib/display.dart#L29

class ResultPage extends StatefulWidget {
    DataModel dataModel;
    ResultPage({Key? key, required this.dataModel}) : super(key: key);

    @override
    _ResultPageState createState() => _ResultPageState();
}

class _ResultPageState extends State<ResultPage> {
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: Math.tex("m=/frac "${widget.datamodel.value}"")
        );
    }
}