0

I'am working on a project in which I have to dynamic populate an icon widget with the icon code read from our webservice.

The thing is that when i'm in debug mode, everything works perfectly and the icons are shown as expected, but as soon as I build the production release apk, it does not show some icons anymore. Here is my widget code.

            @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');
          }

And my ItemDetail Model:

        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,
          };
    }

Also added the screen shots for debug mode and production mode:

Release Mode Debug Mode

  • It seems like a layout problem to me since you used different phones for your layout and production. Also you don't have to place the new keyword anymore. Use const when you don't have to change the padding. Try flutter clean and check if it works, if not its a layout problem – CoderUni Jul 15 '20 at 03:17
  • I found that when I build the apk, flutter removes all fonts that I did not call explicitly, on release final apk. If I call Icons.the_icon_whose_code_is_dynamic_loaded, when I build the production release, the icons are included now. So a fix should be enforce to call icons statics values to avoid removes on build proccess. – Jose Anibal Rodriguez Jul 15 '20 at 13:06

1 Answers1

2

Adding --no-tree-shake-icons to flutter build, fixed the issue for me.

Timo Tijhof
  • 10,032
  • 6
  • 34
  • 48
Sam
  • 38
  • 5