Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

dart - 如何在Flutter应用中正确管理全局textScaleFactor?(How to manage global textScaleFactor in Flutter app properly?)

Flutter apps react on system large text making all Text widgets really large.

(Flutter应用会对系统大文本做出反应,从而使所有“文本”小部件都非常大。)

I want to limit textScaleFactor for Text widgets but I want to do it globally not in each Text widget that I'am using.

(我想限制TextWidget的textScaleFactor,但我想在全局范围内而不是在我使用的每个Text窗口中进行操作。)

Now after enabling large text I got exceptions like

(现在启用大文本后,出现了类似的异常)

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ flutter: The following message was thrown during layout: flutter: A RenderFlex overflowed by 14 pixels on the bottom.

(颤抖:渲染库引起的异常╞═══════════════════════════════════════ ══════════════════抖动:在布局过程中引发了以下消息:抖动:RenderFlex在底部溢出了14个像素。)

What is proper way to do it?

(正确的做法是什么?)

One way is to create some wrapper widget instead of using Text, but maybe it can be solved other way?

(一种方法是创建一些包装器小部件而不是使用Text,但是也许可以用其他方法解决?)

图片1图片2

  ask by moonvader translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This solution was presented during Google IO 2019

(此解决方案是在Google IO 2019期间提出的)

MaterialApp(
 builder: (BuildContext context, Widget child) {
  final MediaQueryData data = MediaQuery.of(context);
  return MediaQuery(
   data: data.copyWith(
    textScaleFactor: data.textScaleFactor * (_isPassive ? 2 : 1)
   ),
   child: child
  );
 }
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...