首页 > 解决方案 > 如何在灯光模式下使用flutter_tex(Flutter)?

问题描述

我正在使用这个包flutter_tex 4.0.3,但我遇到了一个问题:如果我理解正确的话,flutter_tex 使用了一个 webview,显然当启用了 Android 的暗模式时,flutter webview 会强制使用暗模式。

更清楚地说,我如何在 light 模式下使用 flutter_tex ?如何在我使用的 Android 设备上启用 Flutter 中的暗模式?

这是我的代码:

class _Maths extends StatelessWidget {
  const _Maths({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const TeXView(
      renderingEngine: TeXViewRenderingEngine.katex(),
      child: TeXViewDocument(
        r"""<h3>$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</h3>""",
        style: TeXViewStyle(
          textAlign: TeXViewTextAlign.Center,
          backgroundColor: Colors.white, // still dark ;(
        ),
      ),
      style: TeXViewStyle(
        margin: TeXViewMargin.all(5),
        padding: TeXViewPadding.all(10),
        border: TeXViewBorder.all(
          TeXViewBorderDecoration(
            borderColor: Colors.blue,
            borderStyle: TeXViewBorderStyle.Solid,
            borderWidth: 1,
          ),
        ),
        backgroundColor: Colors.white, // still dark ;(
      ),
    );
  }
}

设置为“Colors.white”的“backgroundColor”属性不起作用,而它适用于任何其他颜色......

我尝试了以下“解决方案”:

<item name="android:forceDarkAllowed">false</item>
Theme(
   data: ThemeData.light(),
   child: TeXView(...),
),
void main() {
  // ...
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(statusBarBrightness: Brightness.light),
  );
}
MaterialApp(
   themeMode: ThemeMode.light,
   theme: ThemeData.light(),
   // ...
);

我完全迷路了。我的目标是在白色背景上显示一个方程,仅此而已,我想痛苦地尖叫......

结果:我的问题

注意:由于 null 安全性,flutter_tex 是我唯一可以使用的包。

请帮我

标签: androidflutterfrontendlatexlightmode

解决方案


推荐阅读