Flutter - cannot use Flexible inside Padding for text wrapping purpose

前端 未结 3 609
一整个雨季
一整个雨季 2021-01-24 23:33

In my flutter app, I want to have a card and four boxes aligned horizontally with equal width and height inside it. Code follows ;

   @override
      Widget bui         


        
3条回答
  •  难免孤独
    2021-01-25 00:13

    Please try this...

    @override
    Widget build(BuildContext context) {
     return Scaffold(
        body: SafeArea(
            child: SingleChildScrollView(
      child: Column(
        children: [
          Card(
            margin: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Colors.blue,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Online Pharmacy",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
          Card(
            margin: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Colors.blue,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Online Pharmacy",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
          Card(
            margin: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Colors.blue,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Online Pharmacy",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
          Card(
            margin: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Colors.blue,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Online Pharmacy",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
          Card(
            margin: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width,
                  color: Colors.blue,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Online Pharmacy",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin:
                          EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                      width: 2,
                      height: 70,
                      color: Colors.grey,
                    ),
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: Column(
                                children: [
                                  FlutterLogo(
                                    size: 50,
                                  ),
                                  SizedBox(
                                    height: 10,
                                  ),
                                  //Image.asset("images/medicine.jpg"),
                                  Text('Picture of your Prescription',
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 14)),
                                ],
                                mainAxisSize: MainAxisSize.max,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        ],
      ),
    )));
    }
    

    Just copy paste code and see what happening... May this will help you.

提交回复
热议问题