Flutter 自定义Switch组件(常规|带圆角滑块)

常规自定义组件(案例一)

1.先上效果图

ToggleSwitch.gif

2.关键代码如下

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 设置常规背景颜色
  • inactiveTextColor 设置常规字体颜色
  • labels 设置标题数组
  • onToggle 拨动回调方法

自定义Switch案例二(带圆角滑块)

1.先上效果图

MatchingSwitch.gif

2.实现思路

  • 最外层布局Stack
  • 底部写一个Container背景组件(Widget)
  • 通过AnimatedPositioned 实现滑块效果
    • 设置left或者right
    • 滑动或者点击实现过渡动画
  • 实现滑动底部列表或者点击顶部Tab即可实现滑动滑动效果

3.关键代码

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];
                    },
                    //条目个数
                    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日查询匹配结果',
                                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日查询匹配结果',
                                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),
        ),
      ],
    );
  }
}

未完-待续.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,373评论 0 17
  • 语法 一. 1)名词+이에요/예요:表示“是....” 尊敬阶的终结词尾 名词结尾有收音+이에요 名词结尾没有收音...
    红伞阅读 553评论 0 0
  • 我是个吃货,五味中嗜好甜味。而甜食对于有些人来讲简直就是致命的诱惑。现代人“三高”症多,很多人被永远地排除...
    从明阅读 823评论 5 35
  • 这两天培训感觉还是有收获的,头一天对技术有了进一步加深理解,第二天get了两个软件,一个goole翻译,一个pp匠...
    嗳宁阅读 209评论 0 1