【问题标题】:How can I make ListView CrossAxisAlignment wrap content?如何使 ListView CrossAxisAlignment 包装内容?
【发布时间】:2020-04-09 13:35:16
【问题描述】:

我的目标是制作一个水平滚动的 ListView。我希望高度与 ListView 中最大项目的高度相同。现在,水平 ListView 展开以填满整个垂直屏幕。如何在不指定高度的情况下缩小高度并仍然能够滚动?

这是一个 dartpad 链接,其中包含我拥有的代码:https://dartpad.dev/13bd819a46e6c2d840147a5855a6e54c

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    也许这将是您想要的输出,试试这个,

    // Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
    // for details. All rights reserved. Use of this source code is governed by a
    // BSD-style license that can be found in the LICENSE file.
    
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: Home(),
        );
      }
    }
    
    class Home extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        var fraction = OutlinedContainer(
            child: IntrinsicWidth(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Text("100"),
                    Container(
                      height: 2,
                      color: Colors.black,
                    ),
                    Text("300"),
                  ],
                ),
              ),
            ));
    
        return Scaffold(
            body: OutlinedContainer(
              child: Column(
                mainAxisSize: MainAxisSize.min,
              children: [Wrap(
              children: <Widget>[
                fraction,fraction,   fraction
              ],),]),
            ));
      }
    }
    
    class OutlinedContainer extends Container {
      OutlinedContainer({@required Widget child}) : super(child: child,             decoration: BoxDecoration(
                    border: Border.all(color: Colors.blue, width: 3),
                    borderRadius: BorderRadius.circular(10)));
    }
    

    【讨论】:

    • 如果正确,您可以接受此答案,因为其他用户遵循已批准的答案,因此对他们来说很容易
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多