如何使Stack小部件中的第二个小部件很重要?

时间:2018-08-06 10:51:54

标签: flutter flutter-layout

我使用Stack小部件进行叠加。


让我们想象一下。

1)我在底部添加PageView。

2)我在顶部添加了Container以使Gradient成为


我想知道

尽管有Gradient,如何滚动PageView?

这是一个示例

body: Stack(
    children: <Widget>[
      PageView.builder(
        itemBuilder: (BuildContext context, int index) => Container(
              height: double.infinity,
              width: double.infinity,
              child: Text("Index: $index"),
              color: _pageColors[index],
            ),
        onPageChanged: (number) {
          setState(() {
            _pageFocus = number + 1;
          });
          print(number);
        },
        controller: _pageController,
        itemCount: _pageColors != null ? _pageColors.length : 0,
      ),
      Align(
        alignment: AlignmentDirectional.bottomEnd,
        child: Container(
          height: 100.0,
          child: Stack(
            children: <Widget>[
              Container(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                      colors: [
                        Color.fromRGBO(255, 255, 255, 0.0),
                        Colors.white,
                      ],
                      stops: [
                        0.0,
                        3.0
                      ],
                      begin: FractionalOffset.topCenter,
                      end: FractionalOffset.bottomCenter,
                      tileMode: TileMode.repeated),
                ),
                width: double.infinity,
                height: double.infinity,
              ),
              Padding(
                padding: const EdgeInsets.all(16.0),
                child: Align(
                    alignment: AlignmentDirectional.centerStart,
                    child: Text('$_pageFocus/${_pageColors.length}')),
              )
            ],
          ),
        ),
      ),
    ],
  ),

1 个答案:

答案 0 :(得分:1)

查看将Align包裹在IgonorePointer中是否有帮助。 docs.flutter.io/flutter/widgets/IgnorePointer-class.html