Flutter 如何在flatter中格式化行?

Flutter 如何在flatter中格式化行?,flutter,dart,material-design,row,multiple-columns,Flutter,Dart,Material Design,Row,Multiple Columns,我在想我怎样才能改变我的代码看起来就是这样 我爸爸看起来像那样 这是我的密码 return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( onTap: () { DatbaseService.instance.createorGetConversation(uid, uid, (String _co

我在想我怎样才能改变我的代码看起来就是这样

我爸爸看起来像那样

这是我的密码

    return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
      GestureDetector(
        onTap: () {
          DatbaseService.instance.createorGetConversation(uid, uid,
              (String _conversationID) {
            NavigationService.instance.navigateToRoute(
              MaterialPageRoute(builder: (context) {
                return MeineBeitraege(
                  _conversationID,
                  widget.uid,
                  widget.username,
                  widget.url,
                  widget.email,
                );
              }),
            );
          });
        },
        child: Container(
          child: ClipOval(
            child: Container(
                height: 35,
                width: 35,
                decoration: BoxDecoration(
                  color: Colors.white,
                ),
                child: widget.url != null && widget.url != 'profilepictureer'
                    ? Image.network(
                        widget.url,
                        fit: BoxFit.cover,
                      )
                    : Image.asset(
                        'assets/profilepictureer.png') // Your widget is here when image is no available.
                ),
          ),
          decoration: new BoxDecoration(
              shape: BoxShape.circle,
              border: new Border.all(color: Colors.black, width: 3)),
        ),
      ),
      Column(children: [
        RichText(
          text: TextSpan(
            text: widget.username, // _snapshot.data['username']
            style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),

            children: <InlineSpan>[
              WidgetSpan(
                  alignment: PlaceholderAlignment.baseline,
                  baseline: TextBaseline.alphabetic,
                  child: SizedBox(width: 4)),
              TextSpan(
                //"${comment.data()['comment']}"
                text: widget.comment,
                style: TextStyle(
                  fontWeight: FontWeight.normal,
                ),
              )
            ],
          ),
        ),
        Row(
          children: [
            Text(widget.timeago),
            SizedBox(width: 10),
            Text('${widget.commentlikes} likes'),
            SizedBox(width: 10),
            InkWell(
              onTap: () {
                widget.onTap();
                if (!widget.focusNode.hasPrimaryFocus) {
                  setState(() {
                    FocusScope.of(context).requestFocus(widget.focusNode);
                  });
                }
              },
              child: Text('Reply'),
            ),
          ],
        ),
           widget.commentcount != null && widget.commentcount > 0
            ? Container(
                child: Align(
                  alignment: Alignment.topCenter,
                  child: TextButton(
                    onPressed: () {},
                    style: TextButton.styleFrom(
                      primary: Colors.grey,
                    ),
                    child: InkWell(
                        onTap: () {
                          if (viewreplies) {
                            setState(() {
                              viewreplies = false;
                            });
                          } else {
                            setState(() {
                              viewreplies = true;
                            });
                          }
                        },
                        child: viewreplies == true
                            ? Text(
                                '———View replies(${widget.commentcount})',
                                style: TextStyle(fontSize: 13),
                              )
                            : Text(
                                '———Hide replies(${widget.commentcount})',
                                style: TextStyle(fontSize: 13),
                              )),
                  ),
                ),
              )
            : Container(),
     
      ]),
      
      const Spacer(),
      InkWell(
        onTap: () => likecomment(widget.commentdataid),
        child: widget.likes.contains(uid)
            ? Icon(
                Icons.star,
                size: 25,
                color: Colors.yellow,
              )
            : Icon(
                Icons.star_border_outlined,
                size: 25,
              ),
      )
    ]);
那么commentswidget就是有状态的Lisle Separat

 @override
  Widget build(BuildContext context) {
    final wi = MediaQuery.of(context).size.width;
    return Column(
          children:[

           ListTile( -------)
-- - -- - - 
CommentsComments(),
CommentsComments()是第二个具有第二个listtile的单独状态的第二个listview

 @override
  Widget build(BuildContext context) {
return Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: Column(
          children: [
            Expanded(
   child: StreamBuilder(
        stream: FirebaseFirestore.instance
            .collection('videos')
            .doc(widget.videoid)
            .collection('comments')
            .doc(widget.id)
            .collection("commentcomment")
            .orderBy('time', descending: true)
            .snapshots(),
        builder: (BuildContext context, snapshot) {
          if (snapshot.hasData) {
            return SingleChildScrollView(
              child: Container(
                child: ListView.builder(
    --...
ListTile()

 

要创建类似Instagram的评论部分UI,您可以查看以下代码。 我添加了一个硬编码列表,用于显示。您可以插入自己的服务器数据,并使用逻辑区分两个列表视图。 对于这个UI,我已经创建了一个普通的评论对象,在回复列表中包含对该用户的所有回复,例如

single user comment object
    {
          'name': 'person 1',
          'message': 'Some text message from person 1',
          'replies': [
            {
              'name': 'person 2',
              'message': 'Some text message from person 2',
            },
            {
              'name': 'person 3',
              'message': 'Some text message from person 3',
            },
          ]
        },

导入“包装:颤振/材料.省道”;
最终颜色深蓝色=颜色。来自argb(255,18,32,47);
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主题:ThemeData.dark().copyWith(脚手架背景颜色:深蓝色),
debugShowCheckedModeBanner:false,
家:脚手架(
正文:中(
子项:MyWidget(),
),
),
);
}
}
类MyWidget扩展了无状态Widget{
最终列表注释列表=[
{
“姓名”:“人1”,
'message':'person 1发送的一些短信',
“答复”:[
{
“姓名”:“第二个人”,
'message':'person 2发送的一些短信',
},
{
'姓名':'第三人',
'消息':'来自第三个人的一些短信',
},
]
},
{
'姓名':'第4人',
'消息':'来自第4个人的一些短信',
“答复”:[]
},
{
'姓名':'第5人',
'消息':'来自第5个人的一些短信',
“答复”:[
{
'姓名':'第6人',
'消息':'来自第6个人的一些短信',
}
]
}
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“Hello World”),),
正文:ListView.builder(
填充:常量边集全部(0.0),
收缩膜:对,
itemCount:commentList.length,
itemBuilder:(上下文,索引){
返回列(子项:[
列表砖(
contentPadding:const EdgeInsets.symmetric(水平:8.0),
标题:文本(评论列表[索引]['name']),
领先:图标(图标。光纤新),
),
ListView.builder(
收缩膜:对,
物理学:const NeverScrollableScrollPhysics(),
填充:常量边集全部(0.0),
itemCount:commentList[索引][“回复]。长度为0,
itemBuilder:(上下文,i){
返回列表块(
内容填充:
常数边集对称(水平:24.0),
前导:图标(图标.页面),
标题:文本(评论列表[索引][“回复][i][“名称]),
);
})
]);
}));
}
}
在dartpad中运行此跳线,并根据您的使用情况对其进行重构。

我会尝试一下并给你一些反馈给我5分钟-10分钟ok需要更多的时间比如10-15分钟希望你能帮我吗?@yjanyj是的,请。好的,它工作得很好,我认为,但点击查看回复时,评论的位置不正确。这就像是直接在父注释下。让我们先解决这个问题,然后再解决另一个问题。我会更新我的代码,这样你就可以看到我是如何做的。我应该说我调用listviewbuilder,然后调用单独的staftefulwidget,它是Lisle,工作得很好。
single user comment object
    {
          'name': 'person 1',
          'message': 'Some text message from person 1',
          'replies': [
            {
              'name': 'person 2',
              'message': 'Some text message from person 2',
            },
            {
              'name': 'person 3',
              'message': 'Some text message from person 3',
            },
          ]
        },
import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  final List<dynamic> commentList = [
    {
      'name': 'person 1',
      'message': 'Some text message from person 1',
      'replies': [
        {
          'name': 'person 2',
          'message': 'Some text message from person 2',
        },
        {
          'name': 'person 3',
          'message': 'Some text message from person 3',
        },
      ]
    },
    {
      'name': 'person 4',
      'message': 'Some text message from person 4',
      'replies': []
    },
    {
      'name': 'person 5',
      'message': 'Some text message from person 5',
      'replies': [
        {
           'name': 'person 6',
          'message': 'Some text message from person 6',
        }
      ]
    }
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
        title: Text("Hello World"),),
        body: ListView.builder(
            padding: const EdgeInsets.all(0.0),
            shrinkWrap: true,
            itemCount: commentList.length,
            itemBuilder: (context, index) {
              return Column(children: [
                ListTile(
                  contentPadding: const EdgeInsets.symmetric(horizontal: 8.0),
                  title: Text(commentList[index]['name']),
                  leading: Icon(Icons.fiber_new),
                ),
                ListView.builder(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    padding: const EdgeInsets.all(0.0),
                    itemCount: commentList[index]['replies'].length ?? 0,
                    itemBuilder: (context, i) {
                      return ListTile(
                        contentPadding:
                            const EdgeInsets.symmetric(horizontal: 24.0),
                         leading: Icon(Icons.pages),
                        title: Text(commentList[index]['replies'][i]['name'] ),
                      );
                    })
              ]);
            }));
  }
}