当包含在行中时,如何使Container的高度与TextField的高度匹配?

时间:2019-06-14 01:20:39

标签: user-interface flutter height textfield flutter-layout

在尝试回答此问题期间,我尝试将TextField与常规Text交换...

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
            body: Container(
          color: Colors.orange,
          child: IntrinsicHeight(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Container(
                  color: Colors.grey,
                  child: Text("1st element"),
                ),
                AspectRatio(
                  aspectRatio: 1,
                  child: Container(
                    color: Colors.green,
                  ),
                ),
              ],
            ),
          ),
        )),
      ),
    );
  }
}

...效果很好!仅供参考:我从a comment on github开始学习IntrinsicHeight的工作。

这是我失败的尝试@试图通过TextField获得相似的结果...

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  TextEditingController _controller;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
            body: Container(
          color: Colors.orange,
          child: IntrinsicHeight(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Expanded(
                  flex: 1,
                  child: TextField(
                    controller: _controller,
                    decoration: new InputDecoration(
                        border: InputBorder.none, hintText: "???"),
                  ),
                ),
                AspectRatio(
                  aspectRatio: 1,
                  child: Container(
                    color: Colors.green,
                  ),
                ),
              ],
            ),
          ),
        )),
      ),
    );
  }
}

如果运行这两个程序,您会发现前者的橙色容器的高度将调整可访问性字体大小更改的大小,而后者则不会。

如何使它们表现相同?

0 个答案:

没有答案