在安排ListView与列和行颤振时遇到问题

时间:2020-06-05 16:10:26

标签: flutter flutter-layout

我试图花费数小时来调整小部件以使其完美地适合行或某种滚动面板,但没有成功。

我从Rest API中检索数据,并假定每个元素都适合放在一行中。

我尝试了多种选择,例如扩展,查看文档,但仍然无法使其适应要求。

我上传了一张照片来演示问题。

预先感谢

enter image description here

import 'package:flutter/material.dart';
import 'package:intergrative2020_UI_Rest/Request/getAllElementsRequest.dart';
import 'package:intergrative2020_UI_Rest/models/getElementsFromAPI.dart';
import 'package:intergrative2020_UI_Rest/providers/user_page.dart';
import 'package:provider/provider.dart';

class ShowElements extends StatefulWidget {
  @override
  _ShowUsersState createState() => _ShowUsersState();
}

class _ShowUsersState extends State<ShowElements> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text("Retrieve Elements"),
        centerTitle: true,
        backgroundColor: Colors.blue[700],
      ),
      body: new Container(
        child: new ListView(
                shrinkWrap: true,

          children: <Widget>[
            new FutureBuilder<List<GetElementFromAPI>>(
              future: getElementsWidget(),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  List<GetElementFromAPI> users = snapshot.data;
                  return new Row(
                      children: users
                          .map((element) => Container(
                                child: new Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: <Widget>[
                                      Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceEvenly,
                                          children: <Widget>[
                                            Text(
                                              " Created :\n" +
                                                  " " +
                                                  element.createdBy.toString(),
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.grey[700]),
                                            ),
                                            Text(
                                              " Timestamp:\n" +
                                                  " " +
                                                  element.createdTimeStamp
                                                      .toString(),
                                              style: TextStyle(
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.grey[700]),
                                            ),
                                          ]),
                                      new Row(children: <Widget>[
                                        new Text(
                                          "lat: " +
                                              element.latLngMap.values.first
                                                  .toString() +
                                              '\n' +
                                              "lng: " +
                                              element.latLngMap.values.last
                                                  .toString(),
                                          style: TextStyle(
                                              fontWeight: FontWeight.bold,
                                              color: Colors.teal[300]),
                                        ),
                                         Text(
                                            (" Type\n" + " " + element.type),
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.indigo[400]),
                                          ),
                                      ]),


                                        new Column(children: <Widget>[
                                          new Text(
                                            " Is Active\n" +
                                                " " +
                                                element.isActive.toString(),
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.grey[700]),
                                          ),
                                          new Text(
                                            " Name\n" + " " + element.nameOfStore,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.grey[700]),
                                          ),
                                        ]),
                                    ]),
                              ))
                          .toList());
                } else if (snapshot.hasError) {
                  return snapshot.error;
                }
                return new Center(
                  child: new Column(
                    children: <Widget>[
                      new Padding(padding: new EdgeInsets.all(50.0)),
                      new CircularProgressIndicator(),
                    ],
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }

  Future<List<GetElementFromAPI>> getElementsWidget() async =>
      await GetAllElementRestRequest(
              Provider.of<UserProvider>(this.context, listen: false).getEmail())
          .getElements();
}

0 个答案:

没有答案