【发布时间】:2021-12-19 12:53:46
【问题描述】:
我在使用AppBar 时得到这个error:
Scrollbar 的 ScrollController 没有附加 ScrollPosition。
这是我的CustomScrollBar:
class CustomScrollBar extends StatelessWidget {
final Widget child;
final ScrollController scrollController;
const CustomScrollBar({
required this.scrollController,
required this.child,
});
@override
Widget build(BuildContext context) {
return RawScrollbar(
thumbColor: AppColors.gray,
radius: Radius.circular(8),
thickness: 4,
isAlwaysShown: true,
controller: scrollController,
child: child,
);
}
}
我应该始终可见。这就是我使用它的方式:
child: CustomScrollBar(
scrollController: _scrollControllerForScrollBar,
child: SingleChildScrollView(
controller: _scrollControllerForScrollBar,
child: Padding(
padding: EdgeInsets.all(7.0.scaled),
child: Container(
width: double.infinity,
child: Text(
'any text bla bla bla \n\n\n this is a lot of \n text \n .'
),
),
),
),
),
您可以看到ScrollBar 和SingleChildScrollView 使用相同的ScrollController。我不知道为什么会发生此错误。知道我在这里缺少什么吗?
【问题讨论】:
-
你解决了吗?
-
@Balaji 不,不幸的是没有......
-
我也是同样的问题,等我找到解决办法再告诉你]
-
在您的CustomScrollBar中,您需要将scrollController分配给RawScrollBar。
-
@SamiIssa 啊,我在问题中错过了这一点,在我的代码中附上了它
标签: flutter dart scrollview scrollbar singlechildscrollview