简体   繁体   English

Flutter:如何覆盖库比蒂诺小部件的私有 state 实现?

[英]Flutter: how to override the private state implementation of a Cupertino widget?

I will first give a bit of background of my problem and then ask the actual question which I am trying to achieve:我将首先介绍一下我的问题的背景,然后提出我想要解决的实际问题:

BACKGROUND:背景:

I posted this earlier question about preventing rows from disappearing as soon as they entered the padding area of the CupertinoScrollbar's parent Padding widget:我发布了这个关于防止行在进入 CupertinoScrollbar 父 Padding 小部件的填充区域后立即消失的问题:

Flutter Padding on CupertinoScrollbar - how to prevent row from disappearing as soon as they enter the padding area? Flutter CupertinoScrollbar 上的填充 - 如何防止行在进入填充区域后立即消失?

I have figured out a workaround solution which involves removing the parent Padding widget entirely and instead wrapping the SliverList only in SliverPadding which achieves the padding on the list.我想出了一个解决方案,它涉及完全删除父 Padding 小部件,而是仅将SliverPadding包装在SliverList中,从而实现列表上的填充。 However, this makes the scrollbar start at the top as it's the parent of the SliverPadding and thus doesn't know the padding for the inner SliverList .但是,这会使滚动条从顶部开始,因为它是SliverPadding的父级,因此不知道内部SliverList的填充。

I have figured out a solution for this problem.我已经找到了解决这个问题的方法。 I can edit the source code of the CupertinoScrollbar and modify the following line in the updateScrollbarPainter method:我可以编辑CupertinoScrollbar的源代码并在updateScrollbarPainter方法中修改以下行:

..padding = MediaQuery.of(context).padding

to what I need.到我需要的。

QUESTION:问题:

This updateScrollbarPainter is part of the private state implementation _CupertinoScrollbarState , so I can't access it outside from my app.updateScrollbarPainter是私有 state 实现_CupertinoScrollbarState的一部分,因此我无法从我的应用程序外部访问它。

Is there a workaround for this?有解决方法吗?

If not, is the only possible solution to modify the padding there is to copy the entire source code from this file into my app and then modify it there?如果不是,那么修改填充的唯一可能解决方案是将整个源代码从这个文件复制到我的应用程序中,然后在那里修改它? It seems a bit complicated for modifying a single line of code no?修改一行代码似乎有点复杂,不是吗?

Here's the line I can modify:这是我可以修改的行:

在此处输入图像描述

You can try wrapping widget with MediaQuery and provide the padding while it depends on context.您可以尝试使用MediaQuery包装小部件并根据上下文提供填充。

body: MediaQuery(
    data: MediaQuery.of(context).copyWith(
      padding: EdgeInsets.all(52), //here modify the one you want
    ),
    child: Scrollbar(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM