简体   繁体   English

Flutter ListView 和 List Widget

[英]Flutter ListView and List Widget

I don't know exactly what is wrong here.我不知道这里到底出了什么问题。 Maybe someone can help me.也许有人可以帮助我。 I don't get any errors or other error messages.我没有收到任何错误或其他错误消息。 The screen of the cell phone is white.手机屏幕是白色的。 There may also be another way to better save and call up the data from the list.可能还有另一种方法可以更好地保存和调用列表中的数据。 You could create an extra file with these.您可以使用这些创建一个额外的文件。 I've been trying for a while and tried other things too, unfortunately without results.我已经尝试了一段时间,也尝试了其他东西,不幸的是没有结果。 By the way, when I wrote the data in individually without using a list, it worked.顺便说一句,当我不使用列表单独写入数据时,它起作用了。 Thanks in advance.提前致谢。

import 'package:flutter/material.dart';

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {

  List<String> comname = [
  'Adidas',
  'Nike',
  'Google',
];

List<String> comsales = [
  '200',
  '300',
  '400',
];

List<String> comheadquarter = [
  'Berlin',
  'Hamburg',
  'München',
];

List<String> comemployee = [
  '800',
  '850',
  '900',
];

  @override
  Widget build(BuildContext context) {
    return Scaffold(.......
            ),
            Padding(
              padding: EdgeInsets.only(top: 550, bottom: 50),
              child: Container(
                child: ListView(
                  children: <Widget>[
                    companyCard(
                      comname[0],
                      comsales[0],
                      comheadquarter[0],
                      comemployee[0],
                    ),
                  ],
                  scrollDirection: Axis.horizontal,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Widget companyCard(
    String name, String sales, String headquarter, String employee) {
  return Stack(
    children: <Widget>[
      Container(
        margin: EdgeInsets.symmetric(vertical: 0, horizontal: 15.0),
        height: 180,
        width: 200,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(28.0),
          color: Colors.green,
        ),
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.fromLTRB(8.0, 11.0, 11.0, 35.00),
                  child: Text(
                    name,
                    style: TextStyle(
                      fontSize: 25,
                    ),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(4.0),
                  child: Text(
                    'Sales:',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.all(4.0),
                    child: Text(
                      sales,
                      style: TextStyle(
                        fontSize: 18,
                      ),
                    )),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(4.0),
                  child: Text(
                    'Headquarters:',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.all(4.0),
                    child: Text(
                      headquarter,
                      style: TextStyle(
                        fontSize: 18,
                      ),
                    )),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(4.0),
                  child: Text(
                    'Employee:',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.all(4.0),
                    child: Text(
                      employee,
                      style: TextStyle(
                        fontSize: 18,
                      ),
                    )),
              ],
            ),
          ],
        ),
      ),
    ],
  );
}

Make the padding under the scaffold smaller.使脚手架下的填充物更小。 Maybe this renders the widget out of the page.也许这会将小部件呈现在页面之外。

Make this value smaller使这个值更小

padding: EdgeInsets.only(top: 550, bottom: 50),

Give a smaller value like 50给出一个较小的值,例如 50

padding: EdgeInsets.only(top: 50, bottom: 50),

Tried your code, had to remove the extra parantheses, nevertheless it works properly.尝试了您的代码,必须删除额外的括号,但它可以正常工作。 As others have mentioned, try reducing the padding.正如其他人所提到的,尝试减少填充。 Maybe your device screen was smaller than the top padding and it pushed it out of the screen.也许您的设备屏幕小于顶部填充,并将其推出屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM