Flutter动态图标未在生产版本上显示

时间:2020-07-15 02:20:13

标签: android flutter google-material-icons

我正在一个项目中,我必须用从我们的Web服务读取的图标代码动态填充图标小部件。

问题是,当我处于调试模式时,一切正常,并且图标按预期显示,但是一旦我构建了生产版本apk,它就不再显示某些图标。这是我的小部件代码。

            @override
            Widget build(BuildContext context) {
              var theme = Theme.of(context);
              return Scaffold(
                backgroundColor: CustomColors.primaryVariant,
                appBar: AppBar(
                  title: Text(widget.title ?? ''),
                  backgroundColor: CustomColors.primary,
                ),
                body: Container(
                  color: CustomColors.primary,
                  height: MediaQuery.of(context).size.height,
                  child: Stack(
                    children: [
                      Visibility(
                        visible: items.length > 0,
                        child: ListView.builder(
                          shrinkWrap: true,
                          itemCount: items.length,
                          itemBuilder: (context, index) {
                            var item = items[index];
                            return Card(
                              color: CustomColors.primaryVariant,
                              elevation: 5.0,
                              margin: new EdgeInsets.symmetric(vertical: .5),
                              child: Container(
                                child: ListTile(
                                  leading: Container(
                                    padding: EdgeInsets.only(right: 12.0),
                                    decoration: new BoxDecoration(
                                        border: new Border(
                                            right: new BorderSide(
                                                width: 1.0, color: Colors.white24))),
                                    child: Icon(CustomIcon(item.code), color: Colors.white),
                                  ),
                                  title: Text(
                                    item.detail.capitalize(),
                                    style: TextStyle(color: Colors.white, fontSize: 16),
                                  ),
                                  subtitle: Text(
                                    item.item,
                                    style: TextStyle(color: Colors.white70, fontSize: 14),
                                  ),
                                ),
                              ),
                            );
                          },
                        ),
                      ),
                      Visibility(
                        visible: items.length == 0,
                        child: ListView.builder(
                          shrinkWrap: true,
                          itemCount: 4,
                          itemBuilder: (context, index) {
                            return Card(
                              color: CustomColors.primaryVariant,
                              elevation: 5.0,
                              margin: new EdgeInsets.symmetric(vertical: .5),
                              child: Container(
                                child: ListTile(
                                  leading: Container(
                                    padding: EdgeInsets.only(right: 12.0),
                                    decoration: new BoxDecoration(
                                        border: new Border(
                                            right: new BorderSide(
                                                width: 1.0, color: Colors.white24))),
                                    child: ShimmerSkeleton(
                                      height: 20,
                                      width: 20,
                                    ),
                                  ),
                                  title: SizedBox(
                                    width: 60,
                                    child: ShimmerSkeleton(
                                      height: 20,
                                      width: 60,
                                    ),
                                  ),
                                  subtitle: Padding(
                                    padding: EdgeInsets.only(top: 5),
                                    child: ShimmerSkeleton(
                                      width: 90,
                                    ),
                                  ),
                                ),
                              ),
                            );
                          },
                        ),
                      ),
                      Positioned(
                        bottom: 0,
                        left: MediaQuery.of(context).size.width * 0.5 - 130,
                        child: Container(
                          margin: EdgeInsets.symmetric(vertical: 25),
                          child: Opacity(
                            opacity: .8,
                            child: SizedBox(
                              height: 60,
                              width: MediaQuery.of(context).size.width,
                              child: ListTile(
                                leading: CircleAvatar(
                                  radius: 26,
                                  backgroundImage: AssetImage('assets/img/rodal.jpg'),
                                ),
                                title: Text(
                                  'SUPPORTED BY',
                                  style: theme.textTheme.title.copyWith(
                                      fontWeight: FontWeight.w600, fontSize: 14),
                                ),
                                subtitle: Text(
                                  'Rodaltech, SRL',
                                  style: theme.textTheme.title.copyWith(
                                      fontWeight: FontWeight.w600, fontSize: 20),
                                ),
                              ),
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              );
            }
          }
          
          class CustomIcon extends IconData {
            CustomIcon(int codePoint) : super(codePoint, fontFamily: 'MaterialIcons');
          }

我的ItemDetail模型:

        class ItemDetail {
      ItemDetail({
        this.code,
        this.item,
        this.detail,
      });
    
      int code;
      String item;
      String detail;
    
      ItemDetail copyWith({
        int code,
        String item,
        String detail,
      }) =>
          ItemDetail(
            code: code ?? this.code,
            item: item ?? this.item,
            detail: detail ?? this.detail,
          );
    
      factory ItemDetail.fromJson(Map<String, dynamic> json) =>
          ItemDetail(
            code: json["code"] == null ? null : json["code"],
            item: json["item"] == null ? null : json["item"],
            detail: json["detail"] == null ? null : json["detail"],
          );
    
      Map<String, dynamic> toJson() => {
            "code": code == null ? null : code,
            "item": item == null ? null : item,
            "detail": detail == null ? null : detail,
          };
    }

还添加了调试模式和生产模式的屏幕截图:

Release Mode Debug Mode

1 个答案:

答案 0 :(得分:1)

--no-tree-shake-icons 添加到 flutter build,为我解决了这个问题。