znjameswu / flutter_math

Math rendering and editing in pure Flutter.
https://znjameswu.github.io/flutter_math_demo/
Apache License 2.0
123 stars 52 forks source link

Math.tex(r'\frac a b') will throws an error #18

Closed panmengma closed 3 years ago

panmengma commented 3 years ago

Math.tex(r'\frac a b'); Math.tex(r'\frac a b', mathStyle: MathStyle.display); Math.tex(r'\frac a b', mathStyle: MathStyle.text);

The above code all will throw a same error: NoSuchMethodError: The getter 'color' was called on null. Receiver: null Tried calling: color

My development environment is win10+vscode.

Skyost commented 3 years ago

I don't know if it's a bug or anything, but you have to pass a TextStyle with a non-null color :

Math.tex(r'\frac a b', textStyle: TextStyle(color: Colors.black));

panmengma commented 3 years ago

I don't know if it's a bug or anything, but you have to pass a TextStyle with a non-null color :

Math.tex(r'\frac a b', textStyle: TextStyle(color: Colors.black));

Thanks for your response.

I finally got the code running correctly following your suggestions.

What puzzles me is why the usage like Math.tex(r'\frac a b', mathStyle: MathStyle.display) , Math.tex(r'\frac a b',textStyle: TextStyle(fontSize: 42)) which is in the documentation will throws an error?

Skyost commented 3 years ago

Depends on your testing environment, I think. If you provide a default color to your app text style, then it's all good. Otherwise you will encounter this error (at least, that's what I understood from my investigations).

I could submit a pull request to fix this one as it doesn't seem to be too complicated.

panmengma commented 3 years ago

Depends on your testing environment, I think. If you provide a default color to your app text style, then it's all good. Otherwise you will encounter this error (at least, that's what I understood from my investigations).

I could submit a pull request to fix this one as it doesn't seem to be too complicated.

Yes, I agree with you.

And, Thanks for your work!

znjameswu commented 3 years ago

Sorry for the delay. Yeah, I can confirm confirm it is a bug. Thank you @Skyost !