flutter NestedScrollView

import 'package:ddcsh/common/data/app_data.dart';
import 'package:ddcsh/widget/icon_text_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';

import 'IndexLogic.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> with AutomaticKeepAliveClientMixin {
  final logic = Get.put<IndexLogic>(IndexLogic());

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);

    Widget _headGroup = Container(
      padding: EdgeInsets.all(12.w),
      width: double.infinity,
      color: AppColor.theme,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(height: 44.h),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text("上海市", style: TextStyle(fontSize: 14.sp, color: Colors.white)),
              Expanded(
                child: Container(
                  margin: EdgeInsets.only(left: 15.w),
                  height: 32.h,
                  padding: EdgeInsets.only(left: 8.w, right: 8.w),
                  decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(16.h))),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SizedBox(width: 10.w),
                      Expanded(child: Text("全新輪滑油", style: TextStyle(fontSize: 12.sp, color: AppColor.font99))),
                      const Icon(Icons.search, color: AppColor.font99),
                    ],
                  ),
                ),
              ),
            ],
          ),
          SizedBox(height: 11.h),
          Container(
            height: 50.h,
            padding: EdgeInsets.only(left: 11.w, right: 11.w),
            decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(2.h))),
            child: Row(
              children: [
                Icon(Icons.add, size: 30.h),
                SizedBox(width: 8.w),
                Text("添加愛車", style: TextStyle(fontSize: 18.sp, color: AppColor.black3F, fontWeight: FontWeight.bold)),
                SizedBox(width: 8.w),
                Expanded(child: Text("享受更優(yōu)質(zhì)服務", style: TextStyle(fontSize: 14.sp, color: AppColor.font99))),
                Image.asset("img/car_who_vin.png", height: 28.h),
              ],
            ),
          )
        ],
      ),
    );

    //功能欄目
    Widget _bigFunctionalGridView = Padding(
      padding: EdgeInsets.only(left: 25.w, right: 30.w),
      child: GridView.count(
        padding: const EdgeInsets.symmetric(vertical: 20),
        shrinkWrap: true,
        childAspectRatio: 1 / 1,
        mainAxisSpacing: 10.w,
        physics: const NeverScrollableScrollPhysics(),
        crossAxisSpacing: 18.w,
        crossAxisCount: 4,
        children: [
          _buildGridIconTextItemView("img/car_who_vin.png", "無法啟動"),
          _buildGridIconTextItemView("img/car_who_vin.png", "輪胎壞了"),
          _buildGridIconTextItemView("img/car_who_vin.png", "沒油了"),
          _buildGridIconTextItemView("img/car_who_vin.png", "沒電了"),
          _buildGridIconTextItemView("img/car_who_vin.png", "故障燈亮"),
          _buildGridIconTextItemView("img/car_who_vin.png", "車禍/事故"),
        ],
      ),
    );

    //百變酷炫欄目組
    Widget _recommendRowScrollView = Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.w),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(4.h))),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          _buildNavigationBarView("百變炫酷"),
          SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: [
                _buildRowScrollItemView(),
                _buildRowScrollItemView(),
                _buildRowScrollItemView(),
                _buildRowScrollItemView(),
              ],
            ),
          )
        ],
      ),
    );

    //小的功能欄目
    Widget _minFunctionalGridView = Padding(
      padding: EdgeInsets.only(left: 25.w, right: 30.w),
      child: GridView.count(
        padding: const EdgeInsets.symmetric(vertical: 20),
        shrinkWrap: true,
        childAspectRatio: 1 / 1,
        mainAxisSpacing: 10.w,
        physics: const NeverScrollableScrollPhysics(),
        crossAxisSpacing: 18.w,
        crossAxisCount: 4,
        children: [
          _buildGridIconTextItemView("img/car_who_vin.png", "放心修"),
          _buildGridIconTextItemView("img/car_who_vin.png", "新車"),
          _buildGridIconTextItemView("img/car_who_vin.png", "二手車"),
          _buildGridIconTextItemView("img/car_who_vin.png", "更多"),
        ],
      ),
    );

    //視頻列表
    Widget _gridInfoList = GridView.custom(
      gridDelegate: SliverWovenGridDelegate.count(
        crossAxisCount: 2,
        mainAxisSpacing: 8,
        crossAxisSpacing: 8,
        pattern: [
          const WovenGridTile(1),
          const WovenGridTile(
            5 / 7,
            crossAxisRatio: 0.9,
            alignment: AlignmentDirectional.centerEnd,
          ),
        ],
      ),
      childrenDelegate: SliverChildBuilderDelegate(
        (context, index) => Text("位置 $index", style: TextStyle(fontSize: 12.sp, color: AppColor.font99)),
      ),
    );

    return Scaffold(
      backgroundColor: Colors.white, 
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return [
            SliverAppBar(
              expandedHeight: 680.h,
              floating: true,
              pinned: true,
              flexibleSpace: FlexibleSpaceBar(
                centerTitle: true,
                background: Column(
                  children: [
                    _headGroup,
                    _bigFunctionalGridView,
                    _recommendRowScrollView,
                    _minFunctionalGridView,
                    _buildNavigationBarView("熱門推薦"),
                  ],
                ),
              ),
            )
          ];
        },
        body: _gridInfoList,
      ),
    );
  }

  //構(gòu)建一個上下類型的視圖
  Widget _buildGridIconTextItemView(String iconAsset, String title) {
    return IconTextButton(
      icon: Image.asset(iconAsset, height: 45.h),
      itDirection: IT_Direction.TOP_BOTTOM,
      text: Text(title, style: TextStyle(fontSize: 12.sp, color: Colors.black)),
    );
  }

  //構(gòu)建一個導航Bar
  Widget _buildNavigationBarView(String title) {
    return SizedBox(
      height: 50.h,
      child: Row(
        children: [
          Expanded(child: Text(title, style: TextStyle(fontSize: 16.sp, color: AppColor.black3F, fontWeight: FontWeight.bold))),
          Icon(Icons.chevron_right, color: AppColor.font99, size: 30.h),
        ],
      ),
    );
  }

  Widget _buildRowScrollItemView() {
    return Padding(
      padding: EdgeInsets.only(right: 15.w),
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(5.w)),
        child: SizedBox(
          height: 90.h,
          width: 142.w,
          child: Stack(
            children: [
              SizedBox.expand(
                child: Container(
                  color: Colors.black,
                  child: Image.asset("img/car_who_vin.png"),
                ),
              ),
              Positioned(
                left: 5.h,
                top: 5.h,
                child: Text("炫彩改裝設計圖鑒", style: TextStyle(fontSize: 12.sp, color: Colors.white)),
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<IndexLogic>();
    super.dispose();
  }
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末冀续,一起剝皮案震驚了整個濱河市领跛,隨后出現(xiàn)的幾起案子吻贿,更是在濱河造成了極大的恐慌选酗,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件饶套,死亡現(xiàn)場離奇詭異漩蟆,居然都是意外死亡,警方通過查閱死者的電腦和手機妓蛮,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門怠李,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人蛤克,你說我怎么就攤上這事捺癞。” “怎么了构挤?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵髓介,是天一觀的道長。 經(jīng)常有香客問我筋现,道長唐础,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任矾飞,我火速辦了婚禮彻犁,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘凰慈。我一直安慰自己,他們只是感情好驼鹅,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布微谓。 她就那樣靜靜地躺著森篷,像睡著了一般。 火紅的嫁衣襯著肌膚如雪豺型。 梳的紋絲不亂的頭發(fā)上仲智,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音姻氨,去河邊找鬼钓辆。 笑死,一個胖子當著我的面吹牛肴焊,可吹牛的內(nèi)容都是我干的前联。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼娶眷,長吁一口氣:“原來是場噩夢啊……” “哼似嗤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起届宠,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤烁落,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后豌注,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體伤塌,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年轧铁,在試婚紗的時候發(fā)現(xiàn)自己被綠了每聪。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡属桦,死狀恐怖熊痴,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情聂宾,我是刑警寧澤果善,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站系谐,受9級特大地震影響巾陕,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜纪他,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一鄙煤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧茶袒,春花似錦梯刚、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽澜共。三九已至,卻和暖如春锥腻,著一層夾襖步出監(jiān)牢的瞬間嗦董,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工瘦黑, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留京革,地道東北人。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓幸斥,卻偏偏與公主長得像匹摇,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子睡毒,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容