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

Alignment in line breaking mode #29

Closed Skyost closed 3 years ago

Skyost commented 3 years ago

Hey,

I've followed the instructions here to implement the line breaking feature in my app. It really suits my needs, but there's a little caveat using a Wrap widget in order to display Tex break parts : some parts are not aligned. Here are some examples :

Screenshot_1 Screenshot_2 Screenshot_3

Is there a way to align the Math widgets in a Wrap ?

Thanks !

MuratovArthur commented 3 years ago

@Skyost

Hey!

I am a beginner in flutter, so I couldn't use the author's documentation to implement the line-breaking feature correctly. I have an error: Error: The method 'texBreak' isn't defined for the class 'Math'.

Could you help me? Could you share your code?

Skyost commented 3 years ago

@MuratovArthur You have to install the dev version from git (see here).

MuratovArthur commented 3 years ago

@Skyost

Hey!

Thank you for helping me!

I've tried to install the dev version from git, but it required to update some other packages. I've updated sdk to sdk: ">=2.6.0 <3.0.0", flutter_svg to flutter_svg: ^0.20.0-nullsafety.3.

After that, I've tried to run my app, but there was an error Error: Too few positional arguments: 8 required, 7 given. child: selectionControls!.buildToolbar(.

Did you face such an error?)

Skyost commented 3 years ago

@MuratovArthur Nope because I'm not using selectionControls.buildToolbar, but the error is only telling you that you're missing an argument at that line.

Skyost commented 3 years ago

I finally have some results using the following code :

@override
Widget build(BuildContext context) {
  Math math = Math.tex(input);

  List<Math> parts = math.texBreak().parts;
  if (parts.length == 1) {
    return parts.first;
  }

  return RichText(
    text: TextSpan(
      children: _handleParts(parts),
    ),
  );
}

List<InlineSpan> _handleParts(List<Math> parts) {
  List<InlineSpan> result = [];
  for (Math part in parts) {
    result.add(WidgetSpan(
      baseline: TextBaseline.alphabetic,
      alignment: PlaceholderAlignment.baseline,
      child: part,
    ));
    result.add(const TextSpan(
      text: ' ',
    ));
  }
  return result;
}

I don't think it's the best way to achieve this, but at least it works.

yavuztarhan commented 3 years ago

@MuratovArthur You have to install the dev version from git (see here). i tried add the package flutter_math_fork: ^0.3.0 like yours, it needs tuple 2.0.0(which depends quiver 2.0.0) but your pupspec.yaml not contains tuple, also google sign in depends quiver 3.0.0 , i am stuck

thanks, i solved ;

dependencies: quiver: ^2.0.0+1 dependency_overrides: quiver: "3.0.0"