【问题标题】:Flutter : set background image for Painter classFlutter:为 Painter 类设置背景图像
【发布时间】:2019-03-25 23:08:01
【问题描述】:

我需要为Painter Widget 设置背景图像,因为我正在尝试构建一个小部件,以帮助孩子们在我的背景图像上绘制数字和字母。

这将是默认的小部件背景:

加载小部件后,孩子们应该能够在背景上绘画。

我尝试从官方 Painter 插件example 修改脚手架的主体,但图像没有出现在 Painter 的背景中,它只显示空白屏幕。

Container(
    decoration: new BoxDecoration(
      image: new DecorationImage(
        image: new ExactAssetImage('assets/test.png'),
        fit: BoxFit.cover,
      ),
    ),
    child: Painter(_controller),
  )

是否可以为 Painter 小部件设置背景图像?如果没有,还有其他解决方案可以帮助我完成任务吗?

【问题讨论】:

    标签: dart flutter background-image paint


    【解决方案1】:

    您只需为Painter 使用transparent 背景颜色

    PainterController _controller;
        @override
        void initState() {
          _controller = PainterController();
          _controller.thickness = 5.0;
          _controller.backgroundColor = Colors.transparent;
          super.initState();
        }
    

    就是这样。

    【讨论】:

    • 别担心,记得试着阅读你正在使用的库的源代码,看看它是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2015-01-24
    • 2015-12-12
    • 1970-01-01
    相关资源
    最近更新 更多