我试图显示一个ListView,但是它没有出现,下面是完整的代码(打开包含材料页面路线的屏幕):
pvc_screen.dart:
import 'package:flutter/material.dart';
class PVCScreen extends StatefulWidget {
@override
_PVCScreenState createState() => _PVCScreenState();
}
class _PVCScreenState extends State<PVCScreen> {
List<String> currencyPairs = ['EUR/USD', 'GBP/USD', 'USD/JPY'];
List<String> currencies = ['USD', 'GBP', 'JPY'];
String currencyPair = 'EUR/USD';
String askPrice = '';
String units = '';
String accountCurrency = 'USD';
String result = '';
double dots;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Pip Value Calculator'),
),
body: ListView(children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
title: new Text('Currency Pair'),
subtitle: DropdownButton(
value: currencyPair,
items: <DropdownMenuItem<String>>[
DropdownMenuItem(
value: currencyPairs[0],
child: new Text('${currencyPairs[0]}'),
),
DropdownMenuItem(
value: currencyPairs[1],
child: new Text('${currencyPairs[1]}'),
),
DropdownMenuItem(
value: currencyPairs[2],
child: new Text('${currencyPairs[2]}'),
),
],
onChanged: (String value) {
setState(() {
currencyPair = value;
});
},
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
title: new Text('Ask Price'),
subtitle: new TextField(
controller: TextEditingController(text: '$askPrice'),
decoration: InputDecoration(hintText: '0'),
onChanged: (String text) {
setState(() {
askPrice = text;
});
},
)),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
title: new Text('Position Size (units)'),
subtitle: new TextField(
controller: TextEditingController(text: '$units'),
decoration: InputDecoration(hintText: '0'),
onChanged: (String text) {
setState(() {
units = text;
});
},
)),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
title: new Text('Account Currency'),
subtitle: DropdownButton(
value: accountCurrency,
items: <DropdownMenuItem<String>>[
DropdownMenuItem(
value: currencies[0],
child: new Text('${currencies[0]}'),
),
DropdownMenuItem(
value: currencies[1],
child: new Text('${currencies[1]}'),
),
DropdownMenuItem(
value: currencies[2],
child: new Text('${currencies[2]}'),
),
],
onChanged: (String value) {
setState(() {
accountCurrency = value;
});
},
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: MaterialButton(
child: new Text('Calculate'),
onPressed: () {
setState(() {
dots = currencyPair.split('/')[1] == 'JPY' ? 0.01 : 0.0001;
result = (dots.toInt() / int.parse('$askPrice')).toString();
});
},
),
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: new Text(
'\$$result',
style: TextStyle(fontSize: 24.0),
)),
),
]),
);
}
}
在我看来,所有代码都有效。代码很简单PVCScreen是一个StatefulWidget。在其Build覆盖下,有一个带有AppBar和body的Scaffold,body具有一个带有不同ListTiles项的ListView,现在的问题是AppBar正在显示(显示),但是主体(ListView)没有显示(隐藏)。我希望AppBar和ListView都可见。
答案 0 :(得分:0)
您不能将TextField用作ListTile中的字幕(使用本实现)。
问题已在github上公开: https://github.com/flutter/flutter/issues/18755