Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in version 4.0.10 #201

Closed
bsacetmukul opened this issue Dec 27, 2024 · 13 comments
Closed

Issue in version 4.0.10 #201

bsacetmukul opened this issue Dec 27, 2024 · 13 comments

Comments

@bsacetmukul
Copy link

../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/tex_rendering_server.dart:19:11: Error: Undefined name 'LocalHostServer'.
await LocalHostServer.start(port: port);
^^^^^^^^^^^^^^^
../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/tex_rendering_server.dart:20:14: Error: Undefined name 'LocalHostServer'.
server = LocalHostServer.server;
^^^^^^^^^^^^^^^
../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/tex_rendering_server.dart:65:11: Error: Undefined name 'LocalHostServer'.
await LocalHostServer.close();
^^^^^^^^^^^^^^^
../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/style_utils.dart:8:27: Error: The getter 'r' isn't defined for the class 'Color'.

  • 'Color' is from 'dart:ui'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'r'.
    return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${((color?.a ?? 0) * 255).toInt()})";
    ^
    ../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/style_utils.dart:8:63: Error: The getter 'g' isn't defined for the class 'Color'.
  • 'Color' is from 'dart:ui'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'g'.
    return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${((color?.a ?? 0) * 255).toInt()})";
    ^
    ../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/style_utils.dart:8:99: Error: The getter 'b' isn't defined for the class 'Color'.
  • 'Color' is from 'dart:ui'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'b'.
    return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${((color?.a ?? 0) * 255).toInt()})";
    ^
    ../.pub-cache/hosted/pub.dev/flutter_tex-4.0.10/lib/src/utils/style_utils.dart:8:135: Error: The getter 'a' isn't defined for the class 'Color'.
  • 'Color' is from 'dart:ui'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'a'.
    return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${((color?.a ?? 0) * 255).toInt()})";
    ^
    Target kernel_snapshot_program failed: Exception
@Shahxad-Akram
Copy link
Owner

Please do flutter clean and then use flutter_tex 4.0.12. Do refer to the updated example.

@programmeraditya
Copy link

I am getting the same issue on 4.0.12. Doing a flutter clean didn't solve it.

@Shahxad-Akram
Copy link
Owner

Please share a minimal example that I can try.

@duofingo
Copy link

duofingo commented Jan 2, 2025

the quiz example didn't work in my case. i copy pasted it with no changes made, but i'll just keep it here in case i accidentally did something.

import 'package:flutter/material.dart';
import 'package:flutter_tex/flutter_tex.dart';

class Quiz {
  final String statement;
  final List<QuizOption> options;
  final String correctOptionId;

  Quiz(
      {required this.statement,
      required this.options,
      required this.correctOptionId});
}

class QuizOption {
  final String id;
  final String option;

  QuizOption(this.id, this.option);
}

class TeXViewQuizExample extends StatefulWidget {
  const TeXViewQuizExample({super.key});

  @override
  State<TeXViewQuizExample> createState() => _TeXViewQuizExampleState();
}

class _TeXViewQuizExampleState extends State<TeXViewQuizExample> {
  int currentQuizIndex = 0;
  String selectedOptionId = "";
  bool isWrong = false;

  List<Quiz> quizList = [
    Quiz(
      statement: r"""<h3>What is the correct form of quadratic formula?</h3>""",
      options: [
        QuizOption(
          "id_1",
          r""" <h2>(A)   \(x = {-b \pm \sqrt{b^2+4ac} \over 2a}\)</h2>""",
        ),
        QuizOption(
          "id_2",
          r""" <h2>(B)   \(x = {b \pm \sqrt{b^2-4ac} \over 2a}\)</h2>""",
        ),
        QuizOption(
          "id_3",
          r""" <h2>(C)   \(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</h2>""",
        ),
        QuizOption(
          "id_4",
          r""" <h2>(D)   \(x = {-b + \sqrt{b^2+4ac} \over 2a}\)</h2>""",
        ),
      ],
      correctOptionId: "id_3",
    ),
    Quiz(
      statement:
          r"""<h3>Choose the correct mathematical form of Bohr's Radius.</h3>""",
      options: [
        QuizOption(
          "id_1",
          r""" <h2>(A)   \( a_0 = \frac{{\hbar ^2 }}{{m_e ke^2 }} \)</h2>""",
        ),
        QuizOption(
          "id_2",
          r""" <h2>(B)   \( a_0 = \frac{{\hbar ^2 }}{{m_e ke^3 }} \)</h2>""",
        ),
        QuizOption(
          "id_3",
          r""" <h2>(C)   \( a_0 = \frac{{\hbar ^3 }}{{m_e ke^2 }} \)</h2>""",
        ),
        QuizOption(
          "id_4",
          r""" <h2>(D)   \( a_0 = \frac{{\hbar }}{{m_e ke^2 }} \)</h2>""",
        ),
      ],
      correctOptionId: "id_1",
    ),
    Quiz(
      statement: r"""<h3>Select the correct Chemical Balanced Equation.</h3>""",
      options: [
        QuizOption(
          "id_1",
          r""" <h2>(A)   \( \ce{CO + C -> 2 CO} \)</h2>""",
        ),
        QuizOption(
          "id_2",
          r""" <h2>(B)   \( \ce{CO2 + C ->  CO} \)</h2>""",
        ),
        QuizOption(
          "id_3",
          r""" <h2>(C)   \( \ce{CO + C ->  CO} \)</h2>""",
        ),
        QuizOption(
          "id_4",
          r""" <h2>(D)   \( \ce{CO2 + C -> 2 CO} \)</h2>""",
        ),
      ],
      correctOptionId: "id_4",
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: const Text("TeXView Quiz"),
      ),
      body: ListView(
        physics: const ScrollPhysics(),
        children: <Widget>[
          Text(
            'Quiz ${currentQuizIndex + 1}/${quizList.length}',
            style: const TextStyle(fontSize: 20),
            textAlign: TextAlign.center,
          ),
          TeXView(
            child: TeXViewColumn(children: [
              TeXViewDocument(quizList[currentQuizIndex].statement,
                  style:
                      const TeXViewStyle(textAlign: TeXViewTextAlign.center)),
              TeXViewGroup(
                  children: quizList[currentQuizIndex]
                      .options
                      .map((QuizOption option) {
                    return TeXViewGroupItem(
                        rippleEffect: false,
                        id: option.id,
                        child: TeXViewDocument(option.option,
                            style: const TeXViewStyle(
                                padding: TeXViewPadding.all(10))));
                  }).toList(),
                  selectedItemStyle: TeXViewStyle(
                      borderRadius: const TeXViewBorderRadius.all(10),
                      border: TeXViewBorder.all(TeXViewBorderDecoration(
                          borderWidth: 3, borderColor: Colors.green[900])),
                      margin: const TeXViewMargin.all(10)),
                  normalItemStyle:
                      const TeXViewStyle(margin: TeXViewMargin.all(10)),
                  onTap: (id) {
                    selectedOptionId = id;
                    setState(() {
                      isWrong = false;
                    });
                  })
            ]),
            style: const TeXViewStyle(
              margin: TeXViewMargin.all(5),
              padding: TeXViewPadding.all(10),
              borderRadius: TeXViewBorderRadius.all(10),
              border: TeXViewBorder.all(
                TeXViewBorderDecoration(
                    borderColor: Colors.blue,
                    borderStyle: TeXViewBorderStyle.solid,
                    borderWidth: 5),
              ),
              backgroundColor: Colors.white,
            ),
            // loadingWidgetBuilder: (context) {
            //   return const Center(
            //     child: CircularProgressIndicator(),
            //   );
            // },
          ),
          if (isWrong)
            const Padding(
              padding: EdgeInsets.all(20),
              child: Text(
                "Wrong answer!!! Please choose a correct option.",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 18, color: Colors.red),
              ),
            ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              ElevatedButton(
                onPressed: () {
                  setState(() {
                    if (currentQuizIndex > 0) {
                      selectedOptionId = "";
                      currentQuizIndex--;
                    }
                  });
                },
                child: const Text("Previous"),
              ),
              ElevatedButton(
                onPressed: () {
                  setState(() {
                    if (selectedOptionId ==
                        quizList[currentQuizIndex].correctOptionId) {
                      selectedOptionId = "";
                      if (currentQuizIndex != quizList.length - 1) {
                        currentQuizIndex++;
                      }
                    } else {
                      isWrong = true;
                    }
                  });
                },
                child: const Text("Next"),
              ),
            ],
          )
        ],
      ),
    );
  }
}

error:

../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_tex-4.0.12/lib/src/utils/style_utils.dart:8:27: Error: The getter 'r' isn't defined for the class 'Color'.
 - 'Color' is from 'dart:ui'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'r'.
  return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${color?.a ?? 0})";
                          ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_tex-4.0.12/lib/src/utils/style_utils.dart:8:63: Error: The getter 'g' isn't defined for the class 'Color'.
 - 'Color' is from 'dart:ui'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'g'.
  return "rgba(${((color?.r ?? 0) * 255).toInt()}, ${((color?.g ?? 0) * 255).toInt()}, ${((color?.b ?? 0) * 255).toInt()}, ${color?.a ?? 0})";
                                                              ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_tex-4.0.12/lib/src/utils/style_utils.dart:8:99: Error: The getter 'b' isn't defined for the class 'Color'.

@deepakjoshi17
Copy link

deepakjoshi17 commented Jan 3, 2025

Any solutions here?
Using version: 4.0.12
Also i manually changed the r,g and b to red,green and blue respectively in file style_utils.dart, then the build works.
but still rendering fails.
Error:
PlatformException(FWFEvaluateJavaScriptError, Failed evaluating JavaScript., A JavaScript exception occurred (WKErrorDomain:4:{WKJavaScriptExceptionLineNumber: Unsupported Type: 1, WKJavaScriptExceptionMessage: ReferenceError: Can't find variable: initView, WKJavaScriptExceptionSourceURL: Unsupported Type: undefined, NSLocalizedDescription: A JavaScript exception occurred, WKJavaScriptExceptionColumnNumber: Unsupported Type: 9}), null)

@Shahxad-Akram
Copy link
Owner

Please update your Flutter SDK to at least 3.27.X. For more info have a look at these articles:

@RyanChan548
Copy link

I had the same issue, fixed by updating flutter, thanks

@deepakjoshi17
Copy link

deepakjoshi17 commented Jan 3, 2025

Upgraded to flutter 3.27.1,
the r,g,b issue got fixed, but rendering still fails.
Error same as above on iOS:
PlatformException(FWFEvaluateJavaScriptError, Failed evaluating JavaScript., A JavaScript exception occurred (WKErrorDomain:4:{WKJavaScriptExceptionLineNumber: Unsupported Type: 1, WKJavaScriptExceptionMessage: ReferenceError: Can't find variable: initView, WKJavaScriptExceptionSourceURL: Unsupported Type: undefined, NSLocalizedDescription: A JavaScript exception occurred, WKJavaScriptExceptionColumnNumber: Unsupported Type: 9}), null)as above:

PS. I did flutter clean, deleted derived data and updated pods and ran the build. Also created a new project and still same issue. Running on iOS

Screenshot 2025-01-04 at 2 32 38 AM

@Shahxad-Akram @RyanChan548

@RyanChan548
Copy link

Not sure if you your problem only happens on ios

If so please see Readme>How to use?>ios

@deepakjoshi17
Copy link

deepakjoshi17 commented Jan 3, 2025

@RyanChan548
It's working in web platform.
I have done the steps mentioned in README.
Added these lines in Info.plist:

<key>NSAppTransportSecurity</key>
<dict><key>NSAllowsArbitraryLoads</key> <true/>
</dict><key>io.flutter.embedded_views_preview</key> <true/> 

Is it working for you? if yes, which platform?

@RyanChan548
Copy link

I work on android
I see that your code is a small part of the project, maybe you didn't setup the rendering server before rendering. See readme>how to use>5.

@deepakjoshi17
Copy link

@RyanChan548
Yes that was the missing part.
Maybe they should add these changes to CHANGELOG.
Thanks a lot for pointing that out.
Now the rendering works fine.

But there is anotther crash which i was getting in older version as well because of which i updated the package.

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Invalid argument(s): Result of JavaScript execution returned a `null` value. Use `runJavascript` when expecting a null return value.
#0      WebKitWebViewController.runJavaScriptReturningResult (package:webview_flutter_wkwebview/src/webkit_webview_controller.dart:481:7)
<asynchronous suspension>
#1      TeXViewState._renderTeXView (package:flutter_tex/src/views/tex_view_mobile.dart:57:7)
Screenshot 2025-01-04 at 3 18 15 AM

This is inside the package, if i change the function to runJavascript as suggested in the error log, the error goes away.

If you have any idea on this, it will be really helpful. Otherwise i will have to mute this in crashlytics. Any suggestions are appreciated.

@Shahxad-Akram
Copy link
Owner

@deepakjoshi17 I don't see this issue on my side but I just updated it as mentioned, please update your package to 4.0.13, try and let me know.

PS: I assume you're facing this issue on iOS and I don't have a MAC machine so I can't verify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants