Flutter 自定義Switch組件(常規(guī)|帶圓角滑塊)

常規(guī)自定義組件(案例一)

1.先上效果圖

ToggleSwitch.gif

2.關(guān)鍵代碼如下

1.代碼抽取

/// describe
///
/// created by hujintao
/// created at 2019-12-09
//

import 'package:flutter/material.dart';

typedef OnToggle = void Function(int index);

class ToggleSwitch extends StatefulWidget {
  final Color activeBgColor;
  final Color activeTextColor;
  final Color inactiveBgColor;
  final Color inactiveTextColor;
  final List<String> labels;
  final double cornerRadius;
  final OnToggle onToggle;
  final int initialLabelIndex;
  final double minWidth;
  final List<IconData> icons;
  final List<Color> activeColors;

  ToggleSwitch({
    Key key,
    @required this.activeBgColor,
    @required this.activeTextColor,
    @required this.inactiveBgColor,
    @required this.inactiveTextColor,
    @required this.labels,
    this.onToggle,
    this.cornerRadius = 8.0,
    this.initialLabelIndex = 0,
    this.minWidth = 72,
    this.icons,
    this.activeColors,
  }) : super(key: key);

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

class _ToggleSwitchState extends State<ToggleSwitch>
    with AutomaticKeepAliveClientMixin<ToggleSwitch> {
  int current;

  @override
  void initState() {
    current = widget.initialLabelIndex;
    super.initState();
  }

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return ClipRRect(
      borderRadius: BorderRadius.circular(widget.cornerRadius),
      child: Container(
        height: 40,
        color: widget.inactiveBgColor,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: List.generate(widget.labels.length * 2 - 1, (index) {
            final active = index ~/ 2 == current;
            final textColor =
            active ? widget.activeTextColor : widget.inactiveTextColor;
            var bgColor = Colors.transparent;
            if (active) {
              bgColor = widget.activeColors == null
                  ? widget.activeBgColor
                  : widget.activeColors[index ~/ 2];
            }
            if (index % 2 == 1) {
              final activeDivider = active || index ~/ 2 == current - 1;
              return Container(
                width: 1,
                color: activeDivider ? widget.activeBgColor : Colors.white30,
                margin: EdgeInsets.symmetric(vertical: activeDivider ? 0 : 8),
              );
            } else {
              return GestureDetector(
                onTap: () => _handleOnTap(index ~/ 2),
                child: Container(
                  constraints: BoxConstraints(minWidth: widget.minWidth),
                  alignment: Alignment.center,
                  color: bgColor,
                  child: widget.icons == null
                      ? Text(widget.labels[index ~/ 2],
                      style: TextStyle(color: textColor))
                      : Row(
                    children: <Widget>[
                      Icon(widget.icons[index ~/ 2],
                          color: textColor, size: 17.0),
                      Padding(
                          padding: const EdgeInsets.only(left: 5.0),
                          child: Text(widget.labels[index ~/ 2],
                              style: TextStyle(color: textColor)))
                    ],
                  ),
                ),
              );
            }
          }),
        ),
      ),
    );
  }

  void _handleOnTap(int index) async {
    setState(() => current = index);
    if (widget.onToggle != null) {
      widget.onToggle(index);
    }
  }
}

2.代碼使用

ToggleSwitch(
    initialLabelIndex: 1,
    minWidth: ScreenUtil().setWidth(180),
    cornerRadius: ScreenUtil().setWidth(70),
    activeBgColor: Color(0xffED9CBE),
    activeTextColor: Colors.white,
    inactiveBgColor: Color(0xffF3F4F5),
    inactiveTextColor: Color(0xff999999),
    labels: ['匹配歷史', '匹配CP'],
    onToggle: (index) {
      print('switched to: $index');
    }),

組件使用簡介~

  • minWidth 設置最小寬度
  • cornerRadius 設置圓角
  • activeBgColor 設置高亮時的背景顏色
  • activeTextColor 設置高亮時的字體顏色
  • inactiveBgColor 設置常規(guī)背景顏色
  • inactiveTextColor 設置常規(guī)字體顏色
  • labels 設置標題數(shù)組
  • onToggle 撥動回調(diào)方法

自定義Switch案例二(帶圓角滑塊)

1.先上效果圖

MatchingSwitch.gif

2.實現(xiàn)思路

  • 最外層布局Stack
  • 底部寫一個Container背景組件(Widget)
  • 通過AnimatedPositioned 實現(xiàn)滑塊效果
    • 設置left或者right
    • 滑動或者點擊實現(xiàn)過渡動畫
  • 實現(xiàn)滑動底部列表或者點擊頂部Tab即可實現(xiàn)滑動滑動效果

3.關(guān)鍵代碼

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fpdxapp/components/custom_appbar.dart';
import 'package:fpdxapp/components/switch/toggle.dart';
import 'package:fpdxapp/components/vip_tag.dart';
import 'package:fpdxapp/model/im/im.dart';
import 'package:fpdxapp/utils/screen.dart';
import 'package:fpdxapp/utils/toast.dart';
import 'package:fpdxapp/utils/utils.dart';

class MatchingPage extends StatefulWidget {
  @override
  _MatchingPageState createState() => _MatchingPageState();
}

class _MatchingPageState extends State<MatchingPage> {
  int index = 1;

  ListFriendConversationModel currentItem = ListFriendConversationModel();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar.appBar(
        context,
        title: '匹配CP|匹配歷史',
        theme: CustomAppbarTheme.white,
      ),
      body: MatchingWidget(),
    );
  }
}

class MatchingWidget extends StatefulWidget {
  @override
  _MatchingWidgetState createState() => _MatchingWidgetState();
}

class _MatchingWidgetState extends State<MatchingWidget> {
  final _controller = new PageController();
  final int pageSwitchAnimatedTime = 200;

  double centerPoint = ScreenUtil().setWidth(318) / 2;
  double value = ScreenUtil().setWidth(318) / 2;
  final List<Widget> _pages = <Widget>[
    MatchCp(),
    MatchHistory(),
  ];
  int currentIndex = 1;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: SafeArea(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          //主題Body
          Container(
            child: Column(
              children: <Widget>[
                // 切換Tab
                Center(
                  child: Stack(
                    children: <Widget>[
                      // 主題
                      GestureDetector(
                        child: Container(
                          width: ScreenUtil().setWidth(318),
                          height: 40,
                          decoration: BoxDecoration(
                            color: Color(0xffF3F4F5),
                            borderRadius: BorderRadius.circular(
                              ScreenUtil().setWidth(70),
                            ),
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: <Widget>[
                              Text(
                                '匹配歷史',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: ScreenUtil().setSp(28),
                                ),
                              ),
                              Text(
                                '匹配CP',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: ScreenUtil().setSp(28),
                                ),
                              ),
                            ],
                          ),
                        ),
                        onTap: () {
                          print('this.value=========>${this.value}');
                          if (this.value == 0.0) {
                            this.value = ScreenUtil().setWidth(318) / 2;
                            currentIndex = 1;
                          } else {
                            currentIndex = 0;
                            this.value = 0.0;
                          }
                          //print("currentIndex=============${currentIndex}");
                          _controller.animateToPage(currentIndex == 0 ? 1 : 0,
                              duration: Duration(
                                  milliseconds: (pageSwitchAnimatedTime + 100)),
                              curve: Curves.ease);

                          setState(() {});
                        },
                      ),
                      // 滑塊
                      AnimatedPositioned(
                        left: this.value,
                        duration:
                            Duration(milliseconds: pageSwitchAnimatedTime),
                        child: Container(
                          width: ScreenUtil().setWidth(160),
                          height: 40,
                          decoration: BoxDecoration(
                            color: Color(0xffED9CBE),
                            borderRadius: BorderRadius.circular(
                                ScreenUtil().setWidth(70)),
                          ),
                          child: Center(
                            child: Text(
                              currentIndex == 1 ? '匹配CP' : '匹配歷史',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: ScreenUtil().setSp(28),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),

                // 匹配-Part
                Container(
                  child: PageView.builder(
                    physics: new AlwaysScrollableScrollPhysics(),
                    controller: _controller,
                    itemBuilder: (BuildContext context, int index) {
                      return _pages[index];
                    },
                    //條目個數(shù)
                    itemCount: _pages.length,
                    onPageChanged: (int index) {
                      currentIndex = index == 0 ? 1 : 0;
                      this.value = currentIndex == 1
                          ? ScreenUtil().setWidth(318) / 2
                          : 0.0;
                      setState(() {});
                    },
                  ),
                  height: 500,
                ),
              ],
            ),
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(40)),
          ),
          // 底部描述
          Container(
            margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(37)),
            child: Text(
              '—— 到這兒剛剛好 ——',
              style: TextStyle(
                  color: Color(0xff999999), fontSize: ScreenUtil().setSp(24)),
            ),
          ),
        ],
      )),
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            offset: Offset(0, -ScreenUtil().setWidth(3)),
            blurRadius: ScreenUtil().setWidth(6),
            spreadRadius: ScreenUtil().setWidth(6),
            color: Colors.black.withOpacity(0.03),
          ),
        ],
      ),
    );
  }
}

class MatchHistory extends StatelessWidget {
  ListFriendConversationModel currentItem = ListFriendConversationModel();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        _matching(currentItem),
        _matchSucceed(currentItem),
        _matchFailed(currentItem),
      ],
    );
  }

  /// 匹配中
  Widget _matching(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffFFF2F4),
                          border:
                              new Border.all(width: 2.0, color: Colors.white),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                          boxShadow: [
                            BoxShadow(
                              offset: Offset(0, 0),
                              blurRadius: ScreenUtil().setWidth(7),
                              color: Color(0xffC4566F).withOpacity(0.13),
                            ),
                          ],
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                          ),
                          child: Center(
                            child: Image(
                              image:
                                  Utils.getAssetImgWithPath('matching_in_cp'),
                              width: ScreenUtil().setWidth(70),
                            ),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '匹配中',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xffFF7E98)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '請于8月08日查詢匹配結(jié)果',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFAAAAAA)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                // 箭頭角標
                Container(
                  child: Icon(
                    Icons.arrow_forward_ios,
                    size: ScreenUtil().setSp(28),
                    color: Color(0xff999999),
                  ),
                  margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }

  /// 匹配成功
  Widget _matchSucceed(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffFFE7EC),
                          border: new Border.all(
                              width: 2.0, color: Color(0xffFA8396)),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                            image: DecorationImage(
                                image: NetworkImage(
                                    'https://dss1.bdstatic.com/6OF1bjeh1BF3odCf/it/u=4023145134,3753224785&fm=74&app=80&f=JPEG&size=f121,90?sec=1880279984&t=49fe2a9b312d6f606c1dab71efc9b252'),
                                fit: BoxFit.cover),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '小殼兒',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xff333333)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '51期匹配CP',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFAAAAAA)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                // 箭頭角標
                Container(
                  child: Icon(
                    Icons.arrow_forward_ios,
                    size: ScreenUtil().setSp(28),
                    color: Color(0xff999999),
                  ),
                  margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }

  /// 匹配失敗
  Widget _matchFailed(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffF3F4F5),
                          border:
                              new Border.all(width: 2.0, color: Colors.white),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                          boxShadow: [
                            BoxShadow(
                              offset: Offset(0, 0),
                              blurRadius: ScreenUtil().setWidth(7),
                              color: Color(0xffC4566F).withOpacity(0.13),
                            ),
                          ],
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                          ),
                          child: Center(
                            child: Image(
                              image:
                                  Utils.getAssetImgWithPath('matching_fail_cp'),
                              width: ScreenUtil().setWidth(60),
                            ),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '匹配失敗',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xff999999)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '已報名下一期分配對象',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFDEDEDE)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }
}

class MatchCp extends StatelessWidget {
  ListFriendConversationModel currentItem = ListFriendConversationModel();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        _matchSucceed(currentItem),
        _matchSucceed(currentItem),
      ],
    );
  }

  /// 匹配中
  Widget _matching(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffFFF2F4),
                          border:
                              new Border.all(width: 2.0, color: Colors.white),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                          boxShadow: [
                            BoxShadow(
                              offset: Offset(0, 0),
                              blurRadius: ScreenUtil().setWidth(7),
                              color: Color(0xffC4566F).withOpacity(0.13),
                            ),
                          ],
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                          ),
                          child: Center(
                            child: Image(
                              image:
                                  Utils.getAssetImgWithPath('matching_in_cp'),
                              width: ScreenUtil().setWidth(70),
                            ),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '匹配中',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xffFF7E98)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '請于8月08日查詢匹配結(jié)果',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFAAAAAA)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                // 箭頭角標
                Container(
                  child: Icon(
                    Icons.arrow_forward_ios,
                    size: ScreenUtil().setSp(28),
                    color: Color(0xff999999),
                  ),
                  margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }

  /// 匹配成功
  Widget _matchSucceed(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffFFE7EC),
                          border: new Border.all(
                              width: 2.0, color: Color(0xffFA8396)),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                            image: DecorationImage(
                                image: NetworkImage(
                                    'https://dss1.bdstatic.com/6OF1bjeh1BF3odCf/it/u=4023145134,3753224785&fm=74&app=80&f=JPEG&size=f121,90?sec=1880279984&t=49fe2a9b312d6f606c1dab71efc9b252'),
                                fit: BoxFit.cover),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '小殼兒',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xff333333)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '51期匹配CP',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFAAAAAA)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                // 箭頭角標
                Container(
                  child: Icon(
                    Icons.arrow_forward_ios,
                    size: ScreenUtil().setSp(28),
                    color: Color(0xff999999),
                  ),
                  margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }

  /// 匹配失敗
  Widget _matchFailed(ListFriendConversationModel currentItem) {
    return Column(
      children: <Widget>[
        // 主題部分
        Container(
          color: Colors.transparent,
          width: Screen.width,
          margin: EdgeInsets.only(
              left: ScreenUtil().setWidth(20),
              right: ScreenUtil().setWidth(16),
              top: ScreenUtil().setHeight(20),
              bottom: ScreenUtil().setHeight(20)),
          //color: Colors.green,
          child: Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    children: <Widget>[
                      // 左邊icon 部分
                      Container(
                        width: ScreenUtil().setWidth(120),
                        height: ScreenUtil().setWidth(120),
                        decoration: BoxDecoration(
                          color: Color(0xffF3F4F5),
                          border:
                              new Border.all(width: 2.0, color: Colors.white),
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenUtil().setWidth(120))),
                          boxShadow: [
                            BoxShadow(
                              offset: Offset(0, 0),
                              blurRadius: ScreenUtil().setWidth(7),
                              color: Color(0xffC4566F).withOpacity(0.13),
                            ),
                          ],
                        ),
                        child: Container(
                          margin: EdgeInsets.all(2),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                                Radius.circular(ScreenUtil().setWidth(151))),
                          ),
                          child: Center(
                            child: Image(
                              image:
                                  Utils.getAssetImgWithPath('matching_fail_cp'),
                              width: ScreenUtil().setWidth(60),
                            ),
                          ),
                        ),
                      ),

                      // 文字部分
                      Expanded(
                        child: Container(
                          margin:
                              EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text(
                                    '匹配失敗',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(30),
                                        color: Color(0xff999999)),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(left: 5),
                                    child: VipTag(
                                        currentItem.user?.beVipAt ?? 0,
                                        currentItem.user?.supvipEndAt ?? 0,
                                        currentItem.user?.wxAuth),
                                  )
                                ],
                              ),
                              SizedBox(
                                height: ScreenUtil().setHeight(4),
                              ),
                              Text(
                                '已報名下一期分配對象',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: Color(0xFFDEDEDE)),
                                overflow: TextOverflow.ellipsis,
                                maxLines: 1,
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
        // 分割線
        Container(
          child: Divider(
            height: ScreenUtil().setHeight(2),
            indent: ScreenUtil().setWidth(150),
            endIndent: ScreenUtil().setWidth(30),
            color: Color(0xffEEEEEE),
          ),
          margin: EdgeInsets.only(bottom: 1),
        ),
      ],
    );
  }
}

未完-待續(xù).

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末暑诸,一起剝皮案震驚了整個濱河市欠动,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌朴下,老刑警劉巖胖眷,帶你破解...
    沈念sama閱讀 221,820評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件忘嫉,死亡現(xiàn)場離奇詭異鞭光,居然都是意外死亡咳胃,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,648評論 3 399
  • 文/潘曉璐 我一進店門彤灶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來弹砚,“玉大人,你說我怎么就攤上這事枢希。” “怎么了朱沃?”我有些...
    開封第一講書人閱讀 168,324評論 0 360
  • 文/不壞的土叔 我叫張陵苞轿,是天一觀的道長。 經(jīng)常有香客問我逗物,道長搬卒,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,714評論 1 297
  • 正文 為了忘掉前任翎卓,我火速辦了婚禮契邀,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘失暴。我一直安慰自己坯门,他們只是感情好,可當我...
    茶點故事閱讀 68,724評論 6 397
  • 文/花漫 我一把揭開白布逗扒。 她就那樣靜靜地躺著古戴,像睡著了一般。 火紅的嫁衣襯著肌膚如雪矩肩。 梳的紋絲不亂的頭發(fā)上现恼,一...
    開封第一講書人閱讀 52,328評論 1 310
  • 那天,我揣著相機與錄音,去河邊找鬼叉袍。 笑死始锚,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的喳逛。 我是一名探鬼主播瞧捌,決...
    沈念sama閱讀 40,897評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼艺配!你這毒婦竟也來了察郁?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,804評論 0 276
  • 序言:老撾萬榮一對情侶失蹤转唉,失蹤者是張志新(化名)和其女友劉穎皮钠,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赠法,經(jīng)...
    沈念sama閱讀 46,345評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡麦轰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,431評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了砖织。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片款侵。...
    茶點故事閱讀 40,561評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖侧纯,靈堂內(nèi)的尸體忽然破棺而出新锈,到底是詐尸還是另有隱情,我是刑警寧澤眶熬,帶...
    沈念sama閱讀 36,238評論 5 350
  • 正文 年R本政府宣布妹笆,位于F島的核電站,受9級特大地震影響娜氏,放射性物質(zhì)發(fā)生泄漏拳缠。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,928評論 3 334
  • 文/蒙蒙 一贸弥、第九天 我趴在偏房一處隱蔽的房頂上張望窟坐。 院中可真熱鬧,春花似錦绵疲、人聲如沸哲鸳。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,417評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽帕胆。三九已至,卻和暖如春般渡,著一層夾襖步出監(jiān)牢的瞬間懒豹,已是汗流浹背芙盘。 一陣腳步聲響...
    開封第一講書人閱讀 33,528評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留脸秽,地道東北人儒老。 一個月前我還...
    沈念sama閱讀 48,983評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像记餐,于是被迫代替她去往敵國和親驮樊。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,573評論 2 359

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

  • ¥開啟¥ 【iAPP實現(xiàn)進入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個線程片酝,因...
    小菜c閱讀 6,444評論 0 17
  • 語法 一. 1)名詞+???/??:表示“是....” 尊敬階的終結(jié)詞尾 名詞結(jié)尾有收音+??? 名詞結(jié)尾沒有收音...
    紅傘閱讀 566評論 0 0
  • 我是個吃貨囚衔,五味中嗜好甜味。而甜食對于有些人來講簡直就是致命的誘惑〉裱兀現(xiàn)代人“三高”癥多练湿,很多人被永遠地排除...
    從明閱讀 834評論 5 35
  • 這兩天培訓感覺還是有收獲的,頭一天對技術(shù)有了進一步加深理解审轮,第二天get了兩個軟件肥哎,一個goole翻譯,一個pp匠...
    噯寧閱讀 212評論 0 1