flutter - SingleChildScrollView + Column:溢出或忽略 mainAxisAlignment
问题描述
[已解决] 我已经用工作解决方案更新了 dartpad https://dartpad.dartlang.org/42415ce855bfcdc148eb03872c170c77
在dartpad上运行下面的代码并垂直调整浏览器页面的大小;
你会注意到在右边的例子中
SingleChildScrollView不滚动并且列溢出
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)
],
),
),
),
],
),
);
}
在发布这个问题之前,我做了一些研究
两种情况都相似,但与我的情况不兼容
或者只是躲避问题,将其中一个小部件替换为不同的小部件
(我的情况改变了结果);
我尝试使用以下组合包装列和 scsv
Expanded、ConstrainedBox、Container和SizedOverflowBox
没有成功,要么破坏应用程序,要么失去spaceEvenly
财产
我可以使用一些帮助,谢谢
解决方案
代替 SingleChildScrollView,您可以像这样给 CustomScrollView 一个镜头;
return CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Column(
children: [
// * YOUR WIDGETS HERE
],
),
),
],
);
推荐阅读
- python - python中的目录压缩
- angular - NPM-AUDIT 发现高漏洞。我应该做些什么?
- css - 边框半径不依赖于高度和宽度
- bash - 如何在命令行上使用 MediaInfo 以 MBps 显示我的视频比特率 --Inform
- matrix - 如何使用 R 用随机数替换矩阵中的 NA?
- node.js - Node js、express 和 handlebars - 在渲染之前将逻辑应用于数据的位置
- java - 为什么阻塞依赖状态的操作比那些简单失败的操作更方便、更不容易出错?
- c# - 如何获取整数到数组(从整数 i 到整数 j)。C#
- postgresql - pg_dump 和 restore - pg_restore 在 Windows 上挂起
- javascript - JS - 为匹配 querySelectorAll 的所有元素添加点击事件监听器