Неправильное использование родительского виджета? - PullRequest
0 голосов
/ 24 сентября 2018

enter image description here Это тело Скаффолда, я действительно не понимаю, Почему я получаю эту ошибку?Я добавил ограничения на высоту и ширину.Все еще не получаю ошибку.А последовательность тела мне кажется логикой?

 body:Center(child:SingleChildScrollView
      (child: Column(
        children:_list1
        .map((element)=>
        Container(
          margin: EdgeInsets.all(9.0),
           constraints: new BoxConstraints.expand(height: 300.0),
           decoration: new BoxDecoration(
           border: new Border.all(color: Colors.blueAccent),
           borderRadius: BorderRadius.horizontal( left:Radius.circular(30.0) ,right:Radius.circular(30.0) ),
           image: new DecorationImage(
           image: new AssetImage('assets/food1.jpg'),
           fit: BoxFit.cover,),),
           padding: EdgeInsets.only(bottom: 20.0),

      child: Stack(
        children:<Widget>[
           Positioned(left: 0.0,bottom: 30.0,child:  Text(element.name, style: new TextStyle(fontWeight: FontWeight.bold,fontSize: 20.0,)),),

          Positioned(left: 0.0,bottom: 0.0,child:  Text(element.dis,style: new TextStyle(fontWeight: FontWeight.bold,fontSize: 20.0,)),),
          Positioned(right: 0.0,top:0.0,child:Icon(Icons.star)),
          Positioned(right: 200.0,top:0.0,child:Icon(Icons.check)),

        ]
      ),  

        ), 
        ).toList()
              )
       ) )
     );

1 Ответ

0 голосов
/ 24 сентября 2018

Вы можете использовать ListView вместо Center, SingleChildScrollView и Column.

body: ListView(
        children: _list1
            .map(
              (element) => Container(
                    margin: EdgeInsets.all(9.0),
                    constraints: new BoxConstraints.expand(height: 300.0),
                    decoration: new BoxDecoration(
                      border: new Border.all(color: Colors.blueAccent),
                      borderRadius: BorderRadius.horizontal(
                        left: Radius.circular(30.0),
                        right: Radius.circular(30.0),
                      ),
                      image: new DecorationImage(
                        image: new NetworkImage(
                            'https://images.pexels.com/photos/5317/food-salad-restaurant-person.jpg?auto=compress&cs=tinysrgb&h=350'),
                        fit: BoxFit.cover,
                      ),
                    ),
                    padding: EdgeInsets.only(bottom: 20.0),
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          left: 0.0,
                          bottom: 30.0,
                          child: Text(
                            element.name,
                            style: new TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 20.0,
                            ),
                          ),
                        ),
                        Positioned(
                          left: 0.0,
                          bottom: 0.0,
                          child: Text(
                            element.dis,
                            style: new TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 20.0,
                            ),
                          ),
                        ),
                        Positioned(
                          right: 0.0,
                          top: 0.0,
                          child: Icon(Icons.star),
                        ),
                        Positioned(
                          right: 200.0,
                          top: 0.0,
                          child: Icon(Icons.check),
                        ),
                      ],
                    ),
                  ),
            )
            .toList(),
      ),

В вашем коде Center покажется бесполезным.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...