代码之家  ›  专栏  ›  技术社区  ›  user3808307

无法在颤振中添加垂直线

  •  0
  • user3808307  · 技术社区  · 4 年前

    我有下面的布局

    Form(
      onChanged: _updateFormProgress,
      child: Row(       
        children: [
          Expanded(
            flex: 3,
            child: Column(
              children: [
                ....
              ],
            ),
          ),
          Expanded(
            flex: 2,
            child: Column(
              children: [
                ...
              ],
            ),
          )
        ],
      ),
    );
    

    我需要在两者之间设置一条垂直分隔线 Expanded

    我试过:

    Form(
      onChanged: _updateFormProgress,
      child: Row(       
        children: [
          Expanded(
            flex: 3,
            child: Column(
              children: [
                ....
              ],
            ),
          ),
          Container(
            child: VerticalDivider(
              color: Colors.red,
              width: 1,
            )
          ),
          Expanded(
            flex: 2,
            child: Column(
              children: [
                ...
              ],
            ),
          )
        ],
      ),
    );
    

    它可以编译,但我看不到行。我还尝试了其他选择,比如将扩展的容器包装在一个容器中,并制作一个边框,但有不同的问题

    0 回复  |  直到 4 年前
        1
  •  1
  •   KuKu    4 年前

    我像你们提供的树一样修改了代码,并将其改为工作。

    请用“IntrinsicHeight”包装“Row”。

    enter image description here

    我附上了我测试过的完整代码。

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      void initState() {
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Padding(
            padding: EdgeInsets.all(10),
            child: Center(
              child: Column(
                children: [
                  Container(
                    child: Form(
                      onChanged: () {},
                      child: IntrinsicHeight(
                        child: Row(
                          children: [
                            Expanded(
                              flex: 3,
                              child: Column(
                                children: [
                                  Container(child: Text('a')),
                                  Container(child: Text('a')),
                                  Container(child: Text('a')),
                                ],
                              ),
                            ),
                            Container(
                              child: VerticalDivider(
                                color: Colors.red,
                                width: 1,
                              ),
                            ),
                            Expanded(
                              flex: 2,
                              child: Column(
                                children: [
                                  Container(child: Text('a')),
                                  Container(child: Text('a')),
                                  Container(child: Text('a')),
                                ],
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }