-1

我想在 Flutter 中构建一个屏幕,看起来应该是这样的:

--BEGIN 重要部分--

  1. 生成的列项(包含标题和描述)
  2. 物品清单

--END 重要部分--

如何结合以下 Listview 生成这些列(不应该是 scollable)?如何生成“无 Listview” - 像 n ListView 这样的小部件?如何像构建 ListView 一样构建 Columns?

4

1 回答 1

0

你的问题很混乱。这是你想要的?

import 'package:flutter/material.dart';

main()  {
  runApp(new MaterialApp(
    title: 'Flutter Example',
    home: new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(title: new Text("Flutter Example"),),
        body: new MyApp(),
      ),
    ),
  ));
}

class MyApp extends StatelessWidget {


  @override
  Widget build(BuildContext context) {

    List<ColumnItem> items = [];

    // creates ColumnItems to display
    for (var i = 0; i < 40; i++) {
      items.add(
        new ColumnItem(title: "This is a title", description: "Descriptions are usefull",)
      );
    }

    return new ListView(
      children: items,
    );
  }
}




class ColumnItem extends StatelessWidget {

  final String title;
  final String description;

  const ColumnItem({this.title, this.description});

  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new Text(this.title, style: new TextStyle(fontSize: 22.0, fontWeight: FontWeight.bold),),
        new Text(this.description)
      ],
    );
  }
}

编辑:在进一步阅读你的问题后,也许这就是你想要做的?

import 'package:flutter/material.dart';

main()  {
  runApp(new MaterialApp(
    title: 'Flutter Example',
    home: new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(title: new Text("Flutter Example"),),
        body: new MyApp(),
      ),
    ),
  ));
}

class MyApp extends StatelessWidget {


  @override
  Widget build(BuildContext context) {

    List<ColumnItem> items = [];

    // creates ColumnItems to display
    for (var i = 0; i < 40; i++) {
      items.add(
        new ColumnItem(title: "This is a title", description: "Descriptions are usefull",)
      );
    }

    return new Column(
      children: [
        new Text("Static Title", style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold), ),
        new Text("This is a static desctription"),
        new Divider(),
        new Expanded(
          child: new ListView(children: items) ,
        )

      ],
    );
  }
}




class ColumnItem extends StatelessWidget {

  final String title;
  final String description;

  const ColumnItem({this.title, this.description});

  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new Text(this.title, style: new TextStyle(fontSize: 17.0, fontWeight: FontWeight.bold),),
        new Text(this.description)
      ],
    );
  }
}
于 2018-07-22T23:45:24.650 回答