Implement VisualDensity for text fields. (#51438)

This implements VisualDensity changes for text fields*. By default, the layout of the text field does not change.

If the ThemeData.visualDensity is set to a value other than zero, then the density of the UI will increase or decrease. See the VisualDensity docs for more information.

(*In reality, the changes are on the InputDecorator class, not on the text field.)

I also fixed a problem that I think I found with _Decoration where it doesn't compare isDense or isCollapsed as part of its operator==.
This commit is contained in:
Greg Spencer
2020-02-26 13:38:28 -08:00
committed by GitHub
parent 7ff3a50fe7
commit 9e744c5710
3 changed files with 254 additions and 17 deletions

View File

@@ -401,11 +401,13 @@ class _ControlTile extends StatelessWidget {
class _MyHomePageState extends State<MyHomePage> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final OptionModel _model = OptionModel();
TextEditingController textController;
@override
void initState() {
super.initState();
_model.addListener(_modelChanged);
textController = TextEditingController();
}
@override
@@ -430,8 +432,36 @@ class _MyHomePageState extends State<MyHomePage> {
primarySwatch: m2Swatch,
);
final Widget label = Text(_model.rtl ? 'اضغط علي' : 'Press Me');
textController.text = _model.rtl ? 'يعتمد القرار الجيد على المعرفة وليس على الأرقام.' : 'A good decision is based on knowledge and not on numbers.';
final List<Widget> tiles = <Widget>[
_ControlTile(
label: _model.rtl ? 'حقل النص' : 'Text Field',
child: SizedBox(
width: 300,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: textController,
decoration: const InputDecoration(
hintText: 'Hint',
helperText: 'Helper',
labelText: 'Label',
border: OutlineInputBorder(),
),
),
TextField(
controller: textController,
),
TextField(
controller: textController,
maxLines: 3,
),
],
),
),
),
_ControlTile(
label: _model.rtl ? 'رقائق' : 'Chips',
child: Column(