Search code examples
androidflutterdartlauncher

flutter android launcher makes app icons different sizes


I am using device_apps.dart to make an app launcher that has large app icons. When I try to create l the large icons, apps scale to different sizes.

bad app size example 1

1

bad app size example 2

2

I can change the width of the icons using the scale or width properties of each icon image, but for some reason the icons do not scale the same. If I make the icons slightly larger, there is no problem, but making them the size I desire will cause app sizes to vary. Does anyone know what causes this and what a solution may be?

return GridView.count(  
                      crossAxisCount: columns,
                      //crossAxisSpacing: 0,
                      //mainAxisSpacing: 0,
                      children: List.generate(allApps.length, (index) {
                        return GestureDetector(
                          onTap:() {
                            DeviceApps.openApp(allApps[index].packageName);
                          },
                          child: Column(
                            children: [
                              Image.memory(
                                (allApps[index] as ApplicationWithIcon).icon,
                                //width: 150,
                                scale: .5,
                              ),
                              Text(
                                "${allApps[index].appName}",
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 38,
                                  ),
                                  overflow: TextOverflow.ellipsis,
                              )
                            ]
                          ),
                        );
                      })
                    );
                  }

Solution

  • if you want to make all same size, you can wrap your image with specific size and set fit property on the image

    Column(
      children:[
        SizedBox(
          // you can set only one or both
          // width: 
          height: 200
           child:Image.memory((allApps[index] as ApplicationWithIcon).icon,
              // Use this to scale down or scale up to fit the frame
              fit: BoxFit.contain
            ),
    

    enter image description here

    See here for another option BoxFit : https://api.flutter.dev/flutter/painting/BoxFit.html