用 Flutter 水一個可丑的漸變首頁(一)

看我有漸變色!

緣起

這兩天下載了一個叫《卡片日記》的愛啪啪,看著還有點小清新呢,趕緊抄一個。
嗯,作為一個21世紀(jì)的新青年怎么能不會用漸變?對漸變要,抄起來抄起來!


卡片日記首頁

我超牛逼的漸變復(fù)刻版。。。

呵呵呵~ 抄成這個樣子也是醉了。。。

漸變字體組件搞起來

這個簡單,給文字加這遮罩嘛,哈哈:

/// 隨便寫寫,反正我很菜

class GradientText extends StatelessWidget {
  GradientText({
    @required this.gradient,
    this.text,
    this.style,
    this.iconData,
    this.iconSize,
  })  : assert(text == null || iconData == null, 'text 和 iconData 只能填一個');

  final String text;
  final TextStyle style;
  final IconData iconData;
  final double iconSize;
  final Gradient gradient;

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      shaderCallback: (Rect bound) => gradient.createShader(Offset.zero & bound.size),
      child: text != null
          ? Text(text, style: style == null ? TextStyle(color: Colors.white) : style.copyWith(color: Colors.white))
          : Icon(iconData, size: iconSize, color: Colors.white),
    );
  }
}

什么,你問我傳iconData干什么,iconData也是字體啊,呵呵呵~
感覺這篇要寫完了啊,有點短。。
再補一點

底部導(dǎo)航欄

底部直接用BottomAppBar好了,不然那個劉海還要自己畫,忒麻煩,這里用上上面的GradientText組件,


DecoratedBox(
    decoration: BoxDecoration(boxShadow: [
      BoxShadow( // 陰影效果
        color: Color.fromARGB(100, 200, 200, 200),
        blurRadius: 8,
      )
    ]),
    child: ClipRRect( // 剪出兩個圓角
        borderRadius: BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
          child: BottomAppBar(
            elevation: 0,
            notchMargin: 6,
            shape: CircularNotchedRectangle(),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                IconButton(
                  icon: GradientText(
                    iconData: Icons.note_add,
                    iconSize: 26,
                    gradient: LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: StaticStyle.linerColor[widget.homeProvider.curPage],
                    ),
                  ),
                  onPressed: () {},
                ),
                Text(''),
                IconButton(
                  icon: GradientText(
                    iconData: Icons.person,
                    iconSize: 26,
                    gradient: LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: [
                        Colors.black54,
                        Colors.black,
                      ],
                    ),
                  ),
                  onPressed: () {},
                ),
              ],
            ),
          ),
        ),
    )

還有懸浮的,添加按鈕,也用上漸變

Container(
    width: 56,
    height: 56,
    decoration: BoxDecoration(
      shape: BoxShape.circle,
      gradient: LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: StaticStyle.linerColor[widget.homeProvider.curPage],
      ),
      boxShadow: [
        BoxShadow(
          color: Color.fromARGB(100, 87, 211, 255),
          blurRadius: 8,
        )
      ],
    ),
    child: Icon(Icons.add, color: Colors.white),
  )

這個時候,如果滾動上面的pageview,tab的漸變色是不會跟著變的,怎樣讓它動起來呢,下節(jié)繼續(xù)~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容