美文网首页
flutter 设置elevation,实现和android相同

flutter 设置elevation,实现和android相同

作者: 神经病人思路广 | 来源:发表于2019-03-18 17:22 被阅读0次

    代码如下:

    Material(
            elevation: 3,
            child: Container(
              height: 50,
              width: double.infinity,
              decoration: BoxDecoration(
                color: Colors.white,
              ),
              child: TabBar(
                controller: _controller,
                isScrollable: false,
                indicatorWeight: 0.0001,
                onTap: (index) {
                  setState(() {
                    _currentIndex = index;
                  });
                },
                tabs: _data.map((item) {
                  int index = _data.indexOf(item);
                  return Container(
                    width: 42,
                    height: 42,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      gradient: index == _currentIndex
                          ? LinearGradient(
                        colors: [Color(0xFF42c8ee), Color(0xFF4293ee)],
                        begin: Alignment.topLeft,
                        end: Alignment.bottomRight,
                      )
                          : null,
                      shape: BoxShape.circle,
                    ),
                    child: Wrap(
                      direction: Axis.vertical,
                      crossAxisAlignment: WrapCrossAlignment.center,
                      children: <Widget>[
                        Image.asset(
                          item.value,
                          fit: BoxFit.contain,
                          width: 20,
                          height: 20,
                          color: index == _currentIndex ? Colors.white : null,
                        ),
                        Text(
                          item.key,
                          style: TextStyle(
                            fontSize: 10,
                            color:
                            index == _currentIndex ? Colors.white : Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  );
                }).toList(),
              ),
            ),
          )
    

    就是用Material组件将你的view包裹起来设置elevation就行,切勿使用card等其他view包裹!

    相关文章

      网友评论

          本文标题:flutter 设置elevation,实现和android相同

          本文链接:https://www.haomeiwen.com/subject/ooebmqtx.html