【发布时间】:2020-12-29 19:48:47
【问题描述】:
[已解决] 我已使用有效的解决方案更新了 dartpad https://dartpad.dartlang.org/42415ce855bfcdc148eb03872c170c77
在dartpad 上运行以下代码并垂直调整浏览器页面大小;
你会在右边的例子中注意到
SingleChildScrollView 不滚动,Column 溢出
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) => const MaterialApp(
home: MyHomePage(),
);
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) => Material(
child: Row(
children: [
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('''without wrapping the column in fixed heigth
[MainAxisAlignment.spaceEvenly] doesn't work'''),
for (int i = 0; i < 7; i++) const FlutterLogo(size: 80)
],
),
),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('''wrapping the column in fixed heigth
it overflow ignoring [SingleChildScrollView]'''),
for (int i = 0; i < 7; i++) const FlutterLogo(size: 80)
],
),
),
),
],
),
);
}
在发布这个问题之前我做了一些研究
SingleChildScrollView inside Row
SingleChildScrollView 'cutting' the screen
SingleChildScrollView is not scrolling
SingleChildScrollView inside Row
两种情况都相似,但与我的情况不兼容
或者只是避开问题,将其中一个小部件替换为不同的小部件
(我的情况改变了结果);
我尝试使用组合包装列和 scsv
Expanded、ConstrainedBox、Container 和 SizedOverflowBox
没有成功,要么破坏应用程序,要么丢失spaceEvenly 属性
我可以帮忙,谢谢
【问题讨论】:
-
你需要2个SingleChildScrollView吗?你可以用 1 来做所有事情
-
不不,这只是一个代码示例,我只需要一个“spaceEvenly”且不会溢出的列
-
检查我的答案