【问题标题】:dart, flutter - ListView not showing飞镖,颤动 - ListView 不显示
【发布时间】:2019-02-20 10:06:20
【问题描述】:

我正在尝试显示一个 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 override 下,有 Scaffold 有 AppBar 和 body,body 有一个 ListView 与不同的项目 ListTiles,现在问题是 AppBar 正在显示(出现)但 body(ListView)没有显示(隐藏)。我希望 AppBar 和 ListView 都可见。

【问题讨论】:

  • 控制台是否出现错误

标签: android listview dart flutter


【解决方案1】:

您不能在 ListTile 中使用 TextField 作为字幕(使用当前实现)。

问题已在 github 上打开: https://github.com/flutter/flutter/issues/18755

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 2022-01-10
    • 2019-05-07
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 2022-06-19
    相关资源
    最近更新 更多