[英]How do I only apply padding to the text in a TextField in Flutter?
[英]How do I apply Material Design-compliant padding to my Flutter Scaffold?
我编写了一个Flutter应用程序,该应用程序使用package:flutter/material.dart
。 在iOS模拟器上运行该应用程序如下所示。 如您所见,一行中的组件之间没有填充,并且组件在没有填充/边距/边框的情况下到达顶部,底部,左侧和右侧。 我的问题是:
建议采用哪种方法来应用与材料兼容的填充,例如用于“转换为”和下拉按钮之间的label-component-gap。 我可以将组件包装在容器中并在其中应用填充吗?
提前非常感谢您。
这是应用程序代码:
import 'package:flutter/material.dart';
import 'converter.dart';
import 'model.dart';
const _appName = 'Temperature Converter';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: _appName,
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: _appName),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final Model model = new Model();
var _currentInput = const InputValue();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(config.title),
),
body: new Column(children: <Widget>[
new Row(children: <Widget>[
new Expanded(
child: new Input(
hintText: 'Temperature',
value: _currentInput,
onChanged: (input) => _currentInput = input)),
new DropdownButton(
items: createUnit(),
onChanged: (temperatureUnit newValue) {
setState(() {
model.inUnit = newValue;
});
},
value: model.inUnit)
]),
new Row(children: <Widget>[
new Text("Convert to"),
new DropdownButton(
items: createUnit(),
onChanged: (temperatureUnit newValue) {
setState(() {
model.outUnit = newValue;
});
},
value: model.outUnit),
]),
new FlatButton(
child: new Text('Calculate'),
onPressed: () {
setState(() {
double inTemp = stringToDouble(_currentInput.text);
model.inTemperature = inTemp;
model.calculateOutTemperature();
});
}),
new Text(model.outTemperatureAsString)
]), // This trailing comma tells the Dart formatter to use
// a style that looks nicer for build methods.
);
}
List<DropdownMenuItem> createUnit() {
var l = new List<DropdownMenuItem<temperatureUnit>>();
// degrees Celsius
l.add(new DropdownMenuItem<temperatureUnit>(
value: temperatureUnit.degreesCelsius,
child: new Text(unitDegreesCelsius)));
// degrees Fahrenheit
l.add(new DropdownMenuItem<temperatureUnit>(
value: temperatureUnit.degreesFahrenheit,
child: new Text(unitDegreesFahrenheit)));
// Kelvin
l.add(new DropdownMenuItem<temperatureUnit>(
value: temperatureUnit.kelvin, child: new Text(unitKelvin)));
return l;
}
}
问题绝不是暗示Flutter缺少了某些东西。 我只是想做对。 ;-)
通常,我建议使用Block
作为脚手架的子代。 它具有您可以设置的padding
值。
您也可以只使用Padding
小部件。
我只知道ButtonTheme
具有填充值
ButtonTheme.of(context).padding
因此,我认为目前最好的解决方案是保持恒定的值并使用Container来应用填充。
也许我是错的,但我不知道任何会自动应用任何Material填充的Widget。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.