[英]Flutter: cannot create horizontally scrollable body with shown scroll bar
I need help to create scrollable body: my screen我需要帮助来创建可滚动的主体:我的屏幕
This is how my structure of body looks: build()这就是我的身体结构的样子: build()
body: Padding(
padding: const EdgeInsets.all(30.0),
child: DragAndDropLists(
children: _contents,
onItemReorder: _onItemReorder,
onListReorder: _onListReorder,
axis: Axis.horizontal,
listWidth: 300,
listDraggingWidth: 300,
listPadding: EdgeInsets.all(20.0),
itemDivider: const Divider(
thickness: 4,
height: 10,
color: lightBlue,
),
itemDecorationWhileDragging: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: const Color(0xff004269).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 3,
offset: const Offset(0, 0), // changes position of shadow
),
],
),
listInnerDecoration: BoxDecoration(
color: Theme.of(context).canvasColor,
borderRadius: BorderRadius.all(Radius.circular(5)),
),
lastItemTargetHeight: 2,
addLastItemTargetHeightToTop: true,
lastListTargetSize: 40,
),
),
I tried already ListView, SingleChildScrollView, Column I don't know why but it's doesn't work我已经尝试过 ListView、SingleChildScrollView、Column 我不知道为什么但它不起作用
Maybe somebody has an idea what I can change to see scrollbar and can scroll it horizontally Thank you也许有人知道我可以改变什么来查看滚动条并可以水平滚动谢谢
You seem to be using a bit of complex layout, but a simplified version would look something like this:您似乎使用了一些复杂的布局,但简化版本看起来像这样:
You can set scrollDirection
property of ListView
to Axis.horizontal
and for scrollbar you can wrap ListView
inside Scrollbar
.您可以将ListView
的scrollDirection
属性设置为Axis.horizontal
,对于滚动条,您可以将ListView
包装在Scrollbar
内。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
final ScrollController _scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SizedBox(
height: 120,
child: Scrollbar(
isAlwaysShown: true,
controller: _scrollController,
child: ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
itemCount: 100,
itemBuilder: buildItem),
),
),
),
);
}
Widget buildItem(context, index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green[200],
),
margin: const EdgeInsets.all(8.0),
height: 100,
width: 100,
);
}
}
Try wrap Padding
in your Scaffold
with SingleChildScrollView
尝试使用SingleChildScrollView
将Padding
包裹在Scaffold
中
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Padding(),
)
Other option that you can use is GridView
, and ListView
.您可以使用的其他选项是GridView
和ListView
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.