我有一个带有一些小部件的Flutter应用程序。
我正在使用GestureDetector
小工具进行滑动,我有很多小工具在堆栈中。有时我会在其他小工具的顶部显示一些文本,有时文本太大而无法容纳。所以我想添加滚动作为一个自定义。Positioned
小部件打破了滚动。如果我删除小部件,甚至删除“顶部/左侧/右侧”选项,它工作正常!?
下面是一个可重现的示例。
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: StackOverflowExample()));
}
class StackOverflowExample extends StatelessWidget {
const StackOverflowExample({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
behavior: HitTestBehavior.translucent,
// ignore: avoid_print
onTap: () {
print('tap');
},
child: Stack(
children: [
Center(
child: Container(
width: 400,
height: 400,
color: Colors.red,
),
),
const Positioned(
top: 50,
left: 0,
right: 0,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(
'Lot and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots ',
style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold),
),
),
),
],
),
),
);
}
}
1条答案
按热度按时间k97glaaz1#
我建议把你的
SingleChildScrollView
Package 成SizedBox
,而不是将
Text
小工具的maxLines
固定为2。