Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行 flutter pub run build_runner build 报错 #14

Closed
SionChen opened this issue Jan 11, 2021 · 22 comments
Closed

执行 flutter pub run build_runner build 报错 #14

SionChen opened this issue Jan 11, 2021 · 22 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@SionChen
Copy link

image

@avenwu
Copy link
Contributor

avenwu commented Jan 11, 2021

贴一下doctor信息

@SionChen
Copy link
Author

image

@avenwu
Copy link
Contributor

avenwu commented Jan 11, 2021

错误原因是无法创建编译中间产物,没有权限。
可以flutter clean后,清除.dart_tool文件试试。
另外使用的是自带demo还是?

把更多的runner编译日志发一下,看看是哪一步权限问题

@SionChen
Copy link
Author

这个问题flutter clean之后就解决了。又出现了另一个问题 budle过程farmat错误,我这个widght是可以跑起来的,是fair语法哪里用错了吗?
image
就像这样相应的地方我已经加了
image

@avenwu
Copy link
Contributor

avenwu commented Jan 11, 2021

@SionChen 恭喜你进入接入流程了

budle过程farmat错误 => bundle构建过程format错误?

该问题一般是由于build函数中出现了不支持的语法格式;导致进行代码格式化时出现异常。

这个widght是可以跑起来的

指的是原生运行ok对吧?原生ok的情况下,根据错误日志提示,定位出语法问题,进行组件封装或者引用替换即可。具体示例可以参考example,里面有多重业务场景的替换方法(不唯一)。如果不介意,也可把这个widget的代码贴出来,帮你分析下。

@SionChen
Copy link
Author

import 'package:flutter/material.dart';
import 'package:guangshop_flutter_module/components/home_goods_tab_indicator.dart';
import 'dart:math';
import 'package:fair/fair.dart';

@FairPatch()
class HomeTabGoodsView extends StatefulWidget {
  @override
  _HomeTabGoodsViewState createState() => _HomeTabGoodsViewState();
}

class _HomeTabGoodsViewState extends State<HomeTabGoodsView>
    with SingleTickerProviderStateMixin {
  @FairWell('_scrollViewController')
  ScrollController _scrollViewController;
  @FairWell('_tabController')
  TabController _tabController;
  @FairWell('_tabs')
  List<String> _tabs = ['综合', '佣金', '销量', '销量'];
  @FairWell('_myColor')
  Color _myColor = Colors.red;
  @override
  void initState() {
    super.initState();
    _scrollViewController = ScrollController(initialScrollOffset: 0.0);
    _tabController = TabController(vsync: this, length: _tabs.length);
    _tabController.addListener(() {
      if (_tabController.indexIsChanging) {
        setState(() {
          _myColor = Color.fromARGB(255, Random().nextInt(256) + 0,
              Random().nextInt(256) + 0, Random().nextInt(256) + 0);
        });
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
    _scrollViewController.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _buildGoodsTab();
  }

  // 构建商品tab
  @FairWell('_buildGoodsTab')
  Widget _buildGoodsTab() {
    return Column(children: [
      _buildGoodsTabBar(),
      Column(
        children: [
          _buildListitemView(),
          Container(
            color: _myColor,
            height: 1000,
          ),
        ],
      )
    ]);
  }

  @FairWell('_buildGoodsTabBar')
  Widget _buildGoodsTabBar() {
    return Column(
      children: [
        SizedBox(
          height: 5,
        ),
        Row(
          children: [
            Expanded(
              child: TabBar(
                indicator: AGBubbleTabIndicator(
                    insets: EdgeInsets.symmetric(horizontal: 5)),
                // indicator: BubbleTabIndicator(indicatorHeight: 25),
                // isScrollable: true,
                controller: _tabController,
                tabs: _tabs.map((e) => _buildTabItem(e)).toList(),
                // labelPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
                labelColor: Colors.black,
              ),
            ),
            GestureDetector(
              onTap: () async {
                //弹出对话框并等待其关闭
                bool delete = await _showDeleteConfirmDialog1();
                if (delete == null) {
                  print("取消");
                } else {
                  print("确认");
                  //... 删除文件
                }
              },
              child: Row(
                children: [
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    '筛选',
                    style: TextStyle(
                      color: Colors.red,
                    ),
                  ),
                  Icon(
                    Icons.favorite_rounded,
                    color: Colors.grey,
                  ),
                  SizedBox(
                    width: 10,
                  ),
                ],
              ),
            ),
          ],
        ),
        Row(
          children: [
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Text('猜你喜欢'),
                  Text('高佣必买'),
                  Text('30天热销'),
                  Text('卡片显示'),
                ],
              ),
            ),
            SizedBox(
              width: 5,
            ),
            Row(
              children: [
                Text(
                  '快速选货',
                  style: TextStyle(
                    color: Colors.black,
                  ),
                ),
                SizedBox(
                  width: 10,
                ),
              ],
            ),
          ],
        ),
        SizedBox(
          height: 10,
        ),
      ],
    );
  }

  @FairWell('_buildTabItem')
  Widget _buildTabItem(String text) {
    return Container(
      height: 30,
      child: Padding(
        padding: EdgeInsets.only(top: 5),
        child: Text(text, style: TextStyle(color: Colors.black)),
      ),
    );
  }

  @FairWell('_buildListitemView')
  Widget _buildListitemView() {
    return Padding(
      padding: EdgeInsets.all(8),
      child: Card(
        elevation: 5,
        child: Padding(
            padding: EdgeInsets.all(10),
            child: Row(
              children: [
                Container(
                  decoration: new BoxDecoration(
                      color: Colors.grey,
                      borderRadius: BorderRadius.circular(3)),
                  height: 100,
                  width: 100,
                ),
                SizedBox(
                  width: 10,
                ),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '中秋节苏式月饼礼盒装荷花',
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                      Text(
                        '234位主播在卖 | 已售3232',
                        style: TextStyle(fontSize: 12),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Container(
                        decoration: BoxDecoration(
                            border:
                                Border.all(color: Colors.orange, width: 0.5)),
                        child: Padding(
                          padding: EdgeInsets.symmetric(horizontal: 3),
                          child: Text(
                            '大主播同款',
                            style:
                                TextStyle(color: Colors.orange, fontSize: 10),
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Row(
                        children: [
                          Expanded(
                              child: Column(
                            children: [
                              Text(
                                '预计赚',
                                style: TextStyle(color: Colors.red),
                              ),
                              Text(
                                '¥223',
                                style: TextStyle(color: Colors.red),
                              )
                            ],
                            crossAxisAlignment: CrossAxisAlignment.start,
                          )),
                          Expanded(
                              child: Column(
                            children: [Text('佣金'), Text('50.34%')],
                            crossAxisAlignment: CrossAxisAlignment.start,
                          )),
                          Expanded(
                              child: Column(
                            children: [Text('粉丝购买价'), Text('¥59.3')],
                            crossAxisAlignment: CrossAxisAlignment.start,
                          )),
                        ],
                      )
                    ],
                  ),
                ),
              ],
            )),
      ),
    );
  }

  // 弹出对话框
  @FairWell('_showDeleteConfirmDialog1')
  Future<bool> _showDeleteConfirmDialog1() {
    return showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("提示"),
          content: Text("此处弹出筛选"),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () => Navigator.of(context).pop(), // 关闭对话框
            ),
            FlatButton(
              child: Text("确认"),
              onPressed: () {
                //关闭对话框并返回true
                Navigator.of(context).pop(true);
              },
            ),
          ],
        );
      },
    );
  }
}

@SionChen
Copy link
Author

这个log也没有看出来是哪个语法出了问题

@avenwu avenwu added bug Something isn't working enhancement New feature or request labels Jan 11, 2021
@avenwu
Copy link
Contributor

avenwu commented Jan 11, 2021

这段代码包含逻辑运算,所以报错。目前编译器没有输出更多错误信息,会补充日志,方便开发是排查转义问题

@SionChen
Copy link
Author

好的 目前支持Function的转义吗?@Fairwell修饰?

@SionChen
Copy link
Author

image
image
这是我转义出来的

@avenwu
Copy link
Contributor

avenwu commented Jan 12, 2021

针对函数成员,建议封装为Widget后,添加@FairBinding,会自动生成组件表。
如果需要引用函数,通过Delegate进行配置。
demo中存在数组循环的逻辑,这部分目前还处于实验性质。将你的代码,略加调整后,转换得到如下效果。
Screen Shot 2021-01-12 at 1 31 16 PM

@avenwu
Copy link
Contributor

avenwu commented Jan 12, 2021

调整后的参考代码见附件:
sample.zip

@SionChen
Copy link
Author

好的 多谢。
image
这里是不可以chuan传list数据吗?
image

@SionChen
Copy link
Author

Sugar.mapEach 转义出来的代码是不对的:
image
转义后:
image

@SionChen
Copy link
Author

针对函数成员,建议封装为Widget后,添加@FairBinding,会自动生成组件表。
如果需要引用函数,通过Delegate进行配置。
demo中存在数组循环的逻辑,这部分目前还处于实验性质。将你的代码,略加调整后,转换得到如下效果。
Screen Shot 2021-01-12 at 1 31 16 PM

你这里的GoodsContent json可以发出来看一下吗?

@avenwu
Copy link
Contributor

avenwu commented Jan 12, 2021

data绑定参数,只能使用基础类型,不能使用数组,对象也不建议

{
  "className": "Column",
  "na": {
    "children": [
      {
        "className": "Column",
        "na": {
          "children": [
            {
              "className": "SizedBox",
              "na": {
                "height": 5
              }
            },
            {
              "className": "Row",
              "na": {
                "children": [
                  {
                    "className": "Expanded",
                    "na": {
                      "child": {
                        "className": "TabBar",
                        "na": {
                          "controller": "#(tabController)",
                          "tabs": {
                            "className": "Sugar.mapEach",
                            "pa": [
                              "#(tabs)",
                              {
                                "className": "Container",
                                "na": {
                                  "height": 30,
                                  "child": {
                                    "className": "Padding",
                                    "na": {
                                      "padding": {
                                        "className": "EdgeInsets.only",
                                        "na": {
                                          "top": 5
                                        }
                                      },
                                      "child": {
                                        "className": "Text",
                                        "pa": [
                                          "item"
                                        ],
                                        "na": {
                                          "style": {
                                            "className": "TextStyle",
                                            "na": {
                                              "color": "#(Colors.black)"
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            ]
                          },
                          "labelColor": "#(Colors.black)"
                        }
                      }
                    }
                  },
                  {
                    "className": "GestureDetector",
                    "na": {
                      "onTap": "#(onTap)",
                      "child": {
                        "className": "Row",
                        "na": {
                          "children": [
                            {
                              "className": "SizedBox",
                              "na": {
                                "width": 10
                              }
                            },
                            {
                              "className": "Text",
                              "pa": [
                                "筛选"
                              ],
                              "na": {
                                "style": {
                                  "className": "TextStyle",
                                  "na": {
                                    "color": "#(Colors.red)"
                                  }
                                }
                              }
                            },
                            {
                              "className": "Icon",
                              "pa": [
                                "#(Icons.favorite_rounded)"
                              ],
                              "na": {
                                "color": "#(Colors.grey)"
                              }
                            },
                            {
                              "className": "SizedBox",
                              "na": {
                                "width": 10
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            },
            {
              "className": "Row",
              "na": {
                "children": [
                  {
                    "className": "Expanded",
                    "na": {
                      "child": {
                        "className": "Row",
                        "na": {
                          "mainAxisAlignment": "#(MainAxisAlignment.spaceAround)",
                          "children": [
                            {
                              "className": "Text",
                              "pa": [
                                "猜你喜欢"
                              ]
                            },
                            {
                              "className": "Text",
                              "pa": [
                                "高佣必买"
                              ]
                            },
                            {
                              "className": "Text",
                              "pa": [
                                "30天热销"
                              ]
                            },
                            {
                              "className": "Text",
                              "pa": [
                                "卡片显示"
                              ]
                            }
                          ]
                        }
                      }
                    }
                  },
                  {
                    "className": "SizedBox",
                    "na": {
                      "width": 5
                    }
                  },
                  {
                    "className": "Row",
                    "na": {
                      "children": [
                        {
                          "className": "Text",
                          "pa": [
                            "快速选货"
                          ],
                          "na": {
                            "style": {
                              "className": "TextStyle",
                              "na": {
                                "color": "#(Colors.black)"
                              }
                            }
                          }
                        },
                        {
                          "className": "SizedBox",
                          "na": {
                            "width": 10
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            },
            {
              "className": "SizedBox",
              "na": {
                "height": 10
              }
            }
          ]
        }
      },
      {
        "className": "Column",
        "na": {
          "children": [
            {
              "className": "ListItemView"
            },
            {
              "className": "Container",
              "na": {
                "color": "#(myColor)"
              }
            }
          ]
        }
      }
    ]
  }
}

@SionChen
Copy link
Author

image
我看你的demo里面也用了呢。我这边需要一个list来进行数据传输,没有解决方法吗

@SionChen
Copy link
Author

大佬 有没有交流群? 可以加一下吗

@avenwu
Copy link
Contributor

avenwu commented Jan 12, 2021

demo中是一个数组string对象。字符串是基础类型。不能使用对象的原因是没有反射api,所以很困难支持对象。讨论组,有微信群,后面看看搞一个chat通道

@SionChen
Copy link
Author

Sugar.mapEach 转义出来的代码是不对的:
image
转义后:
image

这个可能是什么问题我加上Sugar.foreach转义就有问题:
image
image

@SionChen
Copy link
Author

image
我换成String也不行

@avenwu
Copy link
Contributor

avenwu commented Jan 12, 2021

到首页去gitter讨论组聊

@avenwu avenwu closed this as completed Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants