【问题标题】:showing error while creating a button widget创建按钮小部件时显示错误
【发布时间】:2023-02-03 16:08:41
【问题描述】:

这里 CuButton 显示错误。我还创建了相同的小部件但没有显示错误但在这种情况下它显示错误

` 小部件 CuBUtton({

    String name = "button",
    Color color = Colors.blueGrey,
    double H = 10,
    double W = 10,
    required Function function,
    required TextStyle Labelstyl}) {
    try {
      return
        InkWell(onTap: () {
          function();
        },
          child: Container(color: color,
            height: H, width: W,
            child: Center(child:
            Text(name,style: Labelstyl,)),),
        );
    } catch (e) {
      print("Error on Button $e");
    }
  }`

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    function 中删除所需的 keyword

    Widget CuButton({
        String name = "button",
        Color color = Colors.blueGrey,
        double H = 10,
        double W = 10,
        Function function,
        TextStyle Labelstyl}) {
      try {
        return InkWell(
          onTap: () {
            function();
          },
          child: Container(
            color: color,
            height: H,
            width: W,
            child: Center(
              child: Text(name, style: Labelstyl),
            ),
          ),
        );
      } catch (e) {
        print("Error on Button $e");
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-11
      相关资源
      最近更新 更多