Flutter For Web 关于Overflow on channel: flutter/platform 的解决方案

1,205

最近在用flutter开发web界面,出现了这个问题。

Overflow on channel: flutter/platform.  Messages on this channel are being discarded in FIFO fashion.  The engine may not be running or you need to adjust the buffer size if of the channel.

看了github上的42880 issues,说是channel的问题,会在将来更改,但是我仔细观察了一下之后,发现并不是,而是跟状态栏属性更改有关。

解决方案

一、brightness

找到项目中AppBar有使用到更改状态栏字体颜色的地方,如下

AppBar(
  brightness: Brightness.light,
);

改成

AppBar(
  brightness: kIsWeb ? null : Brightness.light,
);

二、AnnotatedRegion

as we know 这玩意也是用来改状态栏颜色的地方

AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark, 
)

当在web中,就不用就完事了。 比如这样。

Widget build(BuildContext context) {
    return kIsWeb
        ? mainWidgets
        : AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark, child: mainWidgets);
  }