简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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