【问题标题】:How can I generate a "ColumnList" in Flutter如何在 Flutter 中生成“ColumnList”
【发布时间】:2018-12-30 00:42:02
【问题描述】:

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

--BEGIN 重要部分--

  1. 生成的列项(包含标题和说明)
  2. 项目列表

--END 重要部分--

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

【问题讨论】:

    标签: listview user-interface flutter generate


    【解决方案1】:

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

    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)
          ],
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2022-12-21
      • 2021-10-28
      • 2023-03-09
      • 1970-01-01
      • 2021-08-02
      • 2021-10-31
      • 2021-08-24
      • 2022-10-15
      相关资源
      最近更新 更多