如何显示一个列的一列并允许滚动屏幕
我想用两个块开发该应用程序。每个块都是一个接一个的列。如果内容(如果不适合),则应出现滚动。
我写了下一个应用程序。但是问题是我无法获得滚动工作并获得最低水平的问题。我试图将所有内容包装在singlechildscrollview
中,但它不起作用。
这是我的复制 - 帕斯特代码:
import 'dart:async';
import 'package:flutter/material.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'aaaa'),
);
}
}
class MyHomePage extends StatelessWidget {
late String title;
MyHomePage({required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: [
Row(children: [
Expanded(
flex: 1,
child: Container(
color: Color.fromARGB(255, 255, 252, 234),
margin: const EdgeInsets.only(left: 20.0, top: 20.0, right: 20.0),
child: SizedBox( // emulation of block with fixed size content.
height: 450,
),
),
),
]),
// flex: 5,
Expanded(
flex: 2,
child: Column(
children: [
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
],
)),
],
),
);
}
}
I want to develop app that with two blocks. Every block is column one after another. If content if not fitted to screen scrolls should be appeared.
I wrote next app. But problem that I can't get scrolling work and getting bottom overflow. I tried to wrap all in SingleChildScrollView
but it wont work.
Here is my copy-paste code:
import 'dart:async';
import 'package:flutter/material.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'aaaa'),
);
}
}
class MyHomePage extends StatelessWidget {
late String title;
MyHomePage({required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: [
Row(children: [
Expanded(
flex: 1,
child: Container(
color: Color.fromARGB(255, 255, 252, 234),
margin: const EdgeInsets.only(left: 20.0, top: 20.0, right: 20.0),
child: SizedBox( // emulation of block with fixed size content.
height: 450,
),
),
),
]),
// flex: 5,
Expanded(
flex: 2,
child: Column(
children: [
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
Text("Hello"),
],
)),
],
),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此代码:
Use this code :
似乎您在不正确的位置中添加
SinglechildScrollview()
。您必须将其添加到:
以及第二个
column()
中。您可以尝试:
结果:
It seems like you're adding the
SingleChildScrollView()
in the incorrect places.You have to add it in:
and also in your second
Column()
.You can try:
Result:
更改第二个集团中的列列表视图,然后用灵活的窗口小部件将其包裹起来
Change column in your second Bloc to Listview then wrap it with Flexible instead of Expanded widget