![](/img/trans.png)
[英]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.