首页 > 解决方案 > 在扩展小部件内使用颤振图表小部件

问题描述

这是我想要制作的 UI 的表示(请原谅粗略):

应用程序的线框

我打算将欢迎回复消息、最新阅读消息和图表都放在一个列中,并扩大图表以填满整个屏幕。这是我的组件树和到目前为止的构建方法:

@override
  Widget build(BuildContext context) {
    return Container(
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: _data == null || _data.length == 0
            ? Center(
                child: Text(
                  'No data, add data to get started',
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                ),
              )
            : Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "Welcome Back",
                    style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Text(
                    "Your latest reading was ${_data.last.systolic}/${_data.last.diastolic}.",
                    style: TextStyle(fontSize: 16),
                  ),
                  BPLineChart(data: _data),
                ],
              ),
      ),
    );

但是,如果我用扩展的小部件包装 BPLineChart,我会在控制台中收到此 ui 错误

I/flutter (11080): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (11080): The following assertion was thrown during performLayout():
I/flutter (11080): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
I/flutter (11080): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (11080): inside another render object that allows its children to pick their own size.

这在ui中:

设备上的错误截图

有没有办法用扩展的小部件包装颤振图表小部件?

标签: flutteruser-interfacedartchartsflutter-layout

解决方案


推荐阅读