Home > database >  how to set fix size of gridiew on random text
how to set fix size of gridiew on random text

Time:01-19

           child: Card(
                  elevation: 10,
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.black87,
                        borderRadius: BorderRadius.circular(7)),
                    height: 50,
                    width: 50,
                    margin: EdgeInsets.all(5),
                    child: Center(
                        child: Text(
                      "${toplist[index]}".toUpperCase(),
                      style: TextStyle(
                          fontSize: 20,
                          fontFamily: "regular",
                          color: Colors.white,
                          fontWeight: FontWeight.bold),
                    )),
                  ),
                ),

every time change value of the text in gridview and change the container size, I get a fixed size of the container on every random text.

CodePudding user response:

Put your (Card) Widget inside a (FittedBox) Widget, and select (scaleDown) to your (fit option) as you see below in the code sample.

  FittedBox(
                      fit: BoxFit.scaleDown,
                      child: Card(
                        elevation: 10,
                        child: Container(
                          decoration: BoxDecoration(
                              color: Colors.black87,
                              borderRadius: BorderRadius.circular(7)),
                          height: 50,
                          width: 50,
                          margin: EdgeInsets.all(5),
                          child: Center(
                              child: Text(
                            "${toplist[index]}".toUpperCase(),
                            style: TextStyle(
                                fontSize: 20,
                                fontFamily: "regular",
                                color: Colors.white,
                                fontWeight: FontWeight.bold),
                          )),
                        ),
                      ),
                    ),
  • Related