Почему каждый раз, когда я добавляю ListView в свой столбец, все виджеты исчезают?

#flutter #flutter-layout #flutter-web

#flutter #флаттер-макет #flutter-web

Вопрос:

Я создаю веб-приложение Flutter, и у меня есть что-то вроде этого

 class _HomeViewState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
     var posts = Provider.of<List<Post>>(context);
  List<int> l =[1,2,3,4];
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: TheAppBaar,
      body: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Container(child: Padding(
              padding:  EdgeInsets.all(20.0),
              child: Column(

                children: [
                  CreatePost(connUserUid: widget.user.uid, connUserImage:
                  userFetched.get('profileImage').toString(),
                    connUserFullname: userFetched.get('fullName').toString(),),
                  SizedBox(height: 10,),

                 ListView.separated(itemBuilder: (BuildContext context, int
                      index) {
                    return Container(
                      height: 150,
                      child: Text('${l[index]}'),
                    );
                  },
                      separatorBuilder:
                  (BuildContext context, int index) => Divider(), 
                   itemCount: l.length)
               ],
              ),
             ),
            ),
           ),
          );
        }
}
  

Каждый раз, когда я хочу отобразить ListView с выбранными этими записями или чем-то еще, метод Create Post и поле такого размера исчезают, и список также не отображается.

  @override
  Widget build(BuildContext context) {
    return  Align(
      alignment: Alignment.center,
      child: Container(
        width: 400,
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
            boxShadow: [BoxShadow(
                color:kPrimaryColor.withOpacity(0.2),
                spreadRadius: 2,
                blurRadius: 3,
                offset: Offset(0,3)
            )]
        ),
        child: Padding(
          padding: EdgeInsets.all(20),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Align(
                alignment: Alignment.center,
                child: Container(
                  height: 50,
                  child: Image.network(widget.connUserImage),
                ),
              ),
              Align(
                alignment: Alignment.center,
                child: Container(width: 30,child: Divider(
                  color: kPrimaryColor,
                  thickness: 2,
                ),),
              ),
              SizedBox(height: 8,),

              TextField(
                maxLines: 5,
                decoration: InputDecoration(
                  errorText: errorTextMessage,
                    border: OutlineInputBorder(
                        borderSide: BorderSide(color: kPrimaryColor)
                    ),
                    labelText: 'Yadda, Yadda, Yadda...'
                ),
                onChanged: (String value) {
                  setState(() {
                    postDescription = value;
                    errorTextMessage = null;
                    spinner = false;
                  });
                },
              ),
              SizedBox(height: 12,),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      IconButton(
                        icon: Icon(Icons.add_a_photo_rounded, color: Color
                (0xFFE53E00),
                          size:
                          25,),
                        onPressed: () {
                         imagePicker();

                        },
                      ),
                      SingleChildScrollView(
                        scrollDirection: Axis.horizontal,
                        child: imageInfo == null ? Container() : Text(imageInfo.fileName),
                      )
                    ],
                  ),
                  Icon(Icons.pin_drop_rounded, color: Color(0xFF0077e5),
                    size:
                    25,),
                  Icon(Icons.map_rounded, color: Color(0xFF26c118),
                    size: 25,),
                 spinner? Padding(
                   padding:  EdgeInsets.all(15.0),
                   child: CircularProgressIndicator(backgroundColor: kPrimaryColor,),
                 ) :
                 IconButton(icon:
                 Icon(Icons
                     .arrow_forward_ios_outlined,
                    color:
                  kPrimaryColor,size: 25,), onPressed: ()  {

                  

                  },),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
  

Это метод CreatePost, просто «карточка»,
если я создаю ListView, все исчезают, но если в моем столбце из первого кода я добавляю 1 PostView на 1, они отображаются. Я не понимаю, в чем дело. Должен ли я удалить эти Align или я не знаю. В моей консоли у меня нет никаких ошибок.
Заранее спасибо!

Комментарии:

1. Я думаю, что вы ListView вызываете ошибку… Попробуйте обернуть свой ListView контейнером и указать высоту.

2. попробуйте поместить shrinkWrap: true в свой ListView